This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature

Building an Internet radio recorder with VLC Player

By Dmitri Popov on March 30, 2005 (9:00:00 AM)

Share    Print    Comments   

It's nice to be able to listen to a net radio station directly on your computer. But wouldn't it be great if you could record it on your hard disk? Better yet, what if you could schedule recordings, so you don't miss your favourite programmes? Using VLC Player and a simple batch file you can turn your computer into a radio recorder.

VLC Player is a core application of the VideoLAN project. This versatile software can handle a wealth of video and audio formats and stream content over a local network. Moreover, VLC Player is able to play net streams and record them to the hard disk, which makes it a perfect tool for our project.

Listening to a net radio (or any net stream for that matter) using VLC Player is not that difficult. However, to be able to record it using VLC Player, you have to make sure that you have a direct link to the stream. Normally the links on radio stations' Web sites refer to .pls playlist files, which contain the stream information. Like any other player, VLC Player can use the playlist files to play the stream, but not to record it. To solve this problem you have to extract a direct link to the stream from the .pls file.

Let's say you want to record the Virgin Radio Classic Rock stream. Point your browser to the page containing the streaming links. If you use the Firefox browser, right-click on the desired link (an MP3 modem or broadband is always the safest bet), and select Save Link As to save the playlist file.

Open the saved file in a text editor and locate the line containing the direct link to the stream. In this case it is:

File2=http://vruk.sc.llnwd.net:12265

Check that the link works properly, then copy it into the Clipboard. Launch VLC Player and choose File > Open Network Stream. Select the HTTP/FTP/MMS option, and enter the link into the URL field. To avoid hiccups during playback, you might want to enable caching. To do this, tick the Caching check box and type a value in milliseconds into the Caching field (5,000 works fine in most cases). Finally, click OK. If the link works, VLC Player will play the stream.

The next step is to configure VLC player to record the current stream. Once again, choose File > Open Network Stream, select the HTTP/FTP/MMS option, and enter the link into the URL field. This time, though, tick the Stream output check box, and press the Setting button. This will open the Stream Output dialogue window. If you want to listen to the stream while it's being recorded, tick the Play locally check box.

Use the Browser button next to the Filename field to give the recorded stream file a name and choose where it will be stored. For Encapsulation Method, select Raw. In the Transcoding options section, tick the Audio codec check box and select MP3 from the list. Select a bitrate from the Bitrate list (128 is a good compromise between audio quality and file size). Since you are going to record a stereo stream, select 2 from the Channels list. Finally, press OK to save the settings and close the window.

Press OK to start recording. To make sure that everything works properly, close VLC Player and try to play the recorded file on your favourite MP3 player.

Although VLC Player can now play and record the net stream, there are still a couple of things you can do to improve the way it works. First of all, if you quit VLC Player, you'll lose all your settings. Luckily, you can launch VLC Player using a command with different parameters. This means that you can create a batch file (or a script on Linux) that you can use to launch VLC Player with predefined settings.

Create a new text file and enter the following string, if you're running Windows:

"C:\Program Files\VideoLAN\VLC\vlc.exe" --http-caching 5000 http://vruk.sc.llnwd.net:12265 :sout=#transcode{acodec=mp3,ab=128,channels=2}:duplicate{dst=display,dst=std{access=file,mux=raw,url="C:\VLCOutput.mp3"}}

In this string, "C:\Program Files\VideoLAN\VLC\vlc.exe" points to the VLC Player's executable. Linux users can replace this part with the appropriate file location.

--http-caching 5000 enables caching and sets it to 5,000 milliseconds.

http://vruk.sc.llnwd.net:12265 points VLC Player to the net stream.

The part of the command that starts with :sout contains recording settings. Typing this sting manually can be somewhat laborious. Luckily, you can simply copy the string from the Destination Target field in the Stream Output dialogue window and paste it in the text file. Finally, save the file as a shell script, or with the .bat extension on Windows.

The last part of the project is to create a schedule that will execute the batch file at a predefined time. You can use cron on Linux or the Scheduled Tasks tool on Windows to do this. On Windows, go to Accessories > System Tools > Scheduled Tasks and double-click on Add Scheduled Task. This will launch the Schedule Task wizard that will guide you through the process of creating a task. When the wizard prompts you to choose a program file, press the Browse button and point to the batch file. Configure the rest of the settings, and save the task. That's it! Your radio recorder is ready for use.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, US, German, and Danish computer magazines.

Share    Print    Comments   

Comments

on Building an Internet radio recorder with VLC Player

Note: Comments are owned by the poster. We are not responsible for their content.

Interesting

Posted by: Synonymous on March 31, 2005 03:08 AM
This is a very interesting article<nobr> <wbr></nobr>:)). I am going to try it out because i use VLC all the time.

#

Why? How complicated do you want to be?

Posted by: Anonymous Coward on March 31, 2005 06:02 PM
On Linux, recording a stream for which you have determined the URL can be as simple as wget your.url.com:port<nobr> <wbr></nobr>... Or if you want it really easy, just install Streamripper <a href="http://streamripper.sourceforge.net/" title="sourceforge.net">http://streamripper.sourceforge.net/</a sourceforge.net> and Streamtuner <a href="http://www.nongnu.org/streamtuner/" title="nongnu.org">http://www.nongnu.org/streamtuner/</a nongnu.org> - they work together with a record button on the Streamtuner GUI

You could easily insert either streamripper or wget into a cron script, and with streamripper you have the added advantage that individual tracks will be tagged, and saved in a nicely labelled directory in $HOME.

VLC is a nice app, but whatever happened to the KISS principle and not reinventing the wheel?

#

Re:Why? How complicated do you want to be?

Posted by: lx'd powered on April 08, 2005 12:05 PM
I found this usefull. Although, you didn't mention how to tell vlc when to stop recording! (ok, so it's a no brainer but I'm sure there's other idiots like me out there)

I made 2 files to solve the problem, a batch file to start recording which saves a file in the format "record_MMDDYYYY_HR_MN_SS.SS.mp3":

FOR<nobr> <wbr></nobr>/f "tokens=2 delims= " %%D in ('echo %DATE:/=%') do SET DATEN=%%D
FOR %%T in (echo %TIME::=_%) do SET TIMEN=%%T
"C:\...\vlc.exe" --http-caching 5000 <a href="mms://aninternetaddresshere/" title="aninternetaddresshere">mms://aninternetaddresshere/</a aninternetaddresshere><nobr> <wbr></nobr>:sout=#transcode{acodec=mp3,ab=64,channels=2}:dup<nobr>l<wbr></nobr> icate{dst=std{access=file,mux=raw,url="C:\..\reco<nobr>r<wbr></nobr> d_%DATEN%_%TIMEN%.mp3"}}


Then, I made a vbs file to kill the application:

set wmi = getobject("winmgmts:")
wql = "select * from Win32_Process " & " where name='vlc.exe'"
set results = wmi.execquery(wql)
for each app in results
app.terminate
next


So now I can record overseas shows overnight and listen to them the next morning. It's pretty cool.

#

Thanks!

Posted by: Anonymous [ip: 70.104.230.226] on August 23, 2007 12:46 PM
Good article - I've been trying to learn the nuances of VLC command line and this is a great example!

#

Awesome!

Posted by: Anonymous [ip: 142.59.15.170] on September 26, 2007 05:15 PM
U Da Man!!!!

#

WoW

Posted by: Anonymous [ip: 125.237.198.165] on December 07, 2007 04:37 AM
Thanx heaps for the windows info, definitely prefer the streamripper option for linux tho' (just because of "each song separated" and id tagged) but this was the page to find that too, so

#

Building an Internet radio recorder with VLC Player

Posted by: Anonymous [ip: 68.117.117.196] on January 10, 2008 09:03 AM
I am having an error playing files recorded with vlc in any other media player, Audacity, WMP Itunes, realPlayer exc.. some say file may be corrupted won't play others say something about duration. when I look at my playable mp3 files properties they have a duration property listed that says how long the song is. The files recorded with vlc do not. Also the files are not givin the mp3 extension when I press stop from vlc. Am I not closing right. I also was using other encapsultion methods than raw. not sure if I tried raw. Will do now. I do know I am using the right codec

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya