59

I tried to convert an .m4a file to an .mp3 file using ffmpeg with the following command:

$ ffmpeg -i music.m4a music.mp3

Unfortunately, I got a zero byte-sized file returned as output. The output of the command is as follows:

FFmpeg version 0.6-4:0.6-2ubuntu6.2, Copyright (c) 2000-2010 the FFmpeg developers
  built on Sep 16 2011 17:11:24 with gcc 4.4.5
  configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  WARNING: library configuration mismatch
  libavutil   configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavcodec  configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavformat configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavdevice configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavfilter configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libswscale  configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libpostproc configuration: --extra-version=4:0.6-2ubuntu6.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-vaapi --enable-pthreads --enable-zlib --enable-libvpx --disable-stripping --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-x11grab --enable-libdc1394 --shlibdir=/usr/lib/i686/cmov --cpu=i686 --enable-shared --disable-static --disable-ffmpeg --disable-ffplay
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.11. 0 /  0.11. 0
  libpostproc   51. 2. 0 / 51. 2. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'music.m4a':
  Metadata:
    major_brand     : M4A 
    minor_version   : 0
    compatible_brands: M4A mp42isom
  Duration: 00:00:03.41, start: 0.000000, bitrate: 66 kb/s
    Stream #0.0(und): Audio: aac, 44100 Hz, mono, s16, 63 kb/s
Output #0, mp3, to 'music.mp3':
    Stream #0.0(und): Audio: 0x0000, 44100 Hz, mono, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Encoder (codec id 86017) not found for output stream #0.0

How can I convert an .m4a sound file to an .mp3 file format?

11 Answers 11

50

This worked for me on Ubuntu 14.04:

avconv -i input.m4a ouptut.mp3

To obtain the avconv command, install libav-tools Install libav-tools:

sudo apt-get install libav-tools
  • 16
    FFMPEG is not deprecated. AvConv was a fork that decided to put that message in when somebody called it by the FFMPEG executable name – David Davies-Jones Apr 14 '16 at 10:53
  • 1
    FYI. As of 18.04, libav-tools and avconv are no longer included in repos. – Kevin Bowen Feb 15 at 23:58
  • Just using ffmpeg directly, as specified in the question, works fine for me with ffmpeg 4.1.3 on macOS 10.14.4. – Radon Rosborough May 6 at 15:33
40

The simple way to do it is:

ffmpeg -v 5 -y -i input.m4a -acodec libmp3lame -ac 2 -ab 192k output.mp3

If you want a script to wrap that, try aac2mp3, which should work for you. (The syntax for that last statement was pulled from there.) Inline code included below:

#!/bin/bash
#
# $Id: aac2mp3,v 1.2  03/30/2008 10:00 Daniel Tavares (dantavares@gmail.com) - 
# Based on Script -  rali Exp $
#
#
# Convert one or more AAC/M4A files to MP3.  Based on a script example
# I found at: http://gimpel.gi.funpic.de/Howtos/convert_aac/index.html
#
ME=`basename ${0}`
FFMPEG="/usr/bin/ffmpeg"
EXT="mp4"
BITRATE="128"
do_usage() {            # explanatory text
 echo "usage: ${ME} [-b nnn] [-e ext] [-f] [-c] [-r] [-v] [-h] [file list]"
 echo "       Convert music from AAC format to MP3"
 echo "  -m /path/app  Specify the location of ffmpeg(1)"
 echo "  -b nnn        bitrate for mp3 encoder to use"
 echo "  -e ext        Use .ext rather than .m4a extension"
 echo "  -f            Force overwrite of existing file"
 echo "  -c            Delete original AAC|M4A file(s)"
 echo "  -v            Verbose output"
 echo "  -h            This information"
 echo ""
 echo "For recursive directory, use: find -name '*.${EXT}' -exec ${ME} "{}" [args]     \;"
 exit 0
 }
do_error() {
 echo "$*"
 exit 1
 }
file_overwrite_check() {
 if [ "$FORCE" != "yes" ]
 then
   test -f "${1}" && do_error "${1} already exists."
 else
   test -f "${1}" && echo "  ${1} is being overwritten."
 fi
 }
create_mp3() {  # use ffmpeg(1) to convert from AAC to MP3
 file_overwrite_check "${2}"
 test $VERBOSE && echo -n "Converting file: ${1}"
 ${FFMPEG} -v 5 -y -i "${1}" -acodec libmp3lame -ac 2 -ab ${BITRATE}k "${2}";
 if [ $? -ne 0 ]
 then
   echo ""
   echo "Error!"
   do_cleanup
   do_error "Exiting"
 fi
 test $VERBOSE && echo ".  OK"
 }
do_cleanup() {  # Delete intermediate and (optionally) original file(s)
 test ${RMM4A} && rm -f "${1}"
 test $VERBOSE && echo ".  OK"
 }
