Friday, August 3, 2012

Use VLC to Bulk Convert WMA to MP3

I had a pile of WMA files that I wanted to bulk convert to mp3 and I did not want to pay for some shareware solution.   I settled on using a bash script that invoked VLC to do the job.  I found several good examples online of how to do this:
http://jcandrioli.wordpress.com/2010/11/24/how-to-convert-wma-to-mp3-using-vlc-instead-of-mplayer/
http://wiki.videolan.org/Transcode

I settled on the videolan wiki as my method of choice.

To start you need to have VLC and ffmpeg installed; the first url has an example of getting those on Ubuntu based systems.  After you have those you need to write a short bash file to do the work.

#!/bin/bash
acodec="mp3"
arate="128"
ext="mp3"
mux="ffmpeg"
vlc="/usr/bin/vlc"
fmt="wma"

for a in *$fmt; do
$vlc -I dummy -vvv "$a" --sout "#transcode{acodec=$acodec}:standard{mux=$mux,dst=\"$a.$ext\",access=file}" vlc://quit
done


Put the script in the folder with your wma files.  From the command line make the script executable:

#chmod +x wma2mp3.sh

then execute
#./wma2mp3.sh

I did not use the ‘arate’ variable and the mp3’s sounded fine, however my wma files were from an audiobook so quality is not quite so important.  Also this was not exactly fast but it works.   The script was still running when I retired for the night, it was running at least an hour at that point.  In all I converted 341 files averaging 4 Meg each.


The videolan wiki also gives batch script  examples for doing this in Windows.
The one thing I did not like was that this process just appended .mp3 after the wma extension which offended my sensibilities.  I will fix that  later.  In the meantime that can easily be addressed with the bulk file renamer included with my MINT linux distro.

3 comments: