Skip to content

Commit e072b35

Browse files
committed
Fix for m4a files as audio/mp4. Up-rev to 1.1.2.
1 parent a7d3294 commit e072b35

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

CHANGELOG.md

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

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

5+
## [1.1.2] - 2023-09-30
6+
7+
- codecs: Handle m4a files as audio/mp4.
8+
59
## [1.1.1] - 2023-06-21
610

711
- Fix missing RarVM import in unrar.js.

codecs/codecs.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export function getShortMIMEString(info) {
5858
return 'audio/flac';
5959
}
6060

61+
// M4A files are specifically audio/mp4.
62+
if (info?.format?.filename?.toLowerCase().endsWith('.m4a')) {
63+
return 'audio/mp4';
64+
}
65+
6166
// Otherwise, any file with at least 1 video stream is considered video/.
6267
// Otherwise, any file with at least 1 audio stream is considered audio/.
6368
const type = info.streams.some(s => s.codec_type === 'video') ?

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

tests/codecs.spec.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ describe('codecs test suite', () => {
7575
})).equals('audio/mpeg');
7676
});
7777

78+
it('detects M4A audio', () => {
79+
expect(getShortMIMEString({
80+
format: { filename: 'sample.m4a', format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
81+
streams: [ { codec_type: 'video', }, { codec_type: 'audio' } ],
82+
})).equals('audio/mp4');
83+
});
84+
7885
it('detects MP4 video', () => {
7986
expect(getShortMIMEString({
8087
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
@@ -306,24 +313,21 @@ describe('codecs test suite', () => {
306313

307314
describe('MP4A / AAC', () => {
308315
/** @type {ProbeInfo} */
309-
let info;
310-
311-
beforeEach(() => {
312-
info = {
313-
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
314-
streams: [{
315-
codec_type: 'audio',
316-
codec_tag_string: 'mp4a',
317-
}],
318-
};
319-
});
316+
let baseInfo = {
317+
format: { format_name: 'mov,mp4,m4a,3gp,3g2,mj2' },
318+
streams: [{
319+
codec_type: 'audio',
320+
codec_tag_string: 'mp4a',
321+
}],
322+
};
320323

321324
it('throws when unknown', () => {
322-
expect(() => getFullMIMEString(info)).to.throw();
325+
expect(() => getFullMIMEString(baseInfo)).to.throw();
323326
});
324327

325328
describe('Profile tests', () => {
326329
it('recognizes AAC-LC', () => {
330+
const info = structuredClone(baseInfo);
327331
info.streams[0].profile = 'LC';
328332
expect(getFullMIMEString(info))
329333
.to.be.a('string')
@@ -332,13 +336,24 @@ describe('codecs test suite', () => {
332336
});
333337

334338
it('handles codec_name=aac but no codec_tag_string', () => {
339+
const info = structuredClone(baseInfo);
335340
info.streams[0].profile = 'LC';
336341
info.streams[0].codec_tag_string = '[0][0][0][0]';
337342
info.streams[0].codec_name = 'aac';
338343
expect(getFullMIMEString(info))
339344
.to.be.a('string')
340345
.and.equals('audio/mp4; codecs="mp4a.40.2"');
341346
});
347+
348+
it('handles m4a file with MJPEG stream', () => {
349+
const info = structuredClone(baseInfo);
350+
info.format.filename = 'sample.m4a';
351+
info.streams[0].profile = 'LC';
352+
info.streams.push({codec_name: 'mjpeg', codec_type: 'video', profile: 'Baseline'});
353+
expect(getFullMIMEString(info))
354+
.to.be.a('string')
355+
.and.equals('audio/mp4; codecs="mp4a.40.2"');
356+
})
342357
});
343358

344359
describe('MP4 / FLAC', () => {
@@ -374,7 +389,7 @@ describe('codecs test suite', () => {
374389
expect(getFullMIMEString(vInfo))
375390
.to.be.a('string')
376391
.and.equals('video/mp4; codecs="flac"');
377-
392+
378393
});
379394
});
380395

0 commit comments

Comments
 (0)