1 year ago
#237918
Cambiata
Browser JS: How to extract aac audio data from a mp4 file?
Using browser JavaScript, I need to load mp4-files containing AAC audio data, and extract this audio data for later use.
There is an mdat
block in the mp4 file that (to my understanding) holds the embedded aac data, but just extracting the contents of that mdata block does not seem to give me valid aac data.
So, what is the simplest way to - in the browser - get embedded aac audio data out of a mp4 container file?
Edit:
Looking deeper into this, using some hexfile analysis, reveals the reason why aac decoding fails when just grabbing the data from the mdat block:
As seen in the illustration below - where the file structure of an example.aac file and an example.mp4 file containing the identical audio data are compared - there's a clear difference in the way data is stored:
In the original aac data, chunks of compressed audio data are separated with strings of something like FF F1 4C 80 ** ** FC
(red in illustration). In the mp4 version, the exact same data (green in illustration) doesn't have this separation.
To solve my case, I have to work backwards, I guess: Grab the compressed "unseparated" data from the .mp4 file, and "inject" the separating string in order to get aac decoders to recognize it as valid...
So, does anyone know where to find information about this "aac data-separating string" and how to in the browser inject it into the mp4 data resulting in a valid aac file block?
Edit2:
Further investigation shows that .mp4 stores the aac data as "aac raw", without 7 bytes ADTS headers separating the compressed audio frames.
Syu Kato's mp4.js script (https://github.com/ukyo/mp4.js) has an extractRawAudio(mp4DataAsUInt8Array)
method that can extract the raw aac data and inject the needed frame headers, wHich solves the problem for me.
javascript
audio
browser
mp4
aac
0 Answers
Your Answer