zentara has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm toying around with a Tk frontend to mplayer. One of the ways I can use it, is in slave mode, reading from STDIN. When I do this, I need to feed it a file fast to avoid frame drops, like:
my $pid = open(MP, " | mplayer @options -v 3 - "); open (FH,"< z.mpg"); read( FH, my $buf, -s FH ); close FH; print MP $buf;
That works without dropping any frames. But I want to be able to interrupt the STDIN feed, and I've tried things like
open( FH, "< z.mpg" ); while ( sysread FH, my $data, 32678 ) { if($pause == 1){ goto ENDP } else{syswrite MP, $data;} } ENDP:
The problem is that it sends all the $data to mplayer almost immediately, so even if it is a long, say 1 minute video, and I set "$pause = 1" immediately after starting, the pause has no effect, and the entire video is played. Does anyone have a way of throttling this?

Or is there a way to sysread off of the slurped $buf a chunk at a time. I've been able to write to a variable as a filehandle, but am having trouble reading it like a filehandle.


I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re: loop with throttle through an mpeg file
by simonm (Vicar) on Dec 23, 2004 at 17:40 UTC
    You can use substr() to grab chunks of your $buf, and Time::HiRes's usleep() to pause very briefly between chunks.

    However, unless your file has a known, constant bitrate, it will be difficult to decide how quickly to push chunks to the player.