how to use time out in mplayer?

1

I am trying to save audio using mplayer from a live http stream. saving audio is successful. If there is no live stream playing it does not exit automatically. Is there any way to set timeout if there is no live stream?

code : mplayer -i url -t 00:00:10 -acodec libmp3lame -ab 24 -ar 8000 audio.mp3

Thanks in advance.

manoj

Posted 2010-06-13T23:56:25.463

Reputation: 11

Answers

0

I've solved it by using Expect. You launch the streaming playing with ./play.sh:

while [ '1' == '1' ]; 
do
  expect try_stream.exp $1 
  sleep 3
done

And this uses try_stream.exp:

set timeout 4
spawn mplayer -nocache $argv
expect {
  "Starting playback" { 
    interact
  }
  timeout { 
    send \003;
    exit 1
  }
}

Basically, it tries to play the stream, and if it cannot do it within 3 seconds, it gives up (.exp script) and retries (.sh script). It works as long as you have problems like a very busy server. Unfortunately I don't know how to deal with the case when mplayer gets stuck once it started playing, there is no output string for Expect to detect in such a case.

zakmck

Posted 2010-06-13T23:56:25.463

Reputation: 33