Skip to content

Commit 0b75c27

Browse files
committed
Update to 1.1.6 for mp3 streams and ffprobe reporting mp4 files with unknown levels
1 parent ce8f61d commit 0b75c27

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.1.6] - 2023-10-25
6+
7+
### Changed
8+
9+
- codecs: Special handling for mp3 streams inside mp4 containers.
10+
- codecs: Handle ffprobe level -99 in mp4 files.
11+
512
## [1.1.5] - 2023-10-22
613

714
### Changed

codecs/codecs.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ export function getFullMIMEString(info) {
141141

142142
for (const stream of info.streams) {
143143
if (stream.codec_type === 'audio') {
144+
// MP3 can sometimes have codec_tag_string=mp4a, so we check for it first.
145+
if (stream.codec_name === 'mp3') {
146+
codecFrags.add('mp3');
147+
continue;
148+
}
149+
144150
switch (stream.codec_tag_string) {
145151
case 'mp4a': codecFrags.add(getMP4ACodecString(stream)); break;
146152
default:
@@ -267,8 +273,8 @@ function getVP09CodecString(stream) {
267273
}
268274

269275
// Add LL hex digits.
270-
// If ffprobe is spitting out -99 as level... Just return 'vp9'.
271-
if (stream.level === -99) { return 'vp9'; }
276+
// If ffprobe is spitting out -99 as level... it means unknown, so we will guess level=1.
277+
if (stream.level === -99) { frag += `.10`; }
272278
else {
273279
const levelAsHex = Number(stream.level).toString(16).toUpperCase().padStart(2, '0');
274280
if (levelAsHex.length !== 2) {
@@ -279,8 +285,8 @@ function getVP09CodecString(stream) {
279285
}
280286

281287
// Add DD hex digits.
282-
// TODO: This is just a guess at DD (16?), need to try and extract this info from
283-
// ffprobe JSON output instead.
288+
// TODO: This is just a guess at DD (10-bit color depth), need to try and extract this info
289+
// from ffprobe JSON output instead.
284290
frag += '.10';
285291

286292
return frag;

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

tests/codecs.spec.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ describe('codecs test suite', () => {
349349
});
350350
});
351351

352-
it('detects level = -99', () => {
353-
info.streams[0].level = -99; // I'm not sure what ffprobe means by this.
352+
it('detects level = -99 as level 1', () => {
353+
info.streams[0].level = -99; // I believe this is the "unknown" value from ffprobe.
354354
expect(getFullMIMEString(info))
355355
.to.be.a('string')
356-
.and.equals('video/webm; codecs="vp9"');
356+
.and.equals('video/webm; codecs="vp09.00.10.10"');
357357
});
358358
});
359359

@@ -575,6 +575,18 @@ describe('codecs test suite', () => {
575575
});
576576
});
577577

578+
describe('MP3', () => {
579+
it('detects MP3', () => {
580+
/** @type {ProbeInfo} */
581+
let info = {
582+
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
583+
streams: [ { codec_type: 'audio', codec_name: 'mp3', codec_tag_string: 'mp4a' } ],
584+
};
585+
expect(getShortMIMEString(info)).equals('audio/mp4');
586+
expect(getFullMIMEString(info)).equals('audio/mp4; codecs="mp3"');
587+
});
588+
});
589+
578590
describe('WAV', () => {
579591
it('detects WAV', () => {
580592
/** @type {ProbeInfo} */

0 commit comments

Comments
 (0)