Skip to content

Commit 2a37f87

Browse files
committed
Add handling when codec_name is set but codec_tag_string is not parse-able
1 parent 744162e commit 2a37f87

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

codecs/codecs.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ export function getFullMIMEString(info) {
119119
// TODO: vorbis.
120120
// TODO: opus.
121121
default:
122+
switch (stream.codec_name) {
123+
case 'aac': codecFrags.add(getMP4ACodecString(stream)); break;
124+
default:
125+
throw `Could not handle codec_name ${stream.codec_name}, ` +
126+
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
127+
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
128+
}
129+
break;
122130
}
123131
}
124132
else if (stream.codec_type === 'video') {
@@ -130,8 +138,14 @@ export function getFullMIMEString(info) {
130138
case 'mjpeg':
131139
continue;
132140
default:
133-
throw `Could not handle codec_tag_string ${stream.codec_tag_string} yet. ` +
134-
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
141+
switch (stream.codec_name) {
142+
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
143+
default:
144+
throw `Could not handle codec_name ${stream.codec_name}, ` +
145+
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
146+
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
147+
148+
}
135149
}
136150
}
137151
}
@@ -143,6 +157,7 @@ export function getFullMIMEString(info) {
143157
// TODO: Consider whether any of these should be exported.
144158

145159
/**
160+
* AVC1 is the same thing as H264.
146161
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#iso_base_media_file_format_mp4_quicktime_and_3gp
147162
* @param {ProbeStream} stream
148163
* @returns {string}
@@ -237,6 +252,7 @@ function getVP09CodecString(stream) {
237252
}
238253

239254
/**
255+
* MP4A is the same as AAC.
240256
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter#mp4a
241257
* @param {ProbeStream} stream
242258
* @returns {string}
@@ -248,7 +264,7 @@ function getMP4ACodecString(stream) {
248264
frag += '.2';
249265
break;
250266
// TODO: more!
251-
default:
267+
default:
252268
throw `Cannot handle AAC stream with profile ${stream.profile} yet. ` +
253269
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
254270
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codedread/bitjs",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Binary Tools for JavaScript",
55
"homepage": "https://github.com/codedread/bitjs",
66
"author": "Jeff Schiller",

tests/codecs.spec.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('codecs test suite', () => {
125125
})).to.throw();
126126
});
127127

128-
describe('AVC1', () => {
128+
describe('AVC1 / H264', () => {
129129
/** @type {ProbeInfo} */
130130
let info;
131131

@@ -201,6 +201,16 @@ describe('codecs test suite', () => {
201201
.and.satisfy(s => s.endsWith('0A"'));
202202
});
203203
});
204+
205+
it('Handles codec_name=h264, but no codec_tag_string', () => {
206+
info.streams[0].codec_name = 'h264';
207+
info.streams[0].profile = 'Main';
208+
info.streams[0].codec_tag_string = '[0][0][0][0]';
209+
info.streams[0].level = 20;
210+
expect(getFullMIMEString(info))
211+
.to.be.a('string')
212+
.and.satisfy(s => s.startsWith('video/mp4; codecs="avc1.4D00'));
213+
});
204214
});
205215
});
206216

@@ -260,7 +270,7 @@ describe('codecs test suite', () => {
260270
});
261271
});
262272

263-
describe('AAC', () => {
273+
describe('MP4A / AAC', () => {
264274
/** @type {ProbeInfo} */
265275
let info;
266276

@@ -286,5 +296,14 @@ describe('codecs test suite', () => {
286296
.and.equals('audio/mp4; codecs="mp4a.40.2"');
287297
});
288298
});
299+
300+
it('handles codec_name=aac but no codec_tag_string', () => {
301+
info.streams[0].profile = 'LC';
302+
info.streams[0].codec_tag_string = '[0][0][0][0]';
303+
info.streams[0].codec_name = 'aac';
304+
expect(getFullMIMEString(info))
305+
.to.be.a('string')
306+
.and.equals('audio/mp4; codecs="mp4a.40.2"');
307+
});
289308
});
290309
});

0 commit comments

Comments
 (0)