Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Mac OS X – Terminal – FFMPEG – Convert Music Files FLAC to MP3 or MP4 to MP3

Posted on October 11, 2016January 31, 2019 By David Kittell

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
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.

Related

Code Mac OS X Shell Mac OSX UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

Mac OSX Terminal – Add User to Remote Management (VNC)

Posted on November 16, 2016November 16, 2016

Replace “-users admin” with the username you need to grant access to. sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users admin -privs -all -restart -agent -menu 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…

Read More

Save Text To File

Posted on December 14, 2013October 26, 2015

Public Function SaveTextToFile(ByVal strData As String, ByVal FullPath As String, Optional ByVal ErrInfo As String = "") As Boolean Dim Contents As String = "" Dim bAns As Boolean = False Dim objReader As StreamWriter Try objReader = New StreamWriter(FullPath) objReader.Write(strData) objReader.Close() bAns = True Catch Ex As Exception ErrInfo…

Read More

SELinux Configuration Change

Posted on July 21, 2016December 21, 2017

clear sudo cp /etc/selinux/config /etc/selinux/config.bk sudo sed -i ‘/^#/d’ /etc/selinux/config sudo sed -i ‘/^$/d’ /etc/selinux/config SELinuxStatus=$(cat /etc/selinux/config | grep SELINUX=|cut -d’=’ -f2) echo Current Status: $SELinuxStatus clear # SELinux – Enforcing sudo sed -i "s|SELINUX=$SELinuxStatus|SELINUX=enforcing|" /etc/selinux/config SELinuxStatus=$(cat /etc/selinux/config | grep SELINUX=|cut -d’=’ -f2) echo New Status: $SELinuxStatus clear # SELinux…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes