Skip to main content

Topic: How to store MP3 in an MP4 container (Read 2107 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • Jebus
  • [*][*][*][*][*]
  • Developer
How to store MP3 in an MP4 container
I understand it is possible to store audio layer III files in an MPEG-4 part 14 (aka .mp4 or .m4a) container. Any ideas what software can do this?

I'd like to be able to detect this in my own software, so would like to generate some test cases.

  • Porcus
  • [*][*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #1
ffmpeg. My version refuses to give it the .m4a suffix though.
Code: [Select]
ffmpeg -i filename.mp3 -codec copy filename.mp4 
works, but not if you write "m4a" in place of "mp4"

  • kode54
  • [*][*][*][*][*]
  • Administrator
Re: How to store MP3 in an MP4 container
Reply #2
And it probably doesn't translate the LAME/Xing/FHG/whatever gapless info tags into MP4 chapters or iTunsMPB tags for MP4 gapless playback, so use with caution.

  • polemon
  • [*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #3
ffmpeg. My version refuses to give it the .m4a suffix though.
Code: [Select]
ffmpeg -i filename.mp3 -codec copy filename.mp4 
works, but not if you write "m4a" in place of "mp4"
Could you do a
Code: [Select]
ffmpeg -version
for us?

Here's mine:

ffmpeg version 3.3.3-static http://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 6.4.0 (Debian 6.4.0-2) 20170724
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
libavutil      55. 58.100 / 55. 58.100
libavcodec     57. 89.100 / 57. 89.100
libavformat    57. 71.100 / 57. 71.100
libavdevice    57.  6.100 / 57.  6.100
libavfilter     6. 82.100 /  6. 82.100
libswscale      4.  6.100 /  4.  6.100
libswresample   2.  7.100 /  2.  7.100
libpostproc    54.  5.100 / 54.  5.100

I like John's FFmpeg builds. They come with Vid.Stab should anyone ever need them, etc. And he updates regularly. The only thing that's missing and that I'd love to have at my disposal, is if it were compiled with libfdk_aac.

It seems FFmpeg refuses to put anything into a file suffixed with ".m4a" unless the codec is an AAC codec.
Code: [Select]
ffmpeg -i audio.mp3 -c:a aac audio.m4a
works as expected, but
Code: [Select]
ffmpeg -i audio.mp3 -c:a copy audio.m4a
does not. Looks to me more like an oversight, to be honest. FFmpeg says it cannot find a codec tag for that format, I believe someone simply forgot to make sure MP3 is among the codecs supported in an m4a file.

Someone may or may not make a bug report?

  • Porcus
  • [*][*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #4
Polemon:
ALAC goes into .m4a as well.

I also have 3.3.3. By way of chocolatey.

Code: [Select]
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 7.1.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
libavutil      55. 58.100 / 55. 58.100
libavcodec    57. 89.100 / 57. 89.100
libavformat    57. 71.100 / 57. 71.100
libavdevice    57.  6.100 / 57.  6.100
libavfilter    6. 82.100 /  6. 82.100
libswscale      4.  6.100 /  4.  6.100
libswresample  2.  7.100 /  2.  7.100
libpostproc    54.  5.100 / 54.  5.100

  • polemon
  • [*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #5
Yet, I've never heard or read anything about leaving MP3 specifically out MP4 such that a .m4a file cannot contain it. I don't remember being that part of any spec.

Can MP2 be contained in a MP4 such that .m4a is a valid MP2 file? Is there a guideline at all?

  • Porcus
  • [*][*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #6
such that .m4a is a valid MP2 file?
A valid mp4 file. With a valid mp2 stream. ffmpeg does it (as ".mp4", rename it manually).

A few quirks in ffmpeg and foobar2000:

* ffmpeg refuses to write ".m4a", as said. ffmpeg has no issues reading the manually renamed .m4a though, and extracting from it.

* ffmpeg -i mymp2.mp2 -acodec copy mp2tomp3test.mp3 fails.

* But remuxing to an mp4 and then to an mp3, using
ffmpeg -i  mynewmp4.m4a -acodec copy mp4tomp3test.mp3
does work, albeit with an error message of an invalid audio packet. It puts the mp2 stream in a file with .mp3 suffix. Comparing with the same operation except writing to an mp2 file, fb2k gives an offset of 48 but otherwise identical stream. The mp2 is bit-identical (no offset) to the original mp2.

* foobar2000 reports, erroneously, the .mp3 file and the .mp4/.m4a  file as having "MP3" as codec.


Quite a lot of metadata gets mangled in the remuxing though.

  • polemon
  • [*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #7
Yeah, it all seems to be an oversight / incompleteness on FFmpeg's side of things. As far as I can tell, the endings .m4a and .m4v are informal, and each should contain only an audio or video stream, respectively. Since both endings are a bog-standard MP4 file there's really nothing stopping either to be anything.

As far as I can tell, the ending .m4a was kinda invented by Apple to make it easier to distinguish between files containing both, audio and video (what one might consider a regular video). There seem to be no spec for it, though.

I heard that the ending .aac is supposed to be only used for raw AAC streams, but I might remember incorrectly.

  • polemon
  • [*][*][*][*]
Re: How to store MP3 in an MP4 container
Reply #8
https://en.wikipedia.org/wiki/MPEG-4_Part_14#.MP4_versus_.M4A <-- it really seems to be an error.

It seems there are dumber extensions, too. .m4r for ringtones, I don't see the point at all, since most ringtones are just sound files anyway these days. .m4p is for DRM protected files. I guess the 'p' in there is for "paid" or "protected"? Cumersome, but I can see use in that. .m4b is supposedly for audiobooks and podcasts. Wikipedia states, that while a regular MP4 file is not book-mark-able, those files are. So, the files aren't identical afterall? Using .m4v for video only makes the most sense in that bunch. And shouldn't there be an extra file extention for files containing only subtitles?

Re: How to store MP3 in an MP4 container
Reply #9
You also can go and specify the output format and it writes the files without inferring it from the extension, usefull to write to non standard extensions.

Code: [Select]
ffmpeg -i filename.mp3 -codec copy -f mp4 filename.m4a