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..
Doug's AppleScripts for iTunes
including
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.
-
-
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
-
8Note 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 '18 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
-
1I 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
-
Slight variation on the above for example to fix the extensions: <code>
for i in *.m4a; do echo "${i%.*}.mp3" ; ffmpeg -i "$i" "${i%.*}.mp3"; done
– Mahesh Neelakanta Sep 2 '19 at 18:10 -
Another version to convert all mp3 files in a folder (from inside said folder):
for f in *.mp3 ; do b=`basename -s .mp3 $f` ; afconvert $f -o $b.m4a -f m4af -d aac ; done
– saschpe Nov 12 '20 at 11:37
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 .mp4
s 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):
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
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).
codec:a libmp3lame
andqscale: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