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.

Community
  • 1
  • 1
  • If you would like to do it the Java way without messing around with NDK and FFMPEG, then check my answer [here](http://stackoverflow.com/a/38369475/1188004). – Kingston Jul 14 '16 at 11:32

4 Answers4

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
djeikyb
  • 4,470
  • 3
  • 35
  • 42
  • @ColonelPanic Which did you try? How do you know it's not wrapping? – djeikyb Jan 29 '13 at 01: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. – Colonel Panic Jan 29 '13 at 19:42
  • 1
    @ColonelPanic ffmpeg's man page says it needs a `-codec copy`. Thanks for catching that. – djeikyb Jan 29 '13 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 '14 at 01:47
  • i used MP4Box, and i don't know if it matters, but i added `-ipod` at the end, and it worked fine with iTunes. – robotik Sep 06 '18 at 09:02
  • 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 06 '18 at 09:40
  • 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. – djeikyb Jun 20 '22 at 20:02
5

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

Dark Shikari
  • 7,941
  • 4
  • 26
  • 38
  • 4
    To add to this, ffmpeg usage is about as simple as "ffmpeg -i in.m4a -o out.aac". :) – porges Sep 16 '08 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. – Dark Shikari Sep 16 '08 at 10:39
  • 5
    The format for ffmpeg actually is: “ffmpeg -i foo.aac foo.m4a”, wrapping raw aac into m4a. – Smar Jan 18 '11 at 16:58
  • 1
    Are you certain that isn't re-encoding it? See [my answer](http://stackoverflow.com/a/22367988/1105203) – Alastair Mar 13 '14 at 02:37
  • ffmpeg can also place the moov atom at the start: `-movflags +faststart`. Yes, that's with one o in `movflags`. – MSalters Jun 15 '17 at 08:27
  • 2
    As stated by Alastair, you have to add an option `-acodec copy`, otherwise the stream is re-encoded. – Gras Double Jun 05 '18 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.

Alastair
  • 6,837
  • 4
  • 35
  • 29
  • 2
    Perhaps a word about `avconv`, what it is, where you get it, how it differs from `ffmpeg`? – einpoklum Jan 09 '16 at 21:39
  • I have encountered the same situation with ffmpeg. Without adding this `-acodec copy`option, 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. – Gras Double Jun 05 '18 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.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135