mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +02:00
Add handling when codec_name is set but codec_tag_string is not parse-able
This commit is contained in:
parent
744162ec5b
commit
2a37f87242
3 changed files with 41 additions and 6 deletions
|
@ -119,6 +119,14 @@ export function getFullMIMEString(info) {
|
|||
// TODO: vorbis.
|
||||
// TODO: opus.
|
||||
default:
|
||||
switch (stream.codec_name) {
|
||||
case 'aac': codecFrags.add(getMP4ACodecString(stream)); break;
|
||||
default:
|
||||
throw `Could not handle codec_name ${stream.codec_name}, ` +
|
||||
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
|
||||
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (stream.codec_type === 'video') {
|
||||
|
@ -130,8 +138,14 @@ export function getFullMIMEString(info) {
|
|||
case 'mjpeg':
|
||||
continue;
|
||||
default:
|
||||
throw `Could not handle codec_tag_string ${stream.codec_tag_string} yet. ` +
|
||||
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
|
||||
switch (stream.codec_name) {
|
||||
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
|
||||
default:
|
||||
throw `Could not handle codec_name ${stream.codec_name}, ` +
|
||||
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
|
||||
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +157,7 @@ export function getFullMIMEString(info) {
|
|||
// TODO: Consider whether any of these should be exported.
|
||||
|
||||
/**
|
||||
* AVC1 is the same thing as H264.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#iso_base_media_file_format_mp4_quicktime_and_3gp
|
||||
* @param {ProbeStream} stream
|
||||
* @returns {string}
|
||||
|
@ -237,6 +252,7 @@ function getVP09CodecString(stream) {
|
|||
}
|
||||
|
||||
/**
|
||||
* MP4A is the same as AAC.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#mp4a
|
||||
* @param {ProbeStream} stream
|
||||
* @returns {string}
|
||||
|
@ -248,7 +264,7 @@ function getMP4ACodecString(stream) {
|
|||
frag += '.2';
|
||||
break;
|
||||
// TODO: more!
|
||||
default:
|
||||
default:
|
||||
throw `Cannot handle AAC stream with profile ${stream.profile} yet. ` +
|
||||
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@codedread/bitjs",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "Binary Tools for JavaScript",
|
||||
"homepage": "https://github.com/codedread/bitjs",
|
||||
"author": "Jeff Schiller",
|
||||
|
|
|
@ -125,7 +125,7 @@ describe('codecs test suite', () => {
|
|||
})).to.throw();
|
||||
});
|
||||
|
||||
describe('AVC1', () => {
|
||||
describe('AVC1 / H264', () => {
|
||||
/** @type {ProbeInfo} */
|
||||
let info;
|
||||
|
||||
|
@ -201,6 +201,16 @@ describe('codecs test suite', () => {
|
|||
.and.satisfy(s => s.endsWith('0A"'));
|
||||
});
|
||||
});
|
||||
|
||||
it('Handles codec_name=h264, but no codec_tag_string', () => {
|
||||
info.streams[0].codec_name = 'h264';
|
||||
info.streams[0].profile = 'Main';
|
||||
info.streams[0].codec_tag_string = '[0][0][0][0]';
|
||||
info.streams[0].level = 20;
|
||||
expect(getFullMIMEString(info))
|
||||
.to.be.a('string')
|
||||
.and.satisfy(s => s.startsWith('video/mp4; codecs="avc1.4D00'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -260,7 +270,7 @@ describe('codecs test suite', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('AAC', () => {
|
||||
describe('MP4A / AAC', () => {
|
||||
/** @type {ProbeInfo} */
|
||||
let info;
|
||||
|
||||
|
@ -286,5 +296,14 @@ describe('codecs test suite', () => {
|
|||
.and.equals('audio/mp4; codecs="mp4a.40.2"');
|
||||
});
|
||||
});
|
||||
|
||||
it('handles codec_name=aac but no codec_tag_string', () => {
|
||||
info.streams[0].profile = 'LC';
|
||||
info.streams[0].codec_tag_string = '[0][0][0][0]';
|
||||
info.streams[0].codec_name = 'aac';
|
||||
expect(getFullMIMEString(info))
|
||||
.to.be.a('string')
|
||||
.and.equals('audio/mp4; codecs="mp4a.40.2"');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue