#!/usr/bin/perl use Time::HiRes qw ( usleep getitimer setitimer ITIMER_REAL time ); use Video::Frequencies; use Video::ivtv; #furioustv script arguments $device = $ARGV[0]; $channel = $ARGV[1]; $seconds = $ARGV[2]; $file = $ARGV[3]; #find an unused filename to write to #should produce the same result as the bash code in the ftv examples $ind = 1; if (-e $file) { while (-e ($file . "-" . $ind)) { ++$ind; } $file = $file . "-" . $ind; } #perl is quirky $device = "<" . $device; $file = ">" . $file; #frequency voodoo $freq = $CHANLIST{'ntsc-cable'}->{$channel}; my $driverf = ($freq * 16)/1000; #we use the ivtv interface because it works and #for some reason v4lctl does not work for me open(my $tuner, $device) or die "unable to open: $!"; my $tunerFD = fileno($tuner); my $ivtvObj = Video::ivtv->new(); if (!$ivtvObj->setFrequency($tunerFD, 0, $driverf)) { die "Error: setFrequency($driverf) failed!\n"; } close($tuner); #copy straight from the pvr device to the file #in binary mode of course, no re-encoding open(VIDEODEV, $device); open(FILE, $file); binmode VIDEODEV; binmode FILE; #close files and exit after time elapses $SIG{VTALRM} = sub { close(VIDEODEV); close(FILE); exit(); }; setitimer(ITIMER_REAL, $seconds); #read up to 64k at a time and don't use all the cpu time while (1) { while ( read (VIDEODEV, $buffer, 65536) and print FILE $buffer ) {}; usleep(100); }