mirror of
https://github.com/codedread/bitjs
synced 2025-10-03 09:39:16 +02:00
Improve handling of fLaC
This commit is contained in:
parent
303c635b90
commit
24312405b5
2 changed files with 46 additions and 8 deletions
|
@ -127,9 +127,10 @@ export function getFullMIMEString(info) {
|
|||
case 'opus': codecFrags.add('opus'); break;
|
||||
// I'm going off of what Chromium calls this one, with the dash.
|
||||
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:
|
||||
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. ` +
|
||||
`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 'vp09': codecFrags.add(getVP09CodecString(stream)); break;
|
||||
// We don't handle these as video streams with codecs, so skip them.
|
||||
case 'png':
|
||||
case 'mjpeg':
|
||||
continue;
|
||||
case 'png': continue;
|
||||
default:
|
||||
switch (stream.codec_name) {
|
||||
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
|
||||
case 'vp9': codecFrags.add(getVP09CodecString(stream)); 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:
|
||||
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. ` +
|
||||
`Please file a bug https://github.com/codedread/bitjs/issues/new`;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('codecs test suite', () => {
|
|||
|
||||
it('detects FLAC', () => {
|
||||
expect(getShortMIMEString({
|
||||
format: { format_name: 'flac' },
|
||||
format: { format_name: 'flac', format_tag_string: 'fLaC' },
|
||||
streams: [ { codec_type: 'audio'}, { codec_type: 'video' } ],
|
||||
})).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', () => {
|
||||
/** @type {ProbeInfo} */
|
||||
let info;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue