devroom.io/drafts/2010-09-11-mass-convert-wma-to-mp3-using-ffmpeg-and-ruby.md
Ariejan de Vroom dbae98c4c0 Moar updates
2013-03-24 14:27:51 +01:00

1.4 KiB

title kind slug created_at tags
Mass convert WMA to MP3 using ffmpeg and ruby article mass-convert-wma-to-mp3-using-ffmpeg-and-ruby 2010-09-11
audio
mp3
wma
music
ffmpeg

Today I found myself in a situation where I have a few (200+) WMA audio files. Due to personal preference I want MP3, not WMA. So, let's convert that lot.

What I want to do is convert all those WMA files to constant bitrate 192kbps, stereo mp3 files. (In my case, the WMA files have the required quality to use this settings). ~ The first tool you need is ffmpeg. If you're on Mac, simple run brew install ffmpeg. The second tool is irb or _Interactive Ruby.

With ffmpeg setup and in your path, create a directory and stuff you WMA's there. Then open irb and run the following Ruby command:

:::ruby
ext = ".wma"
Dir.glob("*#{ext}").each {|f| m = f.gsub(ext, '.mp3'); `ffmpeg -i '#{f}' -ab 192k -ac 2 -ar 44100 '#{m}'` }

When done, you'll find the WMA files converted to MP3 (having the same filename, except for the extention).

Happy transcoding!

Note: If you need to add ID3 tags to your files, I can highly recommend MusicBrainz Picard. It can fingerprint your music and find the proper data online. It's free!

Update: Added a separte ext variable, this works great for converting FLAC to MP3 as well! Just use ext = '.flac'.