Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for aac format #208

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added fixture/fixture-adts-2.aac
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion index.d.ts
Expand Up @@ -99,7 +99,8 @@ declare namespace fileType {
| 'lnk'
| 'alias'
| 'voc'
| 'ac3';
| 'ac3'
| 'aac';

interface FileTypeResult {
/**
Expand Down
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -443,7 +443,7 @@ const fileType = input => {
check([0xFF, 0xF0], {offset: start, mask: [0xFF, 0xFC]}) // MPEG 4 layer 0 using ADTS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAAAAAAA AAAABCCD

Letter Length (bits) Description
A 12 syncword 0xFFF, all bits must be 1
B 1 MPEG Version: 0 for MPEG-4, 1 for MPEG-2
C 2 Layer: always 0
D 1 protection absent, Warning, set to 1 if there is no CRC and 0 if there is CRC

2nd byte check should be 0b11110000(0xF0) with mask 0b11111110(0xFE) for aac then(and remaining options caught separately).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, shouldn't mpeg2 be caught too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There actually already is an ADTS/MPEG-2/ACC test file, originating from PR #136. Currently with .mp2 extension, it looks like to reverse engineered the extension based on the MPEG version.

Okay, lets assume this is ext. .acc mime audio/acc candidate as well.

) {
return {
ext: 'mp4',
ext: 'aac',
mime: 'audio/mpeg'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Media type should probably be audio/aac, it's standardized.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Media type should probably be audio/aac, it's standardized.

I think you are right: (ref)

"audio/aac" for sequences of ADTS frames, as specified in ISO/IEC 14496-3:2009

};
}
Expand Down
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -221,6 +221,7 @@ Type: [`stream.Readable`](https://nodejs.org/api/stream.html#stream_class_stream
- [`alias`](https://en.wikipedia.org/wiki/Alias_%28Mac_OS%29) - macOS Alias file
- [`voc`](https://wiki.multimedia.cx/index.php/Creative_Voice) - Creative Voice File
- [`ac3`](https://www.atsc.org/standard/a522012-digital-audio-compression-ac-3-e-ac-3-standard-12172012/) - ATSC A/52 Audio File
- [`aac`](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) - Advanced Audio Coding

*SVG isn't included as it requires the whole file to be read, but you can get it [here](https://github.com/sindresorhus/is-svg).*

Expand Down
27 changes: 17 additions & 10 deletions test.js
Expand Up @@ -108,7 +108,9 @@ const types = [
'lnk',
'alias',
'voc',
'ac3'
'ac3',
'pcap',
'aac'
];

// Define an entry here only if the fixture has a different
Expand Down Expand Up @@ -153,8 +155,7 @@ const names = {
'fixture-isomv2',
'fixture-mp4v2',
'fixture-m4v',
'fixture-dash',
'fixture-aac-adts'
'fixture-dash'
],
tif: [
'fixture-big-endian',
Expand Down Expand Up @@ -199,6 +200,10 @@ const names = {
tar: [
'fixture',
'fixture-v7'
],
aac: [
'fixture-adts',
'fixture-adts-2'
]
};

Expand Down Expand Up @@ -257,13 +262,15 @@ for (const type of types) {
}
}

test('.stream() method - empty stream', async t => {
const emptyStream = fs.createReadStream('/dev/null');
await t.throwsAsync(
fileType.stream(emptyStream),
/Expected the `input` argument to be of type `Uint8Array` /
);
});
if (process.platform !== 'win32') {
test('.stream() method - empty stream', async t => {
const emptyStream = fs.createReadStream('/dev/null');
await t.throwsAsync(
fileType.stream(emptyStream),
/Expected the `input` argument to be of type `Uint8Array` /
);
});
}

test('fileType.minimumBytes', t => {
t.true(fileType.minimumBytes > 4000);
Expand Down