Skip to content

Commit

Permalink
Update to 1.1.6 for mp3 streams and ffprobe reporting mp4 files with …
Browse files Browse the repository at this point in the history
…unknown levels
  • Loading branch information
codedread committed Oct 26, 2023
1 parent ce8f61d commit 0b75c27
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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

## [1.1.6] - 2023-10-25

### Changed

- codecs: Special handling for mp3 streams inside mp4 containers.
- codecs: Handle ffprobe level -99 in mp4 files.

## [1.1.5] - 2023-10-22

### Changed
Expand Down
14 changes: 10 additions & 4 deletions codecs/codecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ export function getFullMIMEString(info) {

for (const stream of info.streams) {
if (stream.codec_type === 'audio') {
// MP3 can sometimes have codec_tag_string=mp4a, so we check for it first.
if (stream.codec_name === 'mp3') {
codecFrags.add('mp3');
continue;
}

switch (stream.codec_tag_string) {
case 'mp4a': codecFrags.add(getMP4ACodecString(stream)); break;
default:
Expand Down Expand Up @@ -267,8 +273,8 @@ function getVP09CodecString(stream) {
}

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

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

return frag;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codedread/bitjs",
"version": "1.1.5",
"version": "1.1.6",
"description": "Binary Tools for JavaScript",
"homepage": "https://github.com/codedread/bitjs",
"author": "Jeff Schiller",
Expand Down
18 changes: 15 additions & 3 deletions tests/codecs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ describe('codecs test suite', () => {
});
});

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

Expand Down Expand Up @@ -575,6 +575,18 @@ describe('codecs test suite', () => {
});
});

describe('MP3', () => {
it('detects MP3', () => {
/** @type {ProbeInfo} */
let info = {
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
streams: [ { codec_type: 'audio', codec_name: 'mp3', codec_tag_string: 'mp4a' } ],
};
expect(getShortMIMEString(info)).equals('audio/mp4');
expect(getFullMIMEString(info)).equals('audio/mp4; codecs="mp3"');
});
});

describe('WAV', () => {
it('detects WAV', () => {
/** @type {ProbeInfo} */
Expand Down

0 comments on commit 0b75c27

Please sign in to comment.