Discussion:
[linux-audio-user] Recording internet radio using MPlayer
Kevin Sookocheff
2005-06-21 19:08:54 UTC
Permalink
Hi,

        I'm not sure if this is the right forum for this but hopefully some of
you have done this before.

I've managed to get everything working as it should when recording internet
from the command line using mplayer.  But I still have a problem recording
using cron to record at specific times.

I issue the following statement on command line :

mplayer http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg -ao pcm
-aofile /home/kbs464/tmp/mystream.wav -vc dummy -vo null;

With the following satisfactory results:

MPlayer 1.0pre6-3.4.3 (C) 2000-2004 MPlayer Team
CPU: Intel Pentium 4/Xeon/Celeron Northwood (Family: 8, Stepping: 3)
Detected cache-line size is 64 bytes
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection - WARNING - this is not optimal!
To get best performance, recompile MPlayer with
--disable-runtime-cpudetection.


77 audio & 188 video codecs
Linux RTC init error in ioctl (rtc_irqp_set 1024): Permission denied
Try adding "echo 1024 > /proc/sys/dev/rtc/max-user-freq" to your system
startup scripts.
Opening joystick device /dev/input/js0
Can't open joystick device /dev/input/js0 : No such file or directory
Can't init input joystick
Setting up LIRC support...
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support.
You will not be able to use your remote control.
Playing http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg.
Resolving oggtrial.nm.cbc.ca for AF_INET6...
Couldn't resolve name for AF_INET6: oggtrial.nm.cbc.ca
Resolving oggtrial.nm.cbc.ca for AF_INET...
Connecting to server oggtrial.nm.cbc.ca[159.33.6.141]:80 ...
Cache size set to 8192 KBytes
Connected to server: oggtrial.nm.cbc.ca
Cache fill: 19.92% (1671168 bytes)    Ogg file format detected.
==========================================================================
Trying to force audio codec driver family libmad...
Opening audio decoder: [libvorbis] Ogg/Vorbis audio decoder
AUDIO: 44100 Hz, 2 ch, 16 bit (0x10), ratio: 4000->176400 (32.0 kbit)
Selected audio codec: [vorbis] afm:libvorbis (OggVorbis Audio Decoder)
==========================================================================
Checking audio filter chain for 44100Hz/2ch/16bit -> 44100Hz/2ch/16bit...
AF_pre: af format: 2 bps, 2 ch, 44100 hz, little endian signed int
AF_pre: 44100Hz 2ch Signed 16-bit (Little-Endian)
[AO PCM] File: /home/kbs464/tmp/mystream.wav (WAVE)
PCM: Samplerate: 44100Hz Channels: Stereo Format Signed 16-bit (Little-Endian)
[AO PCM] Info: fastest dumping is achieved with -vc dummy -vo null
PCM: Info: to write WAVE files use -waveheader (default).
AO: [pcm] 44100Hz 2ch Signed 16-bit (Little-Endian) (2 bps)
Building audio filter chain for 44100Hz/2ch/16bit -> 44100Hz/2ch/16bit...
Video: no video
Starting playback...
Ogg : bad packet in stream 0
A:1049661.2 (91:34:21.2)  0.0% 0%      

and a file /home/kbs464/tmp/mystream.wav gets created.

However, if I run the exact same command as part of the cron scheduler I get
nothing.  No file gets created by mplayer.

My crontab looks like this:

55 11 * * 1-5 /home/kbs464/scripts/streamrecorder &> /dev/null
30 12 * * 1-5 killall -9 mplayer

And the streamrecorder script like so:

#!/bin/bash

mplayer http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg -ao pcm
-aofile /home/kbs464/tmp/mystream.wav -vc dummy -vo null;
oggenc /home/kbs464/tmp/mystream.wav -o /home/kbs464/BraveNewWaves_`date
+%b_%d_%y`.ogg;
rm -f /home/kbs464/tmp/mystream.wav;


If, in crontab, I change the redirect of the streamrecorder script to a text
file I get the following back:

(contents of error file)

MPlayer 1.0pre6-3.4.3 (C) 2000-2004 MPlayer Team
CPU: Intel Pentium 4/Xeon/Celeron Northwood (Family: 8, Stepping: 3)
Detected cache-line size is 64 bytes
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection - WARNING - this is not optimal!
To get best performance, recompile MPlayer with
--disable-runtime-cpudetection.


77 audio & 188 video codecs
Linux RTC init error in ioctl (rtc_irqp_set 1024): Permission denied
Try adding "echo 1024 > /proc/sys/dev/rtc/max-user-freq" to your system
startup scripts.
Can't init input joystick
Opening joystick device /dev/input/js0
Can't open joystick device /dev/input/js0 : No such file or directory
Setting up LIRC support...
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support.
You will not be able to use your remote control.
Playing http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg.
Resolving oggtrial.nm.cbc.ca for AF_INET6...
Couldn't resolve name for AF_INET6: oggtrial.nm.cbc.ca
Resolving oggtrial.nm.cbc.ca for AF_INET...
Connecting to server oggtrial.nm.cbc.ca[159.33.6.141]:80 ...
Cache size set to 8192 KBytes
Connected to server: oggtrial.nm.cbc.ca
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)

