[MPlayer-users] Re: -slave and perl

Jonas Jensen jbj at knef.dk
Wed Jan 15 19:30:17 CET 2003


On Wed, 2003-01-15 at 12:18, Angel wrote:
> Ok... I just realized you're probably going to want to get the output from the 
> mencoder command. You'll need to use either IPC::Open2 or IPC::Open3 to do 
> this. Something along the lines of:
> 
> use IPC::Open2;
> local WRITE_FH;
> local READ_FH;
> 
> open2(\*READ_FH, \*WRITE_FH, 'mencoder blah blah blah');
> 
> If the output of mencoder is via stderr.. you might need to use open3 to 
> capture it.

IPC::Open2 should only be used as a last resort. As its manual states
you can easily get deadlocks if the other program does its buffering in
a way you don't control. Also, the problem can be solved simpler by
forking:

if (open STDOUT, "|-") {
    $| = 1; # autoflush
    # write the seek commands to STDOUT
    exit;

} else {
    if (open STDOUT, "|-") {
        exec("mplayer blah blah 2>&1"); # the 2>&1 part redirects stderr too

    } else {
        # read from STDIN and parse the crop parameters
    }
}

This way of using open does an implicit fork, so you'll have two perl
processes and one mplayer process. Because the perl processes are
independent of each other they will not deadlock, and I find the code
conceptually simpler because the seeking and crop-parsing code is
completely seperated.

-- 
Jonas Jensen <jbj at knef.dk>



More information about the MPlayer-users mailing list