diff --git a/codecs/codecs.js b/codecs/codecs.js index d972e06..05a994f 100644 --- a/codecs/codecs.js +++ b/codecs/codecs.js @@ -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`; } diff --git a/package.json b/package.json index 52e1216..106480a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/codecs.spec.js b/tests/codecs.spec.js index 5637e84..e4ca4b8 100644 --- a/tests/codecs.spec.js +++ b/tests/codecs.spec.js @@ -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"'); + }); }); });