And so on... the cache fill never moves from 0 even though the exact command
that I ran on the command line is running via cron.

Anyone have any suggestions on how to get this working?

Thank you very much for your time,
Kevin
Christoph Eckert
2005-06-21 23:03:02 UTC
Permalink
Post by Kevin Sookocheff
Anyone have any suggestions on how to get this working?
wouldn't it make sense to

* run mplayer on top of JACK
* connect the outputs of mplayer to the alsa outputs
* connect the outputs of mplayer to a recording app like
qarecord


Best regards


ce
Tim Moss
2005-06-21 23:57:37 UTC
Permalink
Post by Kevin Sookocheff
Anyone have any suggestions on how to get this working?
Using an mp3 stream as an example:

mplayer -nocache -dumpaudio -dumpfile OUTFILE.mp3 http://url.of.stream/
Paul
2005-06-22 01:17:23 UTC
Permalink
Hi,
????????I'm not sure if this is the right forum for this but hopefully some of
you have done this before.
I've managed to get everything working as it should when recording internet
from the command line using mplayer. ?But I still have a problem recording
using cron to record at specific times.
Hi;

I think mplayer likes to have an interactive tty. You could
try using ogg123, eg:

ogg123 -d wav -f myfile.wav 'http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg'

or just snag the stream:

wget -O myfile.ogg http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg

Paul
***@pobox.com
Magnus Hjorth
2005-06-23 05:04:27 UTC
Permalink
Try using the -noconsolecontrols option...

Regards,
Magnus

On Tue, 21 Jun 2005 13:08:54 -0600
Post by Kevin Sookocheff
Hi,
        I'm not sure if this is the right forum for this but hopefully some of
you have done this before.
I've managed to get everything working as it should when recording internet
from the command line using mplayer.  But I still have a problem recording
using cron to record at specific times.
mplayer http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg -ao pcm
-aofile /home/kbs464/tmp/mystream.wav -vc dummy -vo null;
MPlayer 1.0pre6-3.4.3 (C) 2000-2004 MPlayer Team
CPU: Intel Pentium 4/Xeon/Celeron Northwood (Family: 8, Stepping: 3)
Detected cache-line size is 64 bytes
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection - WARNING - this is not optimal!
To get best performance, recompile MPlayer with
--disable-runtime-cpudetection.
77 audio & 188 video codecs
Linux RTC init error in ioctl (rtc_irqp_set 1024): Permission denied
Try adding "echo 1024 > /proc/sys/dev/rtc/max-user-freq" to your system
startup scripts.
Opening joystick device /dev/input/js0
Can't open joystick device /dev/input/js0 : No such file or directory
Can't init input joystick
Setting up LIRC support...
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support.
You will not be able to use your remote control.
Playing http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg.
Resolving oggtrial.nm.cbc.ca for AF_INET6...
Couldn't resolve name for AF_INET6: oggtrial.nm.cbc.ca
Resolving oggtrial.nm.cbc.ca for AF_INET...
Connecting to server oggtrial.nm.cbc.ca[159.33.6.141]:80 ...
Cache size set to 8192 KBytes
Connected to server: oggtrial.nm.cbc.ca
Cache fill: 19.92% (1671168 bytes)    Ogg file format detected.
==========================================================================
Trying to force audio codec driver family libmad...
Opening audio decoder: [libvorbis] Ogg/Vorbis audio decoder
AUDIO: 44100 Hz, 2 ch, 16 bit (0x10), ratio: 4000->176400 (32.0 kbit)
Selected audio codec: [vorbis] afm:libvorbis (OggVorbis Audio Decoder)
==========================================================================
Checking audio filter chain for 44100Hz/2ch/16bit -> 44100Hz/2ch/16bit...
AF_pre: af format: 2 bps, 2 ch, 44100 hz, little endian signed int
AF_pre: 44100Hz 2ch Signed 16-bit (Little-Endian)
[AO PCM] File: /home/kbs464/tmp/mystream.wav (WAVE)
PCM: Samplerate: 44100Hz Channels: Stereo Format Signed 16-bit (Little-Endian)
[AO PCM] Info: fastest dumping is achieved with -vc dummy -vo null
PCM: Info: to write WAVE files use -waveheader (default).
AO: [pcm] 44100Hz 2ch Signed 16-bit (Little-Endian) (2 bps)
Building audio filter chain for 44100Hz/2ch/16bit -> 44100Hz/2ch/16bit...
Video: no video
Starting playback...
Ogg : bad packet in stream 0
A:1049661.2 (91:34:21.2)  0.0% 0%      
and a file /home/kbs464/tmp/mystream.wav gets created.
However, if I run the exact same command as part of the cron scheduler I get
nothing.  No file gets created by mplayer.
55 11 * * 1-5 /home/kbs464/scripts/streamrecorder &> /dev/null
30 12 * * 1-5 killall -9 mplayer
#!/bin/bash
mplayer http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg -ao pcm
-aofile /home/kbs464/tmp/mystream.wav -vc dummy -vo null;
oggenc /home/kbs464/tmp/mystream.wav -o /home/kbs464/BraveNewWaves_`date
+%b_%d_%y`.ogg;
rm -f /home/kbs464/tmp/mystream.wav;
If, in crontab, I change the redirect of the streamrecorder script to a text
(contents of error file)
MPlayer 1.0pre6-3.4.3 (C) 2000-2004 MPlayer Team
CPU: Intel Pentium 4/Xeon/Celeron Northwood (Family: 8, Stepping: 3)
Detected cache-line size is 64 bytes
CPUflags:  MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection - WARNING - this is not optimal!
To get best performance, recompile MPlayer with
--disable-runtime-cpudetection.
77 audio & 188 video codecs
Linux RTC init error in ioctl (rtc_irqp_set 1024): Permission denied
Try adding "echo 1024 > /proc/sys/dev/rtc/max-user-freq" to your system
startup scripts.
Can't init input joystick
Opening joystick device /dev/input/js0
Can't open joystick device /dev/input/js0 : No such file or directory
Setting up LIRC support...
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support.
You will not be able to use your remote control.
Playing http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg.
Resolving oggtrial.nm.cbc.ca for AF_INET6...
Couldn't resolve name for AF_INET6: oggtrial.nm.cbc.ca
Resolving oggtrial.nm.cbc.ca for AF_INET...
Connecting to server oggtrial.nm.cbc.ca[159.33.6.141]:80 ...
Cache size set to 8192 KBytes
Connected to server: oggtrial.nm.cbc.ca
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
Cache fill:  0.00% (0 bytes)
And so on... the cache fill never moves from 0 even though the exact command
that I ran on the command line is running via cron.
Anyone have any suggestions on how to get this working?
Thank you very much for your time,
Kevin
Mario Lang
2005-06-22 08:41:28 UTC
Permalink
Post by Kevin Sookocheff
Hi,
I've managed to get everything working as it should when recording internet
from the command line using mplayer.  But I still have a problem recording
using cron to record at specific times.
mplayer http://oggtrial.nm.cbc.ca:80/cbcr2-toronto.ogg -ao pcm
-aofile /home/kbs464/tmp/mystream.wav -vc dummy -vo null;
Is there any reason why you dont use ogg123 directly?

ogg123 -q -d file -f somefile.wav URL
--
CYa,
Mario
Kevin Sookocheff
2005-06-22 15:13:18 UTC
Permalink
Thanks for all the help,

Paul hit the nail on the head. Mplayer likes an interactive shell. Changing
the redirection of output streams helped me fix the problem:

Here is my new crontab that works:
0 22 * * 1-5 /home/xxxxxx/scripts/radio2 >> /dev/null 2>&1
5 2 * * 1-5 killall -9 mplayer >> /dev/null 2>&1

Thanks for the help everyone,
Kevin
Tim Moss
2005-06-22 21:37:09 UTC
Permalink
Post by Kevin Sookocheff
Thanks for all the help,
Paul hit the nail on the head. Mplayer likes an interactive shell. Changing
0 22 * * 1-5 /home/xxxxxx/scripts/radio2 >> /dev/null 2>&1
5 2 * * 1-5 killall -9 mplayer >> /dev/null 2>&1
For what it's worth, here is the script I use to "record" audio streams

----- begin script -----

#!/bin/bash

stream="$1"
outfile=$2
length=$3

mplayer -nocache -dumpaudio -dumpfile /path/to/save/to/${outfile} ${stream} &

/bin/sleep ${length}
/bin/kill -2 $!

----- end script -----

This mplayer command dumps the stream as it actually is so there is no
re-encoding step and thus no diminishing of quality of something that
is, most likely, already not high quality.
The -nocache argument to mplayer isn't required and a cache might be
helpful if your connection to the stream isn't too great.

Assuming the script is called stream_rec_cron.sh, I run it from cron like
this to "record" a show every weekday from 11:00-12:00.

0 11 * * 1-5 /path/to/stream_rec_cron.sh http://url.of.stream/ FILENAME-$(date +\%y\%m\%d\%I\%M).mp3 3600 > /dev/null 2>&1

The .mp3 extension on the filename can be changed to whatever format
the stream actually is (ogg, wmv, etc) or just leave it off altogether.

The 3600 is the duration of the recording, in seconds. There is no
killall cron line necessary because the script itself handles killing
the mplayer process (and only that mplayer process) when the duration
specified as an argument is up. If like me, you may have several
mplayers running (but paused), doing a killall could prove to be rather
inconvenient.
Kevin Sookocheff
2005-06-23 03:46:44 UTC
Permalink
Post by Tim Moss
If like me, you may have several
mplayers running (but paused), doing a killall could prove to be rather
inconvenient.
Good point ... I'll have to change that in my setup.

Kevin

Loading...