You are here

Merging m4a (aac) Audio Files

Error message

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).

I like to record the occasional audio stream for offline listening. Sometimes my recording software pauses and I end up with multiple captures and separate files. I've used tools like Amadeus to edit audio, but it decodes, then re-encodes audio upon saving or exporting. What I really wanted was simply to combine the two audio files, similar to how I use the cat command for text (and other format) files. Naturally, there was a solution on stackoverflow.com. The reason you can't just "cat" the two files together because of the metadata, and I should also point out that ffmpeg strips the metadata during the copying process. So you'll have to save & restore the metadata which is a fairly trivial task and beyond the scope of this article. Let's get to the details.

$ ffmpeg -i file1.m4a -acodec copy file1.aac
$ ffmpeg -i file2.m4a -acodec copy file2.aac
$ cat file1.aac file2.aac >>filenew.aac
$ ffmpeg -i filenew.aac -acodec copy -bsf:a aac_adtstoasc filenew.m4a

Having completed this process, I can attest that the resulting audio file played seamlessly and flawlessly.

Tags: