Showing posts with label lame. Show all posts
Showing posts with label lame. Show all posts

Sunday, December 14, 2008

Saving streaming wmv files with Linux

This past week my sister-in-law was on the radio in NYC and my father-in-law wanted me to try and record it for him. Since I live in North Carolina, obviously the only way to do that would be to stream it over the web. I figured finding and listening to the stream would be the easy part. I listen to streaming radio ALL the time (thanks WUNC!).

Before getting into all of this, you are likely going to need to install some applications. Everything I used was available through the Ubuntu repositories though I do have Medibuntu enabled in addition to all the other easily enable able ones (main, universe, restricted and multiverse). This was also all done using 8.10 Intrepid Ibex. I also know I have several of the restricted packages installed which I am pretty sure is the only reason Windows Media files work. Now for the details.

The hard part would be to actually save the stream. Here is a step by step of what I did:

  • Obviously the first step was to find a stream of the station. She was playing on WQXR - 96.3 FM and I found their Windows Media stream on PenguinRadio.
  • I found that VideoLAN - VLC media player would be my best bet. It also works in Windows too. I didn't try this on Windows but I bet it would work the same with VLC.
  • I had the hardest time trying the many command line options for vlc. I really wanted to download the file and transcode it to wav or directly to MP3 but I just couldn't get that to work. Instead I just saved it directly as WMV and decided to worry about the rest later. I had some trouble with all the many GUI options too so I went with the safer command line route. I used the command line:
    vlc -vvv "http://htc-01.media.globix.net/COMP005996MOD1/meta/wqxr_live_high.asx" --sout '#duplicate{dst=display,dst=std{access=file,mux=asf,dst=/home/forrest/download.wmv}}'
  • Here is the easy to replace version: vlc -vvv "MY_STREAM" --sout '#duplicate{dst=display,dst=std{access=file,mux=asf,dst=MY_DOWNLOAD_FILE}}'

After all that I had a 34.1MB wmv file with just under 27 minutes recorded. At this point I converted it to a wav using mplayer like so: mplayer download.wmv -ao pcm:file=download.wav

Since I wanted to play it safe and be sure not too miss anything I needed recording, I started to recording early and kept it going past time. At first I wanted to use Audacity to trim the file but I had a problem getting that to work so I used a program called sox. To truncate the wav with sox you just specify the trim option, the start time and how long to run (NOT the end time). In my case it was: sox download.wav download-trim.wav trim 14:50 9:39

Next I converted the wav to MP3 so I could make it easy to get to online before burning it to a CD. I was sick of command line options at this point so I used SoundConverter instead of Lame (though it likely uses lame as a back end anyway) to save me the trouble.

Thursday, April 3, 2008

Convert shn (Shorten) to MP3 or FLAC in Linux

Many months ago I downloaded some Jump Little Children live shows from the Internet Archive Live Music Archive. The files, of course, were in a lossless format but it was the older Shorten (*.shn) format instead of the newer and open FLAC. Shorten has limited support in Linux (and Windows too) so instead of trying to play them as shn I decided to convert them to mp3.

Tappers: I know you hate when your lossless recordings are converted to mp3. Heck, the notes that come with the files explicitly say "DO NOT ENCODE INTO MP3!" I am going to do it anyway. I would go with FLAC since it is also lossless, creates smaller files than Shorten and is better supported but I still have problems with FLAC. First, it is still much larger than an mp3 and my hearing and/or audio systems are not good enough for it to matter to me. Second, FLAC does not play on my iPod so I would have to convert it to something else to listen to it there. I promise though that I will not distribute these crappy mp3 copies of your recording and I plan to keep a copy of the shn files around (or maybe a FLAC copy as an archive). Thanks and keep up the good work!

I first installed the shntool package using Synaptic. This page showed me the command line arguments. But that didn't work as planned.

$ shntool conv -o wav *.shn
shntool [conv]: warning: failed to read data from input file using format: [shn]
shntool [conv]: + you may not have permission to read file: [jlc2003-02-14d1t01.shn]
shntool [conv]: + arguments may be incorrect for decoder: [shorten]
shntool [conv]: + verify that the decoder is installed and in your PATH
shntool [conv]: + this file may be unsupported, truncated or corrupt
I needed to download the Shorten codec too (shorten-3.6.1.tar.gz)... but would not compile because the C compiler cannot create executables. Fixing that was a simple:
$ sudo apt-get install libc6-dev g++ gcc
Then I was back to compiling and installing with:
$ ./configure
$ make
$ make check
$ sudo make install
And now I can convert the Shorten files to wav files (or FLAC but that takes more processing and I want to go to mp3 eventually so instead of going Shorten -> FLAC -> WAV -> mp3 I decided to just go Shorten -> WAV -> mp3. I did convert a few to FLAC which worked well. (To do FLAC, use shntool conv -o flac *.shn, wav is the default as you see below.)
$ shntool conv *.shn
Converting [jlc2003-02-14d1t01.shn] (0:35.65) --> [jlc2003-02-14d1t01.wav] : 100% OK
Converting [jlc2003-02-14d1t02.shn] (5:18.22) --> [jlc2003-02-14d1t02.wav] : 100% OK
...
To then convert your wav files to mp3 I would suggest lame (LAME Ain't an Mp3 Encoder). What else is there anyway?
$ sudo apt-get install lame
lame does not support batch processing thought like shntool did so I found a good FLAC to mp3 post that helped me write this little gem:
$ for file in *.wav; do $(lame -V2 "$file" "${file%.wav}.mp3"); done
using the -V2 option will encode the mp3s with variable bit rate at a fairly high quality (4 is default with a range of 0 to 10 and 0 being the best quality)

Now instead of the about 1.2GB of shn files, I have 272MB of mp3s to listen to most anywhere.

One final resource I found helpful was the shn in Ubuntu thread. Enjoy your music.