Skip to content

Commit 2431240

Browse files
committed
Improve handling of fLaC
1 parent 303c635 commit 2431240

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

codecs/codecs.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ export function getFullMIMEString(info) {
127127
case 'opus': codecFrags.add('opus'); break;
128128
// I'm going off of what Chromium calls this one, with the dash.
129129
case 'ac3': codecFrags.add('ac-3'); break;
130-
case 'flac': codecFrags.add('flac'); break;
130+
// It seems to be "fLaC".
131+
case 'flac': codecFrags.add(stream.codec_tag_string); break;
131132
default:
132-
throw `Could not handle codec_name ${stream.codec_name}, ` +
133+
throw `Could not handle audio codec_name ${stream.codec_name}, ` +
133134
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
134135
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
135136
}
@@ -141,16 +142,16 @@ export function getFullMIMEString(info) {
141142
case 'avc1': codecFrags.add(getAVC1CodecString(stream)); break;
142143
case 'vp09': codecFrags.add(getVP09CodecString(stream)); break;
143144
// We don't handle these as video streams with codecs, so skip them.
144-
case 'png':
145-
case 'mjpeg':
146-
continue;
145+
case 'png': continue;
147146
default:
148147
switch (stream.codec_name) {
149148
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
150-
case 'vp9': codecFrags.add(getVP09CodecString(stream)); break;
151149
case 'mpeg2video': codecFrags.add('mpeg2video'); break;
150+
// Skip mjpeg as a video stream for the codecs string.
151+
case 'mjpeg': break;
152+
case 'vp9': codecFrags.add(getVP09CodecString(stream)); break;
152153
default:
153-
throw `Could not handle codec_name ${stream.codec_name}, ` +
154+
throw `Could not handle video codec_name ${stream.codec_name}, ` +
154155
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
155156
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
156157

tests/codecs.spec.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('codecs test suite', () => {
4949

5050
it('detects FLAC', () => {
5151
expect(getShortMIMEString({
52-
format: { format_name: 'flac' },
52+
format: { format_name: 'flac', format_tag_string: 'fLaC' },
5353
streams: [ { codec_type: 'audio'}, { codec_type: 'video' } ],
5454
})).equals('audio/flac');
5555
});
@@ -341,6 +341,43 @@ describe('codecs test suite', () => {
341341
});
342342
});
343343

344+
describe('MP4 / FLAC', () => {
345+
/** @type {ProbeInfo} */
346+
let info;
347+
348+
beforeEach(() => {
349+
info = {
350+
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
351+
streams: [{
352+
codec_type: 'audio',
353+
codec_tag_string: 'mp4a',
354+
}],
355+
};
356+
});
357+
358+
it('audio/mp4 handles fLaC', () => {
359+
info.streams[0].codec_tag_string = 'fLaC';
360+
info.streams[0].codec_name = 'flac';
361+
expect(getFullMIMEString(info))
362+
.to.be.a('string')
363+
.and.equals('audio/mp4; codecs="fLaC"');
364+
});
365+
366+
it('video/mp4 handles fLaC', () => {
367+
const vInfo = structuredClone(info);
368+
vInfo.streams[0].codec_tag_string = 'fLaC';
369+
vInfo.streams[0].codec_name = 'flac';
370+
vInfo.streams.push({
371+
codec_type: 'video',
372+
codec_name: 'mjpeg',
373+
});
374+
expect(getFullMIMEString(vInfo))
375+
.to.be.a('string')
376+
.and.equals('video/mp4; codecs="fLaC"');
377+
378+
});
379+
});
380+
344381
describe('Vorbis', () => {
345382
/** @type {ProbeInfo} */
346383
let info;

0 commit comments

Comments
 (0)