1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/usr/bin/perl
use Video::Capture::V4l;
BEGIN { eval "use Time::HiRes 'time'" }
$grab = new Video::Capture::V4l;
my $channel = $grab->channel (0);
my $tuner = $grab->tuner (0);
$tuner->mode(MODE_PAL); $tuner->set;
$channel->norm(MODE_PAL); $channel->set;
my $fps = 25; # glorious PAL
$grab->picture->brightness(32768);
$grab->picture->contrast(40000);
$grab->picture->hue(32768);
$grab->picture->colour(32768);
$grab->picture->set;
#$RTL2 = 591250;
#$RTL2 = 855250;
$RTL2 = 154250;
print $grab->freq ($RTL2),"\n";
$|=1;
my($w,$h)=(128,128);
my $count = 0;
open DB,">db" or die;
select DB; $|=1; select STDOUT;
print "press enter to start> "; <STDIN>;
my $frame=0;
my $fr=$grab->capture ($frame,$w,$h);
print DB pack("N*",$w>>3,$h>>3);
for(;;) {
my $nfr = $grab->capture (1-$frame,$w,$h);
$grab->sync($frame) or die "unable to sync";
my $stamp = time;
if ($start && $start!=$stamp) {
$stamp = int(($stamp-$start)*$fps+0.5);
print(($stamp-$count)," frames lost\n") if $stamp > $count;
$count=$stamp;
} else {
$start=$stamp;
$stamp=$count;
}
# width MUST be divisible by 4
Video::Capture::V4l::reduce2($fr,$w>>0);
Video::Capture::V4l::reduce2($fr,$w>>1);
Video::Capture::V4l::reduce2($fr,$w>>2);
Video::Capture::V4l::normalize($fr);
#${$img->get_dataref}=$fr; $img->upd_data();
#wpnm $img,sprintf('frame/%03d',$count),'PPM',1;
print " $count\r";
$count++;
print DB pack("i",$stamp),$fr;
$frame = 1-$frame;
$fr = $nfr;
}
|