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

Add vorbis/opus support in codecs.

This commit is contained in:
Jeff Schiller 2022-11-06 01:39:36 -07:00
parent 2a37f87242
commit d3b8765b42
3 changed files with 57 additions and 4 deletions

View file

@ -116,11 +116,11 @@ export function getFullMIMEString(info) {
if (stream.codec_type === 'audio') { if (stream.codec_type === 'audio') {
switch (stream.codec_tag_string) { switch (stream.codec_tag_string) {
case 'mp4a': codecFrags.add(getMP4ACodecString(stream)); break; case 'mp4a': codecFrags.add(getMP4ACodecString(stream)); break;
// TODO: vorbis.
// TODO: opus.
default: default:
switch (stream.codec_name) { switch (stream.codec_name) {
case 'aac': codecFrags.add(getMP4ACodecString(stream)); break; case 'aac': codecFrags.add(getMP4ACodecString(stream)); break;
case 'vorbis': codecFrags.add('vorbis'); break;
case 'opus': codecFrags.add('opus'); break;
default: default:
throw `Could not handle codec_name ${stream.codec_name}, ` + throw `Could not handle codec_name ${stream.codec_name}, ` +
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` + `codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
@ -140,6 +140,7 @@ export function getFullMIMEString(info) {
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;
default: default:
throw `Could not handle codec_name ${stream.codec_name}, ` + throw `Could not handle codec_name ${stream.codec_name}, ` +
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` + `codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +

View file

@ -1,6 +1,6 @@
{ {
"name": "@codedread/bitjs", "name": "@codedread/bitjs",
"version": "1.0.4", "version": "1.0.5",
"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

@ -214,7 +214,7 @@ describe('codecs test suite', () => {
}); });
}); });
describe('VP09', () => { describe('VP09 / VP9', () => {
/** @type {ProbeInfo} */ /** @type {ProbeInfo} */
let info; let info;
@ -268,6 +268,16 @@ describe('codecs test suite', () => {
}); });
}); });
}); });
it('detects codec_name=vp9 but no codec_tag_string', () => {
info.streams[0].codec_name = 'vp9';
info.streams[0].codec_tag_string = '[0][0][0][0]';
info.streams[0].profile = 'Profile 0';
info.streams[0].level = 21; // 0x15
expect(getFullMIMEString(info))
.to.be.a('string')
.and.satisfy(s => s.startsWith('video/webm; codecs="vp09.00.15'));
});
}); });
describe('MP4A / AAC', () => { describe('MP4A / AAC', () => {
@ -306,4 +316,46 @@ describe('codecs test suite', () => {
.and.equals('audio/mp4; codecs="mp4a.40.2"'); .and.equals('audio/mp4; codecs="mp4a.40.2"');
}); });
}); });
describe('Vorbis', () => {
/** @type {ProbeInfo} */
let info;
beforeEach(() => {
info = {
format: { format_name: 'matroska,webm' },
streams: [{
codec_type: 'audio',
codec_name: 'vorbis',
}],
};
});
it('detects vorbis', () => {
expect(getFullMIMEString(info))
.to.be.a('string')
.and.equals('audio/webm; codecs="vorbis"');
});
});
describe('Opus', () => {
/** @type {ProbeInfo} */
let info;
beforeEach(() => {
info = {
format: { format_name: 'matroska,webm' },
streams: [{
codec_type: 'audio',
codec_name: 'opus',
}],
};
});
it('detects opus', () => {
expect(getFullMIMEString(info))
.to.be.a('string')
.and.equals('audio/webm; codecs="opus"');
});
});
}); });