do_set_bitrate() {
 test $VERBOSE && echo -n "Setting bitrate to: $1 kbps"
 BITRATE=$1
 test $VERBOSE && echo ".  OK"
 }
GETOPT=`getopt -o l:m:b:e:cfhrv -n ${ME} -- "$@"`
if [ $? -ne 0 ]
then
 do_usage
fi
eval set -- "$GETOPT"
while true
do
 case "$1" in
   -m) FFMPEG=$2 ; shift ; shift ;;
   -b) do_set_bitrate $2 ; shift ; shift ;;
   -e) EXT=$2 ; shift ; shift ;;
   -f) FORCE="yes" ; shift ;;
   -c) RMM4A="yes" ; shift ;;
   -v) VERBOSE="yes" ; shift ;;
   -h) do_usage ;;
   --) shift ; break ;;
    *)  do_usage ;;
 esac
done
test -f $FFMPEG || do_error "$FFMPEG not found. Use \"-m\" switch."
if [ $# -eq 0 ]
then                    # Convert all files in current directory
 for IFILE in *.${EXT}
 do
   if [ "${IFILE}" == "*.${EXT}" ]
   then
     do_error "Not found ${EXT} in this folder."
   fi
   OUT=`echo "${IFILE}" | sed -e "s/\.${EXT}//g"`
   create_mp3 "${IFILE}" "${OUT}.mp3"
   do_cleanup "${IFILE}" 
 done
else                    # Convert listed files
 for IFILE in "$*"
 do
   test -f "${IFILE}" || do_error "${IFILE} not found."  
   OUT=`echo "${IFILE}" | sed -e "s/\.${EXT}//g"`    
   create_mp3 "${IFILE}" "${OUT}.mp3"
   do_cleanup "${IFILE}"    
 done    
fi   
exit 0
  • 1
    Got (after many lines of text): Unknown encoder 'libmp3lame' Error! Exiting. With apt-get I can see libmp3lame0 and libmp3lame-dev. I tried to install libmp3lame0, but nothing changed. – Tom Brito Oct 11 '11 at 19:45
  • 1
    ffmpeg has been replaced by avconv in newer Ubuntu/Debian releases. See askubuntu.com/questions/432542/… and install libav-tools – Denilson Sá Maia May 25 '14 at 18:05
  • This does not work because ffmpeg is not in the Ubuntu repos...and nor are avconv or libav-tools. Could whoever is in charge of audio software please stop footling around and settle on something stable? – Peter Flynn Feb 20 '15 at 21:01
  • 'EXT="mp4"' needs to be changed to 'EXT="m4a"' according to the question. I would add the following explanatory text to make the understanding simpler: '# EXAMPLE: Will convert all files in the current directory with extension # "m4a" to "mp3" # bash SCRIPT_NAME -b 256 -v' – Eduardo Lucio Jan 4 '18 at 4:04
  • As of 15.04, ffmpeg is back in the repos: webupd8.org/2014/11/ffmpeg-returns-to-official-ubuntu.html As of 18.04, libav-tools and avconv are no longer available. – Kevin Bowen Feb 15 at 23:54
40

SoundConverter can do this without having to mess around on the command-line, and it's available in the Ubuntu Software Center:

Install via the software center

soundcoverter main window and prefs

conversion inprogress

  • If you have your files tagged by MusicBrainz, then find another solution: bugs.launchpad.net/soundconverter/+bug/1174949 – HDave Oct 5 '13 at 4:51
  • 3
    Christ on a crutch, what a mess. Soundconverter failed because Python was missing some packages, then it popped up an installer window for over 20 more packages, none of which it could install, of course, because it wasn't running as root, of course. Someone needs to rewrite the installer and the dependencies. – Peter Flynn Feb 20 '15 at 21:00
  • Program does not load Ubuntu 14.04 – Phillip Moxley Jul 14 '15 at 21:09
  • there is currently a bug in soundconverter related to m4a: bugs.launchpad.net/soundconverter/+bug/1512007 – krumpelstiltskin Dec 14 '15 at 19:30
  • 4
    I am trying to avoid messing around with the gui: I want to automate it. – ctrl-alt-delor Dec 3 '16 at 17:14
16

I needed an alternate solution because - my files were sitting in recursive subdirectories - I had spaces in paths.

So I eventually settled for :

 find . -type f -name '*.m4a' -exec bash -c 'avconv -i "$0" "${0/%m4a/mp3}"' '{}' \;

Then deleted the original files :

find . -type f -name '*.m4a' -exec bash -c 'rm "$0"' '{}' \;
  • 3
    For me, this is the top answer. A small point - the deletion can be expressed more succinctly as: find . -type f -name '*.m4a' -delete – Mark Slater Jan 12 '17 at 22:14
  • 2
    I modified the command by adding -y and -b:a 256k to make sure the program does not halt to ask for permission to overwrite existing mp3-files, and for a better quality (although I did not recognise a difference between the standard output of 128kbit/s (which was only half the bitrate my original m4a's had been): find . -type f -name '*.m4a' -exec bash -c 'avconv -i "$0" -y -b:a 256k "${0/%m4a/mp3}"' '{}' \; – Ben Oct 6 '17 at 22:52
  • 1
    This command can be used successfully by substituting 'ffmpeg' for 'avconv'. – Kevin Bowen Feb 15 at 23:51
9

I created a script to do this.

My requirements were:

  • Must maintain as many tags as possible
  • Must retain album artwork if exists
  • Must be 320K mp3s

Works on all m4a files in a directory, and outputs the new shiny Mp3s into a folder the script creates called Mp3. Warning; this script overwrites existing Mp3s in the output folder if they have the same name. Also uses files 'metadata.txt' and 'metadata2.txt' as temp files.

You'll need to install avconv if it doesn't exist already.

I couldn't figure out how to persist the 'Year' tag into ID3v1 tags, so I didn't enable that option.

#!/bin/bash
files=*.m4a
#create output folder if it doesnt exist
if [ ! -d Mp3 ]; then
        mkdir Mp3
fi

for file in $files; do
        mp3File=${file/%m4a/mp3}
        avconv -y -i "${file}" -f ffmetadata metadata.txt
        sed -e 's/^date=\(.*\)$/TYER=\1/' -e 's/^major_brand=.*$//' -e 's/^minor_version=.*$//' -e 's/^creation.*$//' -e 's/^compatible.*$//' -e 's/^encoder=.*$//' <metadata.txt >metadata2.txt
        avconv -y -i "${file}" -i metadata2.txt -ab 320k -map_metadata 1 -id3v2_version 3 "Mp3/${mp3File}"
done

Save it as 'convert.b', and then run the script by typing:

% bash convert.b
  • This is exactly what I'm looking for. – Rom098 Dec 25 '17 at 20:46
  • killer script, change the avconv to ffmpeg and that did the job. Please update the answer to include explanation for the various commands! – George Udosen Jun 21 at 10:06
5

Sometimes avconv and ffmpeg don't work so cleanly, so:

sudo apt-get install faad lame
faad myfile.m4a -w | lame - myfile.mp3

always works for me.

1

You probably need the unrestricted libav packages in medibuntu repository. Personally I would compile the latest ffmpeg with all codecs, as easy as 123 http://ubuntuforums.org/showthread.php?t=786095

  • 1
    If you don't want to compile ffmpeg: sudo apt-get install libavcodec-extra-53 – z7sg Jul 21 '12 at 11:31
1

On my L-Ubuntu, libav-tools was not available. I installed winff :

sudo apt-get install winff

which provides a graphical tool to convert audio and video files from and into many different formats.

Just tried : it works fine for .m4a to .mp3 :-)

Otherwise vlc also does a great job playing .m4a files :

sudo apt-get install vlc

0

Nautilus Script

This Nautilus Script allows user to convert selected file(s) like m4a files --skipping any mp3 or non-audio files-- to mp3 format in the same location using ffmpeg. The new mp3 files will have the highest variable bitrate and preserve most tags, except the year.

#!/bin/sh
#Nautilus Script to convert selected file(s) - excluding any non-audio and MP3 file(s) - to MP3 format at highest quality with VBR (Variable Bit Rate)
OLDIFS=$IFS
IFS="
"
for filename in $@; do
filetype="$(file -bi "$filename" | awk -F "; " '{print $1}' | awk -F "/" '{print $1}')"
if [ "$filetype" != audio ]; then
echo "Skip non-audio file"
else
filesubtype="$(file -bi "$filename" | awk -F "; " '{print $1}' | awk -F "/" '{print $2}')"
if [ "$filesubtype" != mpeg ]; then
file_name_in=$(basename "$filename")
file_name_out="$(basename "$filename" | sed 's/\.[^.]*$//').mp3"
ffmpeg -loglevel quiet -y -i "$file_name_in" -acodec libmp3lame -aq 0 "$file_name_out"
fi
fi
done
IFS=$OLDIFS
/usr/bin/canberra-gtk-play --id="dialog-information" &
notify-send "Selected file(s) converted to MP3 format, excluding any non-audio and MP3 file(s)" -i gtk-dialog-info -t 5 -u normal
0

I know this question is a bit old, but I think people still see this question (like me), so I share what I have found that worked for me and has a nice UI: fre:ac (https://www.freac.org/). To use in ubuntu just download the binary for ubuntu, decompress and run the file calle freac, that's it. Enjoy!

0

Old question, but I don't see a very simple solution: Use VLC

In VLC you can load a .m4a file and convert it to .MP3 very easyllie.

  1. Open VLC (no need to load any file)

  2. Click on Media or press CTRL+R

  3. Click on Conver/Save

  4. On Profile select MP3

  5. Select destination

  6. Click on Start and wait. To know if it doing something or not, look at the time bar.

I hope this will be usefull for somebody.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.