Now, I know I can use iTunes to convert music. But it's quite a pain.. All I'm asking is: Is there anything built into OS X or UNIX for converting files? Right now I simply want to convert .mp4 to .mp3..

  • 2
    Do you consider open source packages as third party applications ? Or do you want to stick with Apple Products that ships with the OS only . Can you make that clear in your question ? – Sairam Sep 27 '11 at 8:37
  • I would like to do it with pre-loaded software. – James Litewski Sep 27 '11 at 9:00
  • 3
    A comment on the FFmpeg solution (lacking reputation). Output quality control for MP3 can be done via codec:a libmp3lame and qscale:a [0-9] options (see FFmpeg wiki). For instance, to get VBR in a 140-185 kbit/s range use: ffmpeg out.mp3 -i in.mp4 -codec:a libmp3lame -qscale:a 4 This can also be used to reduce MP3 files size. – trybik Nov 12 '14 at 13:11
up vote 15 down vote accepted

Doug's AppleScripts for iTunes

including

Convert and Export 2.0

is a collection of useful scripts that you can run from the Finder or the command line. Of course they all use iTunes to process data, but you might find it more convenient than having to use iTunes' GUI and mouse commands to convert files.

  • How do you run this script? I see no instructions on the site. – CoolAJ86 Aug 15 '12 at 14:57
  • Installation and configuration instructions from the guy providing the scripts are here: dougscripts.com/itunes/itinfo/downloadfaq.php – user9290 Aug 15 '12 at 18:01
  • 7
    Note to those that don't know: this is not a commandline solution. It puts an icon up in the iTunes toolbar. You must select a collection of songs, then select the script from the dropdown menu. It will default to 256Kbps for AAC. It's not mentioned anywhere in the documentation (that I could find), but you can see it in the screencast in the very last 2 or 3 seconds. – CoolAJ86 Aug 15 '12 at 20:40

I installed ffmpeg via MacPorts, although it also available via Homebrew (brew install ffmpeg) or download the binary.

To convert something like that, (without worrying about audio quality, which I know nothing about), I just use:

ffmpeg -i input.mp4 output.mp3

Here is an example of how you would convert a .wav file to .mp3 from their website:

ffmpeg -i input.wav -codec:a libmp3lame -qscale:a 2 output.mp3 

Here is an example of how to find all .wav files larger than 50M, convert them to mp3 and then delete the original wav (aka, batch mode -- alter the find command to create your 'batch')

find . -size +50M -iname *.wav -type f -exec ffmpeg -i {} -codec:a libmp3lame -qscale:a 2 {}.mp3 -y \; -exec /bin/rm {} \;
  • Thanks for the easy answer. How to convert list of files? Also does it have serial or parallel options? – Khaled Annajar May 30 at 12:26

OS X does not ship with any MP3 encoder apart from the one in iTunes. For converting to mpeg4 audio you can use the CLI command afconvert (afconvert -h for available options). For example:

afconvert track.aiff -o track.m4a -q 127 -b 128000 -f m4af -d aac

Help for this tool can be found by running "afconvert --help" as "man afconvert" doesn't point to a useful manual page.

  • 1
    +1 but I really wish somebody would add a pointer to exhaustive documentation. I have gotten it to work through trial and error and guesswork, but many of the options I should perhaps have been using are very very briefly documented. – tripleee Mar 7 '13 at 9:55
  • 3
    The man page is next to useless... :-( – Greenonline May 31 '15 at 8:06
  • 1
    I found this tutorial to be informative. Valid arguments for data and file formats can be seen using afconvert -hf – chb Oct 9 '17 at 2:02

afconvert will not write .mp3 files. Even though it is listed in the help as a format:

MacBook-Pro:local user$ afconvert -hf
Audio file and data formats:
    '3gpp' = 3GP Audio (.3gp)
               data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aach' 'aacl' 
                             'aacp' 'samr' 
    '3gp2' = 3GPP-2 Audio (.3g2)
               data_formats: 'Qclp' 'aac ' 'aace' 'aacf' 'aach' 'aacl' 
                             'aacp' 'samr' 
    'adts' = AAC ADTS (.aac, .adts)
               data_formats: 'aac ' 'aach' 'aacp' 
    'ac-3' = AC3 (.ac3)
               data_formats: 'ac-3' 
    'AIFC' = AIFC (.aifc, .aiff, .aif)
               data_formats: I8 BEI16 BEI24 BEI32 BEF32 BEF64 UI8 'ulaw' 
                             'alaw' 'MAC3' 'MAC6' 'ima4' 'QDMC' 'QDM2' 
                             'Qclp' 'agsm' 
    'AIFF' = AIFF (.aiff, .aif)
               data_formats: I8 BEI16 BEI24 BEI32 
    'amrf' = AMR (.amr)
               data_formats: 'samr' 
    'm4af' = Apple MPEG-4 Audio (.m4a, .m4r)
               data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp' 
                             'alac' 'paac' 
    'm4bf' = Apple MPEG-4 AudioBooks (.m4b)
               data_formats: 'aac ' 'aace' 'aacf' 'aach' 'aacl' 'aacp' 
                             'paac' 
    'caff' = CAF (.caf)
               data_formats: '.mp1' '.mp2' '.mp3' 'QDM2' 'QDMC' 'Qclp' 
                             'Qclq' 'aac ' 'aace' 'aacf' 'aach' 'aacl' 
                             'aacp' 'alac' 'alaw' 'dvi8' 'ilbc' 'ima4' 
                             I8 BEI16 BEI24 BEI32 BEF32 BEF64 LEI16 LEI24 
                             LEI32 LEF32 LEF64 'ms\x00\x02' 'ms\x00\x11' 
                             'ms\x001' 'paac' 'samr' 'ulaw' 
    'MPG1' = MPEG Layer 1 (.mp1, .mpeg, .mpa)
               data_formats: '.mp1' 
    'MPG2' = MPEG Layer 2 (.mp2, .mpeg, .mpa)
               data_formats: '.mp2' 
    'MPG3' = MPEG Layer 3 (.mp3, .mpeg, .mpa)
               data_formats: '.mp3'

If you attempt to use it:

/usr/bin/afconvert -d '.mp3' -f MPG3 mysong.MP4 -o mysong.mp3

then an error occurs:

Error: ExtAudioFileSetProperty ('cfmt') failed ('fmt?')

As explained on afconvert MPG3?

'Core Audio can read, but not write, MP3 files...'

I ended up using zpletan's answer and installed ffmpeg

brew install ffmpeg

and the following script, placed in the same directory as the .MP4 files that I want to convert. It also works for files with spaces:

#!/bin/sh -x
for f in *.MP4; do
        /usr/local/Cellar/ffmpeg/2.5.4/bin/ffmpeg -i "$f" "$f.mp3"
#        /usr/bin/afconvert -d '.mp3' -f MPG3 "$f" -o "$f.mp3"
        echo "$f converted"
done

There's also the X Lossless Decoder - a lossless audio decoder for Mac OS X available as a command line tool and a GUI app. The GUI version supports MP3 as output format.

I compiled libav from source to serve this purpose. This is the same package installed by default on recent versions of Ubuntu Linux so tutorials for Ubuntu works almost as-is on OS X with libav.

Here is something I do to convert MP4 (AAC) to MP3 (using LAME) using command line and a makefile (for the sake of parallelism):

for each in *.mp4; do mv "$each" "$(echo "$each" | sed "s/ /./g")"; done
cat << EOF > Makefile
MP4_FILES := $(wildcard *.mp4)
MP3_FILES := ${MP4_FILES:.mp4=.mp3}

all: $(MP3_FILES)

%.mp3: %.mp4
    avconv -i $< -c:a libmp3lame $@
EOF
make -j20

Adjust the number after -j of the make command to about 1.5x your processor core number. My server had 24 cores but -j24 gave me serious IO bottleneck, throttled it back to -j20 and the performance is pretty well balanced.

I hadn't used it for a decade but I love ecasound for converting sound files.

If you have brew set up:

brew install ecasound

ecasound -i input.mp4 -o output.mp3

I haven't tried it with .mp4s myself but it should work.

I just bumped into this question when looking to convert wav into flac.

With automator, define a service (Thanks DIGITALHOBBIT'S MUSIC BLOG for the idea): enter image description here

And shell script is the following:

    # -----------------------------
    # DESCRIPTION
    #   Export iTunes Music to another destination to get only MP3 files
    #       - Copy MP3 to Destination
    #       - Convert M4A in MP3 in Destination
    #
    # -----------------------------
    # DATE      : 06-Apr-2017
    # AUTHOR    : JF LE MADEC
    # VERSION   : 1.0
    # -----------------------------

    # Local iTunes Directory
    ITUNDIR="$HOME/Music/iTunes/iTunes Media/Music"

    # binary to convert audio files
    AFCONVERT="afconvert"
    # conversion paramaters
    AFCPARAM="-f mp4f -d aac -b 128000"

    # Audio files suffixes
    # Source
    M4ASUF=".m4a"
    # Destination
    MP3SUF=".mp3"

    # for all directories given in arguments copy music
    for destination in "$@"
    do

        # Copy MP3 files
        find "$ITUNDIR" -name "*$MP3SUF" | while read myMp3File; do
            mp3dir=`dirname "$myMp3File"`
            targetDir="$destination${mp3dir#$ITUNDIR}"
            fileName=`basename "$mp3File"`
            [[ -d "$targetDir" ]] || mkdir -p "$targetDir"
            cp -R "$myMp3File" "$targetDir"
        done

        # Convert and copy M4A files (iTunes native)
        find "$ITUNDIR" -name "*$M4ASUF" | while read m4aFile; do
            #afconvert -f mp4f -d aac -b 128000 "./Vianney/Vianney/11 Le Galopin.m4a"  /Users/jflm/Desktop/output2.mp3
            # Get file info
            m4aDir=`dirname "$m4aFile"`
            targetDir="$destination${m4aDir#$ITUNDIR}"
            fileName=`basename -s $M4ASUF "$m4aFile"`
            # Create parent directories if not exist
            [[ -d "$targetDir" ]] || mkdir -p "$targetDir"

            # Convert audio file directly in destination directory
            $AFCONVERT $AFCPARAM "$m4aFile" "$targetDir/$fileName$MP3SUF"

        done
    done
  • Did you mean aac or mp3 in AFCPARAM="-f mp4f -d aac -b 128000"? – John N Apr 6 '17 at 16:04

Under linux, I find python-audio-tools does exactly what I want. Unfortunately, I haven't been able to get it to encode to mp3 under OSX. It might work for you, though. It's not at all built into OSX, but it's very lightweight and can convert between pretty much any pair of formats (or just convert to a more compressed file with the same format).

protected by Community Apr 9 '17 at 11:06

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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