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