Cartometric Blog

A scrapbook of GIS tricks, with emphasis on FOSS4G.

Archive for March 7th, 2015

Q: What’s The best way to convert CDs to MP3s in Windows? A: VLC and the Command Line. Here I’ll show ya..

with 33 comments

Today my friend (shout out to Nic Zamora) wanted to know if I still had a recording we made of a song he co-wrote way back in ancient history 2007 or something. Gah..

Well it got me to thinking—my other buddy (shout out to Corey Nolan) had a similar request awhile back for a recording we did with his brother, Dustin, around the same time. The problem was, the only recording I had of the latter was on CD. Since then, that one simple deterrent—being on CD—was solely responsible for preventing me from ever “getting around to it”, like I said I would.

The reason I hate ripping CDs is because it’s such a ridiculous process ..first you have to open some asinine software (and God help you if it’s Windows Media Player), click around like a fool, be confused, drag files and/or locate folders, agonize over a variety of settings, many of which you, A) may not know anything about, 2) remember from the last time you did this resulting in inconsistently ripped music, and D) ..worst of all, potentially but unintentionally introduce some weak-sauce copy protection.

There had to be a better way.

Caveat—since writing this post, I’ve discovered that CDs containing extra material, like music videos, etc., unfortunately don’t play well with this program. I may return and solve that problem in the future, but with only one CD affected so far, it’s not a high priority.

As a GIS software developer, I use ALOT of open source tools, especially when I need to bend data out of one format and into another—usually from flat files like shapefile into some database instance, like PostgreSQL or MySQL. The best tool for this, of course, is the ogr2ogr command line utility in the GDAL/OGR suite. It’s the best for many reasons. But in this context, it’s the best because everything you want to do is done over the command line. No clicking, no dragging. No BS. Just type the “instruction” you want to execute into a command line window, run it, and you’re done. Simple.

So this morning I had enough and finally asked the obvious question—why can’t I convert music over the command line as easily as I can bend and twist GIS data formats??

It turns out, I can! Using the VLC Media Player, which provides a command line interface..

First, the Google took me to where someone already asked a similar question on Stack Overflow. And after toying around with a batch file provided by a helpful SO user, I tweaked it a little so that I could reuse the file more easily—specifically by passing in the path to any folder where I wanted new mp3 tracks to be saved into.

And its wicked simple. In the time I’ve spent so far writing this post, I’ve already used this solution to rip seven different CDs—Chopper One, ACDC live, Social Distortion, DGC Rarities, Robert Bradley’s Blackwater Surprise, Nerf Herder, and ..yep, the song my friend asked for. 🙂

Oh, and I’ll probably have 8 or 10 CD’s ripped by the time I publish. I love open source software.. LOVE it.

Now that I’m editing the post a little while later—make that 14 albums exported ..going on 15. 8)

So without additional storytelling, here’s what you have to do to rip your CDs to MP3 like a GIS jedi..

1. Install VLC.

When VLC installs, make a note of the directory VLC installs to. It should be something like

C:\Program Files\VideoLAN\.. or maybe


You’ll need this later in Step 5.


2. Create some directory near your drive root that DOES NOT HAVE SPACES in it. Like C:\MP3s

*Note: From here on, let’s assume you won’t put any spaces in any file paths.*


3. Open Notepad. Start > Run > type “notepad” without quotes > ::hit Enter::


4. Copy and paste the code between these lines into your notepad window..




set out_path=%1

:: Set the path to the VLC installation on your system.
:: Make sure you see the file "vlc.exe"
set vlc_path=C:\Program Files\VideoLAN\VLC\vlc

:: Add a trailing backslash if necessary..
if defined out_path if not "%out_path:~-1%"=="\" set out_path=%out_path%\

:: Create the output directory, if necessary..
if not exist %out_path% (
echo Creating output directory..
mkdir %out_path%
) else (
echo Output directory already exists, reusing it..

echo Exporting to "%out_path%" ..

SET /a x=0

:: E: represents your CD player's letter drive. You may need to change this to D:
FOR /R E:\ %%G IN (*.cda) DO (CALL :SUB_VLC "%%G")
GOTO :eof

call SET /a x=x+1
ECHO Transcoding %1
SET out_track=%out_path%Track!x!.mp3
ECHO Output to "%out_track%"
ECHO exporting .. ..

:: Here's where the actual transcoding/conversion happens. The next line
:: fires off a command to VLC.exe with the relevant arguments:
:: E: represents your CD player's letter drive. You may need to change this to D:
CALL "%vlc_path%" -I http cdda:///E:/ --cdda-track=!x! :sout=#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=44100}:std{access="file",mux=raw,dst="%out_track%"} vlc://quit



5. Depending on your version of Windows, you may need to edit the path to your VLC installation.

Look for “IMPORTANT!!!!” in the code you just pasted. This is where you set the path to VLC.

Back in Step 1 I asked you to make note of the VLC installation path. My home system runs Windows XP 32 bit (yes, still), which means VLC installed to..

C:\Program Files\VideoLAN\VLC\vlc

—see where that path is declared in the file? YOU, however, are probably running Windows 7 ..or maybe 8, and if that’s the case, I think you need to change the VLC path to..


..which you should confirm before you continue. Try opening or browsing into that directory and make sure you see the file, vlc.exe. If you see that file, you’re good to advance.


6. Similarly, you may need to edit the code to use the correct letter drive for your CD player. On my system, it’s the E: drive, but on your system, it’s probably the D: drive.. So if changing this value is necessary, find the two remaining “IMPORTANT!!!!” comments in the code and change E: to the letter drive for your CD player.


7. Save the file as a so-called Batch file (.bat).

In Notepad, select File > Save as..

Make sure you change “Save as type” to “All Files”. Then browse into the C:\MP3s folder you created in Step 2 and save the file as “_rip-cd.bat”, which starts with an underscore, “_”.

Frankly, you can name the file whatever you want, but the underscore should cause the file to always appear above or below anything else in this folder, which I find helpful.

Make sure that the file REALLY ends in the .bat extension, and not .txt. If this is correct, your file icon should look like a little gear, like in the image above. If you’re having trouble with this, look here for some help.


8. Now it’s time to put your hard work to use, so pop in a CD and open a fresh command window (a.k.a. the terminal).

Start > Run > type “cmd” without quotes > ::hit Enter::

In the terminal, type the full path to your batch file. If you stuck to the example, that would be..


..follow it with a space, and then a path on your system to where you want to save the exported MP3s. So your full command might look like below. (FYI: “TREoS” is a band, and “Between the Heart and the Synapse” is an album.)

C:\MP3s\_rip-cd.bat C:\MP3s\TREoS\BetweenTheHeartAndTheSynapse

You do NOT have to create the export folder first, the script will create it for you automatically. other words, if you have multiple albums by the same artist, you’ll want to save them in different folders. This is important, because the program can’t name the songs for you, so they’ll be created with names like Track1.mp3, Track2.mp3, etc., and if you try to export another album into the same directory, it will probably fail and complain when it tries to save another Track1.mp3 into a folder already containing a Track1.mp3. Hopefully this makes sense.

Here’s what it looks like when you fire it up and run it. Just so you know what you’re seeing, the part I actually typed was

D:\x_Rip\_rip-cd.bat D:\x_Rip\STP\Purple

(yeah ..I’m using different drive letters and a different folder path, but hopefully you get the gist.)

That’s all there is to it. Using this approach, it’s ultra-painless to export a CD to MP3s. As a bonus, you’ll export the same way every time, never having to worry about required or optional configurations, or some pesky copyright protection that some software try to impose.



Written by elrobis

March 7th, 2015 at 5:37 pm

Posted in Uncategorized