23

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.

1
  • If you would like to do it the Java way without messing around with NDK and FFMPEG, then check my answer here.
    – Kingston
    Jul 14, 2016 at 11:32

4 Answers 4

33

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
7
  • @ColonelPanic Which did you try? How do you know it's not wrapping?
    – djeikyb
    Jan 29, 2013 at 1:11
  • 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. Jan 29, 2013 at 19:42
  • 1
    @ColonelPanic ffmpeg's man page says it needs a -codec copy. Thanks for catching that.
    – djeikyb
    Jan 29, 2013 at 21:43
  • 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).
    – Rob
    Jan 16, 2014 at 1:47
  • 1
    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.
    – robotik
    Sep 6, 2018 at 9:40
5

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

6
  • 4
    To add to this, ffmpeg usage is about as simple as "ffmpeg -i in.m4a -o out.aac". :)
    – porges
    Sep 16, 2008 at 10:36
  • 3
    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. Sep 16, 2008 at 10:39
  • 5
    The format for ffmpeg actually is: “ffmpeg -i foo.aac foo.m4a”, wrapping raw aac into m4a.
    – Smar
    Jan 18, 2011 at 16:58
  • 1
    Are you certain that isn't re-encoding it? See my answer
    – Alastair
    Mar 13, 2014 at 2:37
  • 2
    As stated by Alastair, you have to add an option -acodec copy, otherwise the stream is re-encoded. Jun 5, 2018 at 10:53
3

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.

2
  • 2
    Perhaps a word about avconv, what it is, where you get it, how it differs from ffmpeg?
    – einpoklum
    Jan 9, 2016 at 21:39
  • 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. Jun 5, 2018 at 11:24
1

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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.