Cartometric Blog

A scrapbook of GIS tricks, with emphasis on FOSS4G.

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 13 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 ..like 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

C:\Programs\VideoLAN\..

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..

 


@ECHO OFF

setlocal ENABLEDELAYEDEXPANSION

set out_path=%1

:: IMPORTANT!!!!
:: 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

:: IMPORTANT!!!!
:: 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

:SUB_VLC
call SET /a x=x+1
ECHO.
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:
:: IMPORTANT!!!!
:: 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

:eof

 

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..

C:\Programs\VideoLAN\VLC\vlc

..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..

C:\MP3s\_rip-cd.bat

..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.

..in 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.

Cheers!

elrobis

Written by elrobis

March 7th, 2015 at 5:37 pm

Posted in Uncategorized

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

Subscribe to comments with RSS or TrackBack to 'Q: What’s The best way to convert CDs to MP3s in Windows? A: VLC and the Command Line. Here I’ll show ya..'.

  1. Hey, great tutorial, but when I follow the steps, I obtain empty mp3 files (0 bytes), but the correct number of tracks. Any idea why?

    Nassim

    30 Dec 15 at 7:43 pm

  2. Whoa! Cewl! Very 80′s DOS BAT file programming. Works like a charm. Now I can listen to my best of New Order and Simple Minds CDs in the RAV4. Thanks do much, I really have forgotten a lot of old coding skills. Ahh! old age, ain’t it great and Google to help.

    OldFart

    2 Feb 16 at 9:01 pm

  3. Hello,
    Thanks for this, it’s been a long time since DOS has come out of my keyboard! But I get the same results as Nassim: correct number of mp3 files (tracks) but they’re empty (0 bytes). Seems OldFart got this to work … hmmm. Any suggestions?

    Diddikai

    8 Feb 16 at 6:29 pm

  4. Same here. Bunch of 0 length files. Using windows 10 and VLC 2.2.2.

    Dork

    9 Jun 16 at 10:19 pm

  5. Hi Nassim–sorry for the ultra-slow reply here. Any chance you were using spaces when you passed the “artist name” variable into the script?? If so, I could imagine spaces might break things at some level.. If you did, try again without using any spaces; for example C:\MP3s\_rip-cd.bat C:\MP3s\ArtistNameWithoutSpaces

    elrobis

    17 Jun 16 at 12:45 pm

  6. Hi Diddikai–sorry for the ultra-slow reply here. Any chance you were using spaces when you passed the “artist name” variable into the script?? If so, I could imagine spaces might break things at some level.. If you did, try again without using any spaces; for example C:\MP3s\_rip-cd.bat C:\MP3s\ArtistNameWithoutSpaces

    elrobis

    17 Jun 16 at 12:46 pm

  7. Hi Dork :) )) Any chance you were using spaces when you passed the “artist name” variable into the script?? For example C:\MP3s\_rip-cd.bat C:\MP3s\Artist Name With Spaces If so, I could imagine spaces might break things at some level.. If you did, try again without using any spaces for the artist name; for example C:\MP3s\_rip-cd.bat C:\MP3s\ArtistNameWithoutSpaces ..if this solves the problem, please let me know and I’ll update the post! Best, Elijah

    elrobis

    17 Jun 16 at 12:47 pm

  8. Win 10 user here – got it working after some tinkering.
    Uninstalled & reinstalled VLC using a separate root folder with no spaces in case that was a problem.
    Threw an error as follows:
    exporting .. ..
    ‘”C:\VLC”‘ is not recognized as an internal or external command,
    operable program or batch file.
    ———————————-
    Changed the 5th line of the copied script to:
    set vlc_path=C:\VLC\vlc.exe

    after that, success!
    C:\Users\Sage>c:\MP3\_rip-cd.bat c:\MP3\voggies
    Output directory already exists, reusing it..
    Exporting to “c:\MP3\voggies\” ..
    ——————————-
    Hope this will give others courage to keep trying!

    Sage Wizard

    3 Aug 16 at 12:02 pm

  9. @SageWizard, I’m glad you got it working, and thanks for the helpful feedback! /Elijah

    elrobis

    3 Aug 16 at 12:58 pm

  10. Great. It works! Thank you.

    Zsolt Edelényi

    28 Aug 16 at 12:48 pm

  11. The such as you master my thoughts! You appear to comprehension lots roughly the following, as if you published the ebook inside something like that new latest music releases. I do think that you just can do by Per cent to help force the content house a bit more, on the other hand in lieu of this, this really is superb web site. A fantastic read. I most certainly will certainly come back.

    Www.Facebook.Com

    12 Jan 17 at 8:44 pm

  12. If some one needs expert view concerning running a blog after that
    i recommend him/her to pay a visit this website, Keep up
    the good job.

    canyon bus tour

    2 Mar 17 at 7:43 pm

  13. Hi! Good script! Next step: grab the meta info mp3 and write with the destination files. Bye

    beppe

    4 Jun 17 at 9:03 am

Leave a Reply