1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-03 17:49:16 +02:00

Add handling when codec_name is set but codec_tag_string is not parse-able

This commit is contained in:
Jeff Schiller 2022-11-06 01:09:43 -07:00
parent 744162ec5b
commit 2a37f87242
3 changed files with 41 additions and 6 deletions

View file

@ -119,6 +119,14 @@ export function getFullMIMEString(info) {
// TODO: vorbis. // TODO: vorbis.
// TODO: opus. // TODO: opus.
default: 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') { else if (stream.codec_type === 'video') {
@ -130,8 +138,14 @@ export function getFullMIMEString(info) {
case 'mjpeg': case 'mjpeg':
continue; continue;
default: default:
throw `Could not handle codec_tag_string ${stream.codec_tag_string} yet. ` + switch (stream.codec_name) {
`Please file a bug https://github.com/codedread/bitjs/issues/new`; 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. // 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 * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#iso_base_media_file_format_mp4_quicktime_and_3gp
* @param {ProbeStream} stream * @param {ProbeStream} stream
* @returns {string} * @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 * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#mp4a
* @param {ProbeStream} stream * @param {ProbeStream} stream
* @returns {string} * @returns {string}

View file

@ -1,6 +1,6 @@
{ {
"name": "@codedread/bitjs", "name": "@codedread/bitjs",
"version": "1.0.3", "version": "1.0.4",
"description": "Binary Tools for JavaScript", "description": "Binary Tools for JavaScript",
"homepage": "https://github.com/codedread/bitjs", "homepage": "https://github.com/codedread/bitjs",
"author": "Jeff Schiller", "author": "Jeff Schiller",

View file

@ -125,7 +125,7 @@ describe('codecs test suite', () => {
})).to.throw(); })).to.throw();
}); });
describe('AVC1', () => { describe('AVC1 / H264', () => {
/** @type {ProbeInfo} */ /** @type {ProbeInfo} */
let info; let info;
@ -201,6 +201,16 @@ describe('codecs test suite', () => {
.and.satisfy(s => s.endsWith('0A"')); .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} */ /** @type {ProbeInfo} */
let info; let info;
@ -286,5 +296,14 @@ describe('codecs test suite', () => {
.and.equals('audio/mp4; codecs="mp4a.40.2"'); .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"');
});
}); });
}); });