Recursively convert WMA files to MP3 using ffmeg on a Mac OS X bash shell
Posted by jpluimers on 2017/04/05
A friend of mine made the mistake to capture some CDs using WMA files and throwing away the CDs. His old Nokia could play them, but not his new iOS and Android devices.
ffmeg and bash to the rescue:
find . -iname "*.wma" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 192k "${NAME/.wma/.mp3}" -map_metadata 0:s:0 && rm "$NAME"' \;
Tricks used:
- find executing commands where the command is terminated by
\;
- using
execdir
so find switches to the directory where it executes the command - bash -c to execute a string as a comment
- the {} braces have the result of each find result, saving it in a $NAME variable then re-using it.
- the brew install ffmpeg edition
- using
-map_metadata
(or-map_meta_data
for older ffmpeg versions) so meta data is converted too - the && ensure that only after a succesful NAME assignment and ffmpeg MP3 conversion, rm removes the WMA file
- specifying ffmpeg bitrates is a bit underdocumented but -ab 192k limits the audio bitrate to 192k (-b:a 192k would dou the same).
–jeroen
Source:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -iname "*.wma" -execdir bash -c 'NAME="{}" && ffmpeg -y -i "$NAME" -ab 192k "${NAME/.wma/.mp3}" -map_metadata 0:s:0 && rm "$NAME"' \; |
Leave a Reply