Bulk Convert WMA to MP3

Don’t care about the what or why?  Skip to the how below.

Many years ago, I decided that lossless WMA was going to be the wave of the future.  My Creative Labs Zen played them beautifully when the world still hadn’t accepted FLAC.

It was a weird time for music.  Ipods weren’t a thing yet and the world didn’t know what to do with digital music.  Solid storage was impractically expensive and almost no MP3 players had it.  If they did, 64 megabytes of flash storage was equivalent to a 500 megabytes of magnetic disk storage.

Basically the answer was to go backward from everything we worked toward to have our home audio closely match the real thing and use absolute crap quality, highly compressed audio files so we could carry them to the gym.  Disgusting.

I did my research way back then and I believe my argument for the lossless WMA was both that WMP ripped them quicker than lossless MP3s and, more interestingly, supposedly it was less disk access to read them.  Think about it this way – highly compressed media needs to be decompressed.  This uses processing power and battery.  Less compression (or zero compression) only needs to be read from the disk, quickly interpreted, and then turned into audio.

Back in 2003-ish, I was convinced of this and ripped tons of my personal CDs into WMAs.  Eventually the Zune popped up and though it will be forever mocked, was a solid MP3 player.  It handled WMAs just fine so I still felt comfortable with my decision made a decade prior.

Later on, post Zune, I had a Windows Phone which, again, played WMAs without any issue.  Eventually I moved away from that (forcefully) and am now on an Android.  Androids can play WMA files just fine and Microsoft’s Groove player did a fine job of that.  Still, fifteen years later, I felt like it was a fine decision.  More so now that my files were stored online and bandwidth isn’t even a consideration any longer.

Recently Microsoft announced a plan to sunset (kill) the Groove player on all platforms except Microsoft platforms.  Unfortunately this left me in a rut as the final kill will happen in a few months and I’d still like to listen to these.

Plex has a cloud service that, well, sucks.  It’s supposed to read the files from your OneDrive account and give you a serverless playback option.  It works great with MP3 files but struggles greatly with WMAs regardless of platform.  I looked for many other options and everything seems to struggle.  I don’t know if it’s an on-fly conversion or some caching issue but WMAs are a thing of the past and I’m accepting that my twenty-year-ago decision was the wrong one.

But to be fair, nobody knew what would happen.

Being in OneDrive, it’s easy to sync up my library.  I recently went through the process of converting all of the WMA files into 192kb MP3 files.  File sizes shrank drastically as did quality.  I wasn’t looking to save space, I was looking to stream my music reliably and file size is important.

HOW

If you’re like me and you keep your music up on OneDrive and want to play it anywhere at any time, give this a try.  What I’m using:

  • Windows 10
  • OneDrive (built in)
  • Plex Cloud
  • PowerShell (built in)
  • ffmpeg

First off, you’ll need to download all of the WMAs.  My collection has a combination of many file types collected over eighteen years but we’ll convert these.

Mine are all gone so here’s a dummy.  Select all (ctrl + a) and right click, choose “Always keep on this device”.  This will start the OneDrive mega sync.  All of the WMA files, regardless of folder within your “music” folder, will begin to download.  This was about 60GB for me.

Then you wait.  Go download ffmpeg while you wait and extract it somewhere.  It doesn’t need to be installed.

Find the directory of the “ffmpeg.exe” file.  This is the tool that we’ll use to do the conversions.

Next we’re going to open up PowerShell.  I’ve written the script here.  It’s sloppy but it works and we’re not going for anything permanent.  Here’s the script.

$m = "C:\users\jason\OneDrive\Music\*"
#$m = "\\?\C:\users\jason\OneDrive\Music\*"

$batchtoconvert = gci -Path $m -Filter *.wma -Recurse

foreach ($filename in $batchtoconvert)
{
	write-host $filename.FullName
	$st = get-date
	$input = $filename.FullName
	$output = $filename.FullName -replace ".wma", ".mp3"
	& "C:\PATHTOFFMPEG\bin\ffmpeg.exe" -i $input -ab 192k -map_metadata 0 -id3v2_version 3 $output -y -loglevel panic
	$et = get-date
	$ts = [DateTime]$et - [DateTime]$st
	write-host $ts.seconds " seconds"
	Remove-Item $filename.FullName -Force
}

What’s it do?  We’ll go through it.

To get PowerShell open on a Windows computer, push WindowKey + R, type “powershell ise”, and push enter.  Copy/paste that script into the TOP window.

The first line is the main path of your music folder.  Under this, in any subfolder, you’ll have your WMA files.

The second line is to be used if paths get REALLY LONG.  It might be best to use this instead.  The pound symbol is a comment.

The next chunk says “give me a list of WMA files in all of these directories and sub directories”.

Then we get to the loop.  The next thing you need to change is that c:\PATHOFFFMPEG\.  Make sure to put the path of the ffmpeg.exe file you downloaded from the website earlier.

What this will do is take each one, name by name, and convert it a 192kb MP3 file, preserving the metadata and embedded album art on the way.  Cool!  It will also remove the WMA file (if it can – more on that below) so that the MP3 can effectively take its place.

To run it, highlight the whole text and push F8.

I recommend testing a few at a time.  You explicitly specify a directory to convert or even a whole letter.  I did my collection letter by letter with “…\A*” to get all the A’s.  This was not necessary but I worry about things and my computer is pushing seven years old so I wanted to keep an eye on it.

I actually ran two instances of PowerShell and ran a letter of the alphabet in each one.  T and S took the longest and it let more cores do more work.

A few caveats that could be fixed if you wanted to spend the time fixing them:

Paths that are too long will break it.  If it simply doesn’t work from the start, try a shorter or more explicit directory and see if that works.  You might have some long stuff.  You can also try using the “\\?\” syntax in front of the path to hint at the long paths.  If you have bad habits about giving paths crazy deep or long names, this can be a problem.  Play around with it.

Second, if a file or folder has [square brackets] anywhere, it will break the delete part of the script because I never bothered to escape them.  What I recommend is either write that in yourself (haha) or after you’re all converted, do another search for all the remaining WMA files.  You might notice that they all have a square bracket somewhere.  You can bulk delete them this way.  This won’t prevent them from being converted, just deleted.

Third and what should have been at the very top of this post: do this at your own risk.  You’re deleting your old WMAs, replacing them with MP3s, and eating a ton of bandwidth on the way.

  • OneDrive will go into frantic scan and upload mode during this process if you do it in the live sync’d directory.  Let it.
  • You will break your old playlists because they likely depended on the other filenames.
  • OneDrive will keep everything deleted for at least a month in the online recycle bin.  If everything gets really screwed up, you can bring back your old stuff.
  • KEEP YOUR MEDIA PLAYER CLOSED!  If it’s trying to scan this stuff while you do this, you’re going to make it vomit.
  • Be patient.

If this all works out for you, Plex offers a cloud player that will supposedly grab your files from OneDrive and play them anywhere you can install the app.  It works on Windows, Android handhelds and TVs, and the website.  It’s a great app but their handling of the streaming is sub-par.  I don’t recommend Plex right now but when the next thing comes around, the MP3 files will most likely be where the world wants you to be.  This time, I’ll be ready.

I’m considering a hosted personal server.  If I go that route, I’ll share all Linux commands and the scripting along the way.

Expect a follow up post in 2034 with the “I was wrong again – here’s how to really do it” explanation.

Have fun.

Leave a Reply