#!/usr/bin/perl use Video::Capture::V4l; use Video::RTjpeg; $|=1; $SIG{PIPE} = 'IGNORE'; $stream = "/tmp/vstream"; require $stream; $mpegencode = "/root/cvt/mpeg_movie-1.6.0/video_in/mpeg_encode"; my $gop = 8; $tmpdir = "/tmp/encode$$/"; $tmpdir = "/tmp/encode"; mkdir $tmpdir, 0700; $fsize = $w*$h*2; $partlen = $fps*60; $partlen = $gop*100; my @dec; sub new_vdecoder { my $number = @dec; my $decp = do { local *DECODER_READER }; my $decc = do { local *DECODER_WRITER }; pipe $decp, $decc; if (fork==0) { my ($buf, $tables); open DATA, "<$outprefix.v$number" or die; read DATA, $buf, 4; my ($tlen) = unpack "N*", $buf; read DATA, $tables, $tlen; Video::RTjpeg::init_decompress($tables, $w, $h); while (read DATA, $buf, 8) { my ($time, $size) = unpack "N*", $buf; print $decc pack "N", $time; read DATA, $buf, $size; print $decc Video::RTjpeg::decompress $buf; } exit; } push @dec, $decp; } my @nframeid; sub next_frame { my $min = 1e30; my $buf; my $minid; for (0..$#dec) { unless (defined $nframeid[$_]) { read $dec[$_], $buf, 4; $nframeid[$_] = unpack "N", $buf; } ($min,$minid) = ($nframeid[$_],$_) if $nframeid[$_] < $min && defined $nframeid[$_]; } read $dec[$minid], $buf, $fsize; undef $nframeid[$minid]; ($buf, $min); } new_vdecoder for 1..$vencoders; my $part = 0; sub do_encode { my ($pstart, $pframes) = @_; $pframes = sprintf "%06d", $pframes-1; $part = sprintf "%03d", $part+1; open TEMPLATE, ">$tmpdir/param" or die; print TEMPLATE <$tmpdir/frame%06d.yuv", $pframe; print FRAME $buf; close FRAME; $frame++; $pframe++; print "s" if $frame != $framex; } last if $frame >= $nframe; } do_encode $pstart, $pframe;