Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of multiple video codecs when converting from AVC1 to AVCOTI #6533

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/utils/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,20 @@ 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 = 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
1 change: 1 addition & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import './unit/loader/playlist-loader';
import './unit/utils/attr-list';
import './unit/utils/binary-search';
import './unit/utils/buffer-helper';
import './unit/utils/codecs';
import './unit/utils/error-helper';
import './unit/utils/discontinuities';
import './unit/utils/exp-golomb';
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/utils/codecs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'chai';
import { convertAVC1ToAVCOTI } from '../../../src/utils/codecs';

describe('codecs', function () {
it('convert codec string from AVC1 to AVCOTI', function () {
expect(convertAVC1ToAVCOTI('avc1.66.30')).to.equal('avc1.42001e');
});

it('convert list of codecs string from AVC1 to AVCOTI', function () {
expect(convertAVC1ToAVCOTI('avc1.77.30,avc1.66.30')).to.equal(
'avc1.4d001e,avc1.42001e',
);
});

it('does not convert string if it is already converted', function () {
expect(convertAVC1ToAVCOTI('avc1.64001E')).to.equal('avc1.64001E');
});

it('does not convert list of codecs string if it is already converted', function () {
expect(convertAVC1ToAVCOTI('avc1.64001E,avc1.64001f')).to.equal(
'avc1.64001E,avc1.64001f',
);
});
});
Loading