[MPlayer-users] controlling dumpstream durations...

Darrell Berry darrell at ku24.com
Thu Jan 6 15:44:35 CET 2005


I'm trying, in perl, to write a little program which, given:

-playlist URL

will, using mplayer, dump <duration> seconds of the stream to the named
file. i've read prior discussion on this list where the idea of adding a
timer flag to dumpstream was pretty much discounted, so i've been looking
at doing this in slave mode with a pty (fwiw using a fifo and -input file
works, but i want to be able to run multiple calls of this concurrently,
and don't want to have to have a fifo for each instance).

i'm trying the code below to test a way of doing it -- if i can get this
working, wrapping it up and putting error checking and args is easy. but i
have a problem: the slave process starts up, but doesn't quit when
requested to -- in fact it keeps going until the parent process dies, at
which time i get:

MPlayer interrupted by signal 1 in module: dumpstream
- MPlayer crashed. This shouldn't happen.
  It can be a bug in the MPlayer code _or_ in your drivers _or_ in your
  gcc version. If you think it's MPlayer's fault, please read
  DOCS/HTML/en/bugreports.html and follow the instructions there. We can't
  won't help unless you provide this information when reporting a possible

...obviously i'm missing something about how to use slave mode with ptys
-- can anyone shed any light on this? i can't be the only person wanting
to do this!


- darrell

use IO::Pty;

# forks and returns a pty connected to mplayer
sub start_mplayer {
     my(@mplayer_args) = @_;

     $mplayer_pty = IO::Pty->new() or die("pty: $!");
     $mplayer_pid = fork();
     if( $mplayer_pid != 0 ) {
         return($mplayer_pty, $mplayer_pid);

     # the child
     open(STDIN, "<&" . $mplayer_pty->slave()->fileno());
     #open(STDOUT, ">&" . $mplayer_pty->slave()->fileno());
     open(STDOUT, ">/dev/null");

     exec('mplayer', @mplayer_args);

$duration = 20;
$playlist = "http://www.sleepbot.com/ambience/cgi/listen.cgi/listen.pls";
@args = ("-slave", "-playlist", $playlist, "-dumpstream");

($pty, $pid) = start_mplayer(@args);

print "mplayer PID is $pid\n";
sleep 10;
print "requesting quit\n";
print $pty "quit";
sleep 10;

More information about the MPlayer-users mailing list