What is the easiest way to wrap a raw .aac file into a .m4a container
Asked Answered
H

4

25

This question is overflow from the following question:

How do I programmatically convert mp3 to an itunes-playable aac/m4a file?

Anyway, I learned how to create an aac file and then i found out that an aac is not just an m4a file with a different file extension. In fact, I need to somehow wrap the aac into an m4a container. Ideally I'd be able to simply make a call to the command line.

Homs answered 16/9, 2008 at 8:57 Comment(1)
If you would like to do it the Java way without messing around with NDK and FFMPEG, then check my answer here.Darmstadt
C
6

mp4box if you want a dedicated tool; its probably the easiest way to go. ffmpeg can do the job too.

Cantu answered 16/9, 2008 at 10:18 Comment(6)
To add to this, ffmpeg usage is about as simple as "ffmpeg -i in.m4a -o out.aac". :)Ballonet
mp4box is roughly the same, and I'd recommend it over ffmpeg because it places the moov atom at the beginning rather than the end, which is important for progressive download, iPod playback, etc.Cantu
The format for ffmpeg actually is: “ffmpeg -i foo.aac foo.m4a”, wrapping raw aac into m4a.Lanark
Are you certain that isn't re-encoding it? See my answerDulosis
ffmpeg can also place the moov atom at the start: -movflags +faststart. Yes, that's with one o in movflags.Brunn
As stated by Alastair, you have to add an option -acodec copy, otherwise the stream is re-encoded.Amazonas
U
36

ffmpeg is a general purpose (de)muxer/transcoder. MP4Box is a (de)muxer/transcoder from GPAC, a package dedicated to MP4 related software tech. Right now it seems wiser to use MP4Box because it writes the moov atom at the beginning of the file, which is important for streaming and ipod playing.

Use ffmpeg like this:

ffmpeg -i input.aac -codec: copy output.m4a

Use MP4Box like this:

MP4Box -add input.aac#audio output.m4a
Undeviating answered 16/9, 2008 at 8:57 Comment(7)
@ColonelPanic Which did you try? How do you know it's not wrapping?Undeviating
The console output suggested that ffmpeg was re-encoding - it also took some time, and the file was a significantly different size. But the mp4box command worked perfectly and fast, thanks.Buoyancy
@ColonelPanic ffmpeg's man page says it needs a -codec copy. Thanks for catching that.Undeviating
No luck for me with either, ffmpeg said the input is corrupt, MP4Box converted but only wrote 1.5 seconds of the audio (it's actually 20 minutes long).Pulse
i used MP4Box, and i don't know if it matters, but i added -ipod at the end, and it worked fine with iTunes.Hallel
interesting thing that the resulting encapsuled m4a is smaller than the raw aac. it seems it is because there is a packet header that is shorter in m4a.Hallel
I rolled back an edit that suggested using ffmpeg -i input.aac -c:a copy -vn output.m4a to avoid problems with album art. That could be good advice when converting mp3 files, but in this q&a, we're talking about a raw aac file, which is not capable of having album art. The input is an audio stream, not a container.Undeviating
C
6

mp4box if you want a dedicated tool; its probably the easiest way to go. ffmpeg can do the job too.

Cantu answered 16/9, 2008 at 10:18 Comment(6)
To add to this, ffmpeg usage is about as simple as "ffmpeg -i in.m4a -o out.aac". :)Ballonet
mp4box is roughly the same, and I'd recommend it over ffmpeg because it places the moov atom at the beginning rather than the end, which is important for progressive download, iPod playback, etc.Cantu
The format for ffmpeg actually is: “ffmpeg -i foo.aac foo.m4a”, wrapping raw aac into m4a.Lanark
Are you certain that isn't re-encoding it? See my answerDulosis
ffmpeg can also place the moov atom at the start: -movflags +faststart. Yes, that's with one o in movflags.Brunn
As stated by Alastair, you have to add an option -acodec copy, otherwise the stream is re-encoded.Amazonas
D
4

avconv -i input.aac -acodec copy output.m4a

In my case, without the explicit flag to copy, it re-encodes the audio for some odd reason.

Dulosis answered 16/9, 2008 at 8:57 Comment(2)
Perhaps a word about avconv, what it is, where you get it, how it differs from ffmpeg?Sedlik
I have encountered the same situation with ffmpeg. Without adding this -acodec copyoption, the stream is re-encoded. But I don't think it's odd, I guess it's logical from the point of view of the command parser.Amazonas
S
2

Just use any mp4-Muxer like Yamb to create an mp4-file with only the aac audio track in it, then change the file extension to m4a.

Slating answered 16/9, 2008 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.