Skip to content

Commit

Permalink
Fix parsing of multiple codecs when converting from AVC1 to AVCOTI
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonatangcavalcanti committed Jul 2, 2024
1 parent 0a6165f commit dda848d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/utils/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,21 @@ export function pickMostCompleteCodecName(

export function convertAVC1ToAVCOTI(codec: string) {
// Convert avc1 codec string from RFC-4281 to RFC-6381 for MediaSource.isTypeSupported
const avcdata = codec.split('.');
if (avcdata.length > 2) {
let result = avcdata.shift() + '.';
result += parseInt(avcdata.shift() as string).toString(16);
result += ('000' + parseInt(avcdata.shift() as string).toString(16)).slice(
-4,
);
return result;
// Examples: avc1.66.30 to avc1.42001e and avc1.77.30,avc1.66.30 to avc1.4d001e,avc1.42001e.
const codecs = codec.split(',')
for (let i = 0; i < codecs.length; i++) {
const avcdata = codecs[i].split('.');
if (avcdata.length > 2) {
let result = ''
result = avcdata.shift() + '.';
result += parseInt(avcdata.shift() as string).toString(16);
result += ('000' + parseInt(avcdata.shift() as string).toString(16)).slice(
-4,
);
codecs[i] = result
}
}
return codec;
return codecs.join(',');
}

export interface TypeSupported {
Expand Down

0 comments on commit dda848d

Please sign in to comment.