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

Improve handling of fLaC

This commit is contained in:
Jeff Schiller 2023-02-05 21:44:00 -08:00
parent 303c635b90
commit 24312405b5
2 changed files with 46 additions and 8 deletions

View file

@ -127,9 +127,10 @@ export function getFullMIMEString(info) {
case 'opus': codecFrags.add('opus'); break; case 'opus': codecFrags.add('opus'); break;
// I'm going off of what Chromium calls this one, with the dash. // I'm going off of what Chromium calls this one, with the dash.
case 'ac3': codecFrags.add('ac-3'); break; case 'ac3': codecFrags.add('ac-3'); break;
case 'flac': codecFrags.add('flac'); break; // It seems to be "fLaC".
case 'flac': codecFrags.add(stream.codec_tag_string); break;
default: default:
throw `Could not handle codec_name ${stream.codec_name}, ` + throw `Could not handle audio codec_name ${stream.codec_name}, ` +
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` + `codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
`Please file a bug https://github.com/codedread/bitjs/issues/new`; `Please file a bug https://github.com/codedread/bitjs/issues/new`;
} }
@ -141,16 +142,16 @@ export function getFullMIMEString(info) {
case 'avc1': codecFrags.add(getAVC1CodecString(stream)); break; case 'avc1': codecFrags.add(getAVC1CodecString(stream)); break;
case 'vp09': codecFrags.add(getVP09CodecString(stream)); break; case 'vp09': codecFrags.add(getVP09CodecString(stream)); break;
// We don't handle these as video streams with codecs, so skip them. // We don't handle these as video streams with codecs, so skip them.
case 'png': case 'png': continue;
case 'mjpeg':
continue;
default: default:
switch (stream.codec_name) { switch (stream.codec_name) {
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break; case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
case 'vp9': codecFrags.add(getVP09CodecString(stream)); break;
case 'mpeg2video': codecFrags.add('mpeg2video'); break; case 'mpeg2video': codecFrags.add('mpeg2video'); break;
// Skip mjpeg as a video stream for the codecs string.
case 'mjpeg': break;
case 'vp9': codecFrags.add(getVP09CodecString(stream)); break;
default: default:
throw `Could not handle codec_name ${stream.codec_name}, ` + throw `Could not handle video codec_name ${stream.codec_name}, ` +
`codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` + `codec_tag_string ${stream.codec_tag_string} for file ${info.format.filename} yet. ` +
`Please file a bug https://github.com/codedread/bitjs/issues/new`; `Please file a bug https://github.com/codedread/bitjs/issues/new`;

View file

@ -49,7 +49,7 @@ describe('codecs test suite', () => {
it('detects FLAC', () => { it('detects FLAC', () => {
expect(getShortMIMEString({ expect(getShortMIMEString({
format: { format_name: 'flac' }, format: { format_name: 'flac', format_tag_string: 'fLaC' },
streams: [ { codec_type: 'audio'}, { codec_type: 'video' } ], streams: [ { codec_type: 'audio'}, { codec_type: 'video' } ],
})).equals('audio/flac'); })).equals('audio/flac');
}); });
@ -341,6 +341,43 @@ describe('codecs test suite', () => {
}); });
}); });
describe('MP4 / FLAC', () => {
/** @type {ProbeInfo} */
let info;
beforeEach(() => {
info = {
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
streams: [{
codec_type: 'audio',
codec_tag_string: 'mp4a',
}],
};
});
it('audio/mp4 handles fLaC', () => {
info.streams[0].codec_tag_string = 'fLaC';
info.streams[0].codec_name = 'flac';
expect(getFullMIMEString(info))
.to.be.a('string')
.and.equals('audio/mp4; codecs="fLaC"');
});
it('video/mp4 handles fLaC', () => {
const vInfo = structuredClone(info);
vInfo.streams[0].codec_tag_string = 'fLaC';
vInfo.streams[0].codec_name = 'flac';
vInfo.streams.push({
codec_type: 'video',
codec_name: 'mjpeg',
});
expect(getFullMIMEString(vInfo))
.to.be.a('string')
.and.equals('video/mp4; codecs="fLaC"');
});
});
describe('Vorbis', () => { describe('Vorbis', () => {
/** @type {ProbeInfo} */ /** @type {ProbeInfo} */
let info; let info;