Skip to content

Commit d3b8765

Browse files
committed
Add vorbis/opus support in codecs.
1 parent 2a37f87 commit d3b8765

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

codecs/codecs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export function getFullMIMEString(info) {
116116
if (stream.codec_type === 'audio') {
117117
switch (stream.codec_tag_string) {
118118
case 'mp4a': codecFrags.add(getMP4ACodecString(stream)); break;
119-
// TODO: vorbis.
120-
// TODO: opus.
121119
default:
122120
switch (stream.codec_name) {
123121
case 'aac': codecFrags.add(getMP4ACodecString(stream)); break;
122+
case 'vorbis': codecFrags.add('vorbis'); break;
123+
case 'opus': codecFrags.add('opus'); break;
124124
default:
125125
throw `Could not handle codec_name ${stream.codec_name}, ` +
126126
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +
@@ -140,6 +140,7 @@ export function getFullMIMEString(info) {
140140
default:
141141
switch (stream.codec_name) {
142142
case 'h264': codecFrags.add(getAVC1CodecString(stream)); break;
143+
case 'vp9': codecFrags.add(getVP09CodecString(stream)); break;
143144
default:
144145
throw `Could not handle codec_name ${stream.codec_name}, ` +
145146
`codec_tag_string ${stream.codec_tag_string} for file ${info.filename} yet. ` +

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.4",
3+
"version": "1.0.5",
44
"description": "Binary Tools for JavaScript",
55
"homepage": "https://github.com/codedread/bitjs",
66
"author": "Jeff Schiller",

tests/codecs.spec.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('codecs test suite', () => {
214214
});
215215
});
216216

217-
describe('VP09', () => {
217+
describe('VP09 / VP9', () => {
218218
/** @type {ProbeInfo} */
219219
let info;
220220

@@ -268,6 +268,16 @@ describe('codecs test suite', () => {
268268
});
269269
});
270270
});
271+
272+
it('detects codec_name=vp9 but no codec_tag_string', () => {
273+
info.streams[0].codec_name = 'vp9';
274+
info.streams[0].codec_tag_string = '[0][0][0][0]';
275+
info.streams[0].profile = 'Profile 0';
276+
info.streams[0].level = 21; // 0x15
277+
expect(getFullMIMEString(info))
278+
.to.be.a('string')
279+
.and.satisfy(s => s.startsWith('video/webm; codecs="vp09.00.15'));
280+
});
271281
});
272282

273283
describe('MP4A / AAC', () => {
@@ -306,4 +316,46 @@ describe('codecs test suite', () => {
306316
.and.equals('audio/mp4; codecs="mp4a.40.2"');
307317
});
308318
});
319+
320+
describe('Vorbis', () => {
321+
/** @type {ProbeInfo} */
322+
let info;
323+
324+
beforeEach(() => {
325+
info = {
326+
format: { format_name: 'matroska,webm' },
327+
streams: [{
328+
codec_type: 'audio',
329+
codec_name: 'vorbis',
330+
}],
331+
};
332+
});
333+
334+
it('detects vorbis', () => {
335+
expect(getFullMIMEString(info))
336+
.to.be.a('string')
337+
.and.equals('audio/webm; codecs="vorbis"');
338+
});
339+
});
340+
341+
describe('Opus', () => {
342+
/** @type {ProbeInfo} */
343+
let info;
344+
345+
beforeEach(() => {
346+
info = {
347+
format: { format_name: 'matroska,webm' },
348+
streams: [{
349+
codec_type: 'audio',
350+
codec_name: 'opus',
351+
}],
352+
};
353+
});
354+
355+
it('detects opus', () => {
356+
expect(getFullMIMEString(info))
357+
.to.be.a('string')
358+
.and.equals('audio/webm; codecs="opus"');
359+
});
360+
});
309361
});

0 commit comments

Comments
 (0)