| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use Video::Capture::V4l; |
| 4 |
|
| 5 |
sub print_capability { |
| 6 |
my $c=shift; |
| 7 |
print "Device: "; |
| 8 |
print "name ",$c->name; |
| 9 |
print ", type"; |
| 10 |
for (qw(capture tuner teletext overlay chromakey clipping frameram scales monochrome subcapture)) { |
| 11 |
print " $_" if eval "\$c->$_"; |
| 12 |
} |
| 13 |
print ", channels ",$c->channels; |
| 14 |
print ", audios ",$c->audios; |
| 15 |
print ", sizes ",$c->minwidth,"x",$c->minheight,"-",$c->maxwidth,"x",$c->maxheight; |
| 16 |
print "\n"; |
| 17 |
} |
| 18 |
|
| 19 |
sub print_channel { |
| 20 |
my $c=shift; |
| 21 |
print "Channel ",$c->channel,": "; |
| 22 |
print "name ",$c->name; |
| 23 |
print ", tuners ",$c->tuners; |
| 24 |
print ", flags"; |
| 25 |
for (qw(tuner audio)) { |
| 26 |
print " $_" if eval "\$c->$_"; |
| 27 |
} |
| 28 |
print ", type"; |
| 29 |
for (qw(tv camera)) { |
| 30 |
print " $_" if eval "\$c->$_"; |
| 31 |
} |
| 32 |
# PAL, NTSC, SECAM, PAL-NC, PAL-M, PAL-N, NTSC-Japan |
| 33 |
print ", norm ",$c->norm; |
| 34 |
print "\n"; |
| 35 |
} |
| 36 |
|
| 37 |
sub print_tuner { |
| 38 |
my $c=shift; |
| 39 |
print "Tuner ",$c->tuner,": "; |
| 40 |
print "name ",$c->name; |
| 41 |
print ", range ",$c->rangelow,"-",$c->rangehigh; |
| 42 |
print ", flags"; |
| 43 |
for (qw(pal ntsc secam low norm stereo_on rds_on mbs_on)) { |
| 44 |
print " $_" if eval "\$c->$_"; |
| 45 |
} |
| 46 |
print ", mode ",$c->mode; |
| 47 |
print ", signal ",$c->signal; |
| 48 |
print "\n"; |
| 49 |
} |
| 50 |
|
| 51 |
sub print_audio { |
| 52 |
my $c=shift; |
| 53 |
print "Audio Channel ",$c->audio,": "; |
| 54 |
print "volume ",$c->volume; |
| 55 |
print ", bass ",$c->bass; |
| 56 |
print ", treble ",$c->treble; |
| 57 |
print ", flags"; |
| 58 |
for (qw(mute mutable volume bass treble)) { |
| 59 |
print " $_" if eval "\$c->$_"; |
| 60 |
} |
| 61 |
print ", name ",$c->name; |
| 62 |
print ", mode ",$c->mode; |
| 63 |
print ", balance ",$c->balance; |
| 64 |
print ", step ",$c->step; |
| 65 |
print "\n"; |
| 66 |
} |
| 67 |
|
| 68 |
sub print_picture { |
| 69 |
my $c=shift; |
| 70 |
print "Picture Settings: "; |
| 71 |
print "brightness ",$c->brightness; |
| 72 |
print ", hue ",$c->hue; |
| 73 |
print ", colour ",$c->colour; |
| 74 |
print ", contrast ",$c->contrast; |
| 75 |
print ", whiteness ",$c->whiteness; |
| 76 |
print ", depth ",$c->depth; |
| 77 |
print ", palette ",$c->palette; |
| 78 |
print "\n"; |
| 79 |
} |
| 80 |
|
| 81 |
$grab = new Video::Capture::V4l |
| 82 |
or die "Unable to open Videodevice: $!"; |
| 83 |
|
| 84 |
print_capability $grab->capability; |
| 85 |
for (0..$grab->capability->channels-1) { |
| 86 |
print_channel $grab->channel($_); |
| 87 |
} |
| 88 |
|
| 89 |
for($_=0; my $tuner = $grab->tuner($_); $_++) { |
| 90 |
last if $tuner->tuner != $_; |
| 91 |
print_tuner $tuner; |
| 92 |
} |
| 93 |
|
| 94 |
for($_=0; my $audio = $grab->audio($_); $_++) { |
| 95 |
last if $audio->audio != $_; |
| 96 |
print_audio $audio; |
| 97 |
} |
| 98 |
|
| 99 |
print_picture $grab->picture; |
| 100 |
|
| 101 |
my $channel = $grab->channel (0); |
| 102 |
my $tuner = $grab->tuner (0); |
| 103 |
$tuner->mode(MODE_PAL); |
| 104 |
$channel->norm(MODE_PAL); |
| 105 |
$tuner->mode(8); |
| 106 |
$tuner->set; |
| 107 |
$channel->set; |
| 108 |
|
| 109 |
$RTL2 = 154250; |
| 110 |
$RTL2 = 196250; |
| 111 |
|
| 112 |
my $format = PALETTE_YUYV; |
| 113 |
|
| 114 |
print $grab->freq ($RTL2),"\n"; |
| 115 |
|
| 116 |
$|=1; |
| 117 |
|
| 118 |
my($w,$h)=(576,432); |
| 119 |
|
| 120 |
my @dests = ( |
| 121 |
"stream1", |
| 122 |
"stream2", |
| 123 |
"stream3", |
| 124 |
); |
| 125 |
|
| 126 |
my $frame=0; |
| 127 |
my $fr=$grab->capture($frame, $w, $h, $format); |
| 128 |
my $index=0; |
| 129 |
|
| 130 |
for(;;) { |
| 131 |
my $nfr = $grab->capture(1-$frame, $w, $h, $format); |
| 132 |
$grab->sync($frame) or print "unable to sync"; |
| 133 |
|
| 134 |
# save $fr now, as it contains the raw BGR data |
| 135 |
use File::Sync qw/fsync/; |
| 136 |
$index++; |
| 137 |
print "."; |
| 138 |
open FRAME, (sprintf ">%s/frame%08d", $dests[$index % @dests], $index) or die; |
| 139 |
print FRAME $fr; |
| 140 |
close FRAME; |
| 141 |
|
| 142 |
$frame = 1-$frame; |
| 143 |
$fr = $nfr; |
| 144 |
} |
| 145 |
|