Prerequisite: Homebrew
Essentially you can convert just about anything but this script is specific to FLAC to MP3
<br> brew install ffmpeg --with-vpx --with-vorbis --with-libvorbis --with-vpx --with-vorbis --with-theora --with-libogg --with-libvorbis --with-gpl --with-version3 --with-nonfree --with-postproc --with-libaacplus --with-libass --with-libcelt --with-libfaac --with-libfdk-aac --with-libfreetype --with-libmp3lame --with-libopencore-amrnb --with-libopencore-amrwb --with-libopenjpeg --with-openssl --with-libopus --with-libschroedinger --with-libspeex --with-libtheora --with-libvo-aacenc --with-libvorbis --with-libvpx --with-libx264 --with-libxvid<br>
<br>
#!/bin/sh</p>
<p>clear</p>
<p># Declare main variables - start<br>
declare pkg="ffmpeg"<br>
declare MusicDir=$1<br>
# Declare main variables - stop</p>
<p>if [ -z ${1+x} ]; then<br>
echo "Music Directory is unset"<br>
echo "Example: sh ConvertMusic.sh ~/Music"<br>
exit 0<br>
fi</p>
<p>if brew list -1 | grep -q "^$pkg\$"; then<br>
echo "Package '$pkg' is installed"<br>
else<br>
echo "Package '$pkg' is not installed"<br>
brew install $pkg<br>
fi</p>
<p>cd $MusicDir</p>
<p>for f in *.flac;<br>
do<br>
echo "Processing:\n$f"<br>
ffmpeg -v quiet -i "$f" -ab 320k -map_metadata 0 -id3v2_version 3 "${f%.flac}.mp3";<br>
echo "Processed:\n$f"<br>
echo "Deleting:\n$f"<br>
rm -f "$f"<br>
echo "Moving MP3:\n${f%.flac}.mp3"<br>
mv "${f%.flac}.mp3" /Volumes/4TB/MusicFiles/mp3<br>
done<br>
To convert from MP4 to MP3 the code below will work
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
Originally Posted on October 11, 2016
Last Updated on January 31, 2019
Last Updated on January 31, 2019
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.