Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

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

And this uses try_stream.exp:

set timeout 4
spawn mplayer -nocache $argv
expect {
  "Starting playback" { 
  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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.