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 |
use Time::HiRes qw(usleep); |
---|
27 |
|
---|
28 |
|
---|
29 |
$path = $0; |
---|
30 |
$path =~ s/tvrecording.pl$//i; |
---|
31 |
if ($pwd ne "./"){ |
---|
32 |
push( @INC, "$path"); |
---|
33 |
} |
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
$extendrecendsec = 10; |
---|
44 |
$startupsleeptime = 52; |
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
require 'foltialib.pl'; |
---|
50 |
|
---|
51 |
&writelog("tvrecording: DEBUG $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] "); |
---|
52 |
|
---|
53 |
sub getChCallsign { |
---|
54 |
if ($ARGV[5] ne ""){ |
---|
55 |
$recchname = $ARGV[5] ; |
---|
56 |
}else{ |
---|
57 |
$recchname = $recch."ch"; |
---|
58 |
} |
---|
59 |
|
---|
60 |
} |
---|
61 |
|
---|
62 |
sub getRecPath{ |
---|
63 |
$recfolderpath = '/home/foltia/php/tv'; |
---|
64 |
} |
---|
65 |
|
---|
66 |
|
---|
67 |
&prepare; |
---|
68 |
|
---|
69 |
$reclengthsec = &chkrecprocess(); |
---|
70 |
&setbitrate; |
---|
71 |
&chkextinput; |
---|
72 |
|
---|
73 |
$reclengthsec = $reclengthsec + $extendrecendsec ; |
---|
74 |
|
---|
75 |
&writelog("tvrecording:$recch:$reclengthsec:$outputfile:$recdevice:$capturedeviceinputnum:$ivtvrecch:$stdbitrate:$peakbitrate"); |
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 |
|
---|
80 |
sub chkextinput{ |
---|
81 |
|
---|
82 |
if ($recch == 0){ |
---|
83 |
if ($svideoinputnum > -1 && $svideoinputnum < 30){ |
---|
84 |
$capturedeviceinputnum = $svideoinputnum ; |
---|
85 |
}else{ |
---|
86 |
$capturedeviceinputnum = 7 ; |
---|
87 |
} |
---|
88 |
$capturedeviceinputName = "S-Video 0"; |
---|
89 |
$ivtvrecch = ''; |
---|
90 |
}elsif($recch == -1){ |
---|
91 |
if ($comvideoinputnum > -1 && $comvideoinputnum < 30){ |
---|
92 |
$capturedeviceinputnum = $comvideoinputnum; |
---|
93 |
}else{ |
---|
94 |
$capturedeviceinputnum = 8; |
---|
95 |
} |
---|
96 |
$capturedeviceinputName = "Composite 0"; |
---|
97 |
$ivtvrecch = ''; |
---|
98 |
}else{ |
---|
99 |
if ($tunerinputnum > -1 && $tunerinputnum < 30){ |
---|
100 |
$capturedeviceinputnum = $tunerinputnum ; |
---|
101 |
}else{ |
---|
102 |
$capturedeviceinputnum = 6 ; |
---|
103 |
} |
---|
104 |
$capturedeviceinputName = "Tuner 0"; |
---|
105 |
$ivtvrecch = $recch; |
---|
106 |
} |
---|
107 |
|
---|
108 |
if($recch > 12){ |
---|
109 |
if ($uhfbandtype == 1){ |
---|
110 |
$frequencyTable = "ntsc-cable-jp"; |
---|
111 |
}else{ |
---|
112 |
$frequencyTable = "ntsc-bcast-jp"; |
---|
113 |
} |
---|
114 |
}else{ |
---|
115 |
$frequencyTable = "ntsc-bcast-jp"; |
---|
116 |
} |
---|
117 |
&writelog ("tvrecording DEBUG $frequencyTable $recch"); |
---|
118 |
|
---|
119 |
} |
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 |
sub chkrecprocessOLD{ |
---|
124 |
|
---|
125 |
my $mencoderkillcmd = ""; |
---|
126 |
|
---|
127 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp $recdevice`; |
---|
128 |
$mencoderkillcmd =~ s/p//; |
---|
129 |
|
---|
130 |
if ($mencoderkillcmd != ""){ |
---|
131 |
|
---|
132 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
---|
133 |
system ($mencoderkillcmd); |
---|
134 |
chomp($mencoderkillcmd); |
---|
135 |
&writelog ("tvrecording Killed current recording process. process:$mencoderkillcmd"); |
---|
136 |
sleep(1); |
---|
137 |
my $videodevice =`/usr/sbin/lsof $recdevice`; |
---|
138 |
|
---|
139 |
while ($videodevice =~ /tvrecording/){ |
---|
140 |
|
---|
141 |
$videodevice =`/usr/sbin/lsof $recdevice`; |
---|
142 |
sleep(1); |
---|
143 |
$sleepcounter++; |
---|
144 |
$reclengthsec = $reclengthsec - $sleepcounter; |
---|
145 |
&writelog ("tvrecording videodevice wait:$sleepcounter"); |
---|
146 |
} |
---|
147 |
$sleepcounter = 0; |
---|
148 |
} |
---|
149 |
|
---|
150 |
return $reclengthsec; |
---|
151 |
|
---|
152 |
} |
---|
153 |
|
---|
154 |
sub chkrecprocess{ |
---|
155 |
my $mencoderkillcmd = ""; |
---|
156 |
my $j = $recunits -1; |
---|
157 |
my $i = 0; |
---|
158 |
my $testrecdevice = ""; |
---|
159 |
my @usedevices ; |
---|
160 |
my @unusedevices; |
---|
161 |
my $n = 0; |
---|
162 |
$recdevice = ""; |
---|
163 |
if ($ARGV[7] ne ""){ |
---|
164 |
$recdevice = $ARGV[7] ; |
---|
165 |
} |
---|
166 |
|
---|
167 |
|
---|
168 |
for ($i = 0 ;$i <= $j ; $i++){ |
---|
169 |
|
---|
170 |
$testrecdevice = "/dev/video$i"; |
---|
171 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp $testrecdevice`; |
---|
172 |
$mencoderkillcmd =~ s/p//; |
---|
173 |
if ($mencoderkillcmd != ""){ |
---|
174 |
push (@usedevices , $testrecdevice); |
---|
175 |
&writelog ("tvrecording now using:$testrecdevice"); |
---|
176 |
}else{ |
---|
177 |
push (@unusedevices , $testrecdevice); |
---|
178 |
&writelog ("tvrecording unused:$testrecdevice"); |
---|
179 |
} |
---|
180 |
} |
---|
181 |
|
---|
182 |
$i = 0; |
---|
183 |
$n = @unusedevices; |
---|
184 |
|
---|
185 |
if ($recdevice ne ""){ |
---|
186 |
|
---|
187 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp $recdevice`; |
---|
188 |
$mencoderkillcmd =~ s/p//; |
---|
189 |
if ($mencoderkillcmd != ""){ |
---|
190 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
---|
191 |
system ($mencoderkillcmd); |
---|
192 |
chomp($mencoderkillcmd); |
---|
193 |
&writelog ("tvrecording Killed current recording process. $recdevice:$mencoderkillcmd"); |
---|
194 |
sleep(1); |
---|
195 |
} |
---|
196 |
}else{ |
---|
197 |
|
---|
198 |
if (($n == 0) and ($recch > 0)) { |
---|
199 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp /dev/video$i`; |
---|
200 |
$mencoderkillcmd =~ s/p//; |
---|
201 |
if ($mencoderkillcmd != ""){ |
---|
202 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
---|
203 |
system ($mencoderkillcmd); |
---|
204 |
chomp($mencoderkillcmd); |
---|
205 |
&writelog ("tvrecording Killed current recording process. /dev/video$i:$mencoderkillcmd"); |
---|
206 |
sleep(1); |
---|
207 |
} |
---|
208 |
$recdevice = "/dev/video$i"; |
---|
209 |
&writelog ("tvrecording select device:$recdevice"); |
---|
210 |
|
---|
211 |
}elsif ($recch <= 0) { |
---|
212 |
|
---|
213 |
|
---|
214 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp /dev/video$j`; |
---|
215 |
$mencoderkillcmd =~ s/p//; |
---|
216 |
if ($mencoderkillcmd != ""){ |
---|
217 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
---|
218 |
system ($mencoderkillcmd); |
---|
219 |
chomp($mencoderkillcmd); |
---|
220 |
&writelog ("tvrecording Killed current recording process. /dev/video$j:$mencoderkillcmd"); |
---|
221 |
sleep(1); |
---|
222 |
} |
---|
223 |
$recdevice = "/dev/video$j"; |
---|
224 |
}else{ |
---|
225 |
|
---|
226 |
$recdevice = shift(@unusedevices ); |
---|
227 |
} |
---|
228 |
|
---|
229 |
} |
---|
230 |
|
---|
231 |
|
---|
232 |
if ($recdevice eq ""){ |
---|
233 |
$recdevice = "/dev/video0"; |
---|
234 |
&writelog ( "Rec Device un defined. / $recch "); |
---|
235 |
} |
---|
236 |
return $reclengthsec; |
---|
237 |
|
---|
238 |
} |
---|
239 |
|
---|
240 |
|
---|
241 |
|
---|
242 |
sub prepare{ |
---|
243 |
|
---|
244 |
|
---|
245 |
$recch = $ARGV[0] ; |
---|
246 |
$reclengthsec = $ARGV[1]; |
---|
247 |
if (($recch eq "" )|| ($reclengthsec eq "")){ |
---|
248 |
print "usage tvrecording.pl ch length(sec) [clip No(000-)] [filename] [bitrate(5)] [TID] [NO] [/dev/video0]\n"; |
---|
249 |
exit; |
---|
250 |
} |
---|
251 |
|
---|
252 |
srand(time ^ ($$ + ($$ << 15))); |
---|
253 |
my $useconds = int(rand(12000000)); |
---|
254 |
my $intval = int ($useconds / 1000000); |
---|
255 |
my $startupsleeptimemicro = ($startupsleeptime * 1000000) - $useconds; |
---|
256 |
$reclengthsec = $reclengthsec + $intval + 1; |
---|
257 |
|
---|
258 |
|
---|
259 |
|
---|
260 |
&writelog("tvrecording: DEBUG SLEEP $startupsleeptime:$useconds:$intval:$startupsleeptimemicro"); |
---|
261 |
|
---|
262 |
usleep ( $startupsleeptimemicro ); |
---|
263 |
|
---|
264 |
if ($recunits > 1){ |
---|
265 |
my $deviceno = $recunits - 1; |
---|
266 |
$recdevice = "/dev/video$deviceno"; |
---|
267 |
$recch = $ARGV[0] ; |
---|
268 |
}else{ |
---|
269 |
|
---|
270 |
$recdevice = "/dev/video0"; |
---|
271 |
$recch = $ARGV[0] ; |
---|
272 |
} |
---|
273 |
|
---|
274 |
&getChCallsign(); |
---|
275 |
|
---|
276 |
|
---|
277 |
$outputpath = "$recfolderpath"."/"; |
---|
278 |
|
---|
279 |
if ($ARGV[6] eq "0"){ |
---|
280 |
$outputfile = $outputpath.$ARGV[5]."--"; |
---|
281 |
}else{ |
---|
282 |
$outputfile = $outputpath.$ARGV[5]."-".$ARGV[6]."-"; |
---|
283 |
} |
---|
284 |
|
---|
285 |
if ($ARGV[3] ne ""){ |
---|
286 |
|
---|
287 |
|
---|
288 |
|
---|
289 |
|
---|
290 |
|
---|
291 |
$outputfile = $ARGV[3]; |
---|
292 |
$outputfile = &filenameinjectioncheck($outputfile); |
---|
293 |
$outputfile = $outputpath.$outputfile ; |
---|
294 |
|
---|
295 |
|
---|
296 |
&writelog("tvrecording: DEBUG ARGV[2] ne null \$outputfile $outputfile "); |
---|
297 |
|
---|
298 |
}else{ |
---|
299 |
$outputfile .= `date +%Y%m%d-%H%M --date "1 min "`; |
---|
300 |
chomp($outputfile); |
---|
301 |
$outputfile .= ".m2p"; |
---|
302 |
&writelog("tvrecording: DEBUG ARGV[2] is null \$outputfile $outputfile "); |
---|
303 |
|
---|
304 |
} |
---|
305 |
|
---|
306 |
|
---|
307 |
@wday_name = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); |
---|
308 |
$sleepcounter = 0; |
---|
309 |
$cmd=""; |
---|
310 |
|
---|
311 |
|
---|
312 |
if ( -e "$outputfile" ){ |
---|
313 |
&writelog("tvrecording :ABORT :recfile $outputfile exist."); |
---|
314 |
exit 1; |
---|
315 |
} |
---|
316 |
|
---|
317 |
} |
---|
318 |
|
---|
319 |
sub setbitrate{ |
---|
320 |
$bitrate = $ARGV[4] ; |
---|
321 |
$bitrate = $bitrate * 1024*1024; |
---|
322 |
$peakbitrate = $bitrate + 350000; |
---|
323 |
$recordbitrate = " --bitrate $bitrate --peakbitrate $peakbitrate "; |
---|
324 |
$stdbitrate = "$bitrate"; |
---|
325 |
$peakbitrate = "$peakbitrate"; |
---|
326 |
} |
---|
327 |
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 |
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 |
|
---|
338 |
|
---|
339 |
|
---|
340 |
|
---|
341 |
|
---|
342 |
|
---|
343 |
|
---|
344 |
|
---|
345 |
|
---|
346 |
|
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 |
|
---|
357 |
|
---|
358 |
|
---|
359 |
|
---|
360 |
|
---|
361 |
|
---|
362 |
|
---|
363 |
|
---|
364 |
|
---|
365 |
|
---|
366 |
|
---|
367 |
|
---|
368 |
|
---|
369 |
|
---|
370 |
|
---|
371 |
|
---|
372 |
|
---|
373 |
|
---|
374 |
|
---|
375 |
|
---|
376 |
|
---|
377 |
|
---|
378 |
|
---|
379 |
|
---|
380 |
|
---|
381 |
|
---|
382 |
|
---|
383 |
|
---|
384 |
|
---|
385 |
|
---|
386 |
|
---|
387 |
|
---|
388 |
|
---|
389 |
|
---|
390 |
|
---|
391 |
|
---|
392 |
|
---|
393 |
|
---|
394 |
|
---|
395 |
|
---|
396 |
|
---|
397 |
|
---|
398 |
|
---|
399 |
|
---|
400 |
|
---|
401 |
|
---|
402 |
|
---|
403 |
|
---|
404 |
|
---|
405 |
|
---|
406 |
|
---|
407 |
|
---|
408 |
|
---|
409 |
|
---|
410 |
|
---|
411 |
|
---|
412 |
|
---|
413 |
|
---|
414 |
|
---|
415 |
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|
421 |
|
---|
422 |
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 |
|
---|
428 |
|
---|
429 |
|
---|
430 |
use Getopt::Long qw(:config no_ignore_case bundling); |
---|
431 |
use Fcntl; |
---|
432 |
use Video::Frequencies 0.03; |
---|
433 |
use Video::ivtv 0.12; |
---|
434 |
use Config::IniFiles; |
---|
435 |
|
---|
436 |
my $version="1.29"; |
---|
437 |
my $cfgVersion = "2"; |
---|
438 |
my $cfgVersionStr = "_configVersion_"; |
---|
439 |
|
---|
440 |
my @capabilities = (); |
---|
441 |
|
---|
442 |
my %settings = ( |
---|
443 |
Channel => $ivtvrecch , |
---|
444 |
RecordDuration => $reclengthsec , |
---|
445 |
InputNum => $capturedeviceinputnum , |
---|
446 |
InputName => "$capturedeviceinputName", |
---|
447 |
OutputDirectory => "$recfolderpath", |
---|
448 |
VideoDevice => "$recdevice", |
---|
449 |
VideoWidth => "720", |
---|
450 |
VideoHeight => "480", |
---|
451 |
VideoStandard => "NTSC", |
---|
452 |
VideoType => "mpeg", |
---|
453 |
Bitrate => "$stdbitrate", |
---|
454 |
PeakBitrate => "$peakbitrate", |
---|
455 |
Aspect => 2, |
---|
456 |
AudioBitmask => 0x00e9, |
---|
457 |
BFrames => 3, |
---|
458 |
DNRMode => 0, |
---|
459 |
DNRSpatial => 0, |
---|
460 |
DNRTemporal => 0, |
---|
461 |
DNRType => 0, |
---|
462 |
Framerate => 0, |
---|
463 |
FramesPerGOP => 15, |
---|
464 |
GOPClosure => 1, |
---|
465 |
Pulldown => 0, |
---|
466 |
StreamType => 0, |
---|
467 |
OutputFileName => "$outputfile", |
---|
468 |
FrequencyTable => "$frequencyTable", |
---|
469 |
Frequency => "", |
---|
470 |
ResetCardSettings => 1, |
---|
471 |
ConfigFileName => "$ENV{HOME}/.ivtvrc", |
---|
472 |
UpdateConfigFile => 0, |
---|
473 |
UseConfigFile => 0, |
---|
474 |
UsingIvtvDriver => 1, |
---|
475 |
DontRecord => 0, |
---|
476 |
DirectoryFormatString => " ", |
---|
477 |
DateTimeFormatString => "+%Y%m%d-%H%M", |
---|
478 |
|
---|
479 |
minBitrate => 1, |
---|
480 |
maxBitrate => 14500000, |
---|
481 |
minPeakBitrate => 1500, |
---|
482 |
maxPeakBitrate => 16000000, |
---|
483 |
|
---|
484 |
SetMSPMatrix => 1, |
---|
485 |
MSPInput => 3, |
---|
486 |
MSPOutput => 1, |
---|
487 |
MSPSleep => 2, |
---|
488 |
|
---|
489 |
Debug => 0, |
---|
490 |
TunerNum => 0, |
---|
491 |
); |
---|
492 |
|
---|
493 |
|
---|
494 |
print " $settings{InputNum} / $settings{InputName} /IVTVRECCH:$settings{Channel}/$recdevice \n\n" if $settings{Debug}; |
---|
495 |
|
---|
496 |
|
---|
497 |
my $result=""; |
---|
498 |
my @profileNames=(); |
---|
499 |
my %configIni; |
---|
500 |
my $ivtvObj = Video::ivtv->new(); |
---|
501 |
|
---|
502 |
|
---|
503 |
my %mappings = ( |
---|
504 |
"Channel" => "c|channel", |
---|
505 |
"RecordDuration" => "t|duration", |
---|
506 |
"InputNum" => "i|inputnum", |
---|
507 |
"InputName" => "I|inputname", |
---|
508 |
"OutputDirectory" => "D|directory", |
---|
509 |
"VideoDevice" => "d|input", |
---|
510 |
"VideoWidth" => "W|width", |
---|
511 |
"VideoHeight" => "H|height", |
---|
512 |
"VideoStandard" => "s|standard", |
---|
513 |
"VideoType" => "T|type", |
---|
514 |
"Bitrate" => "b|bitrate", |
---|
515 |
"PeakBitrate" => "B|peakbitrate", |
---|
516 |
"Aspect" => "aspect", |
---|
517 |
"AudioBitmask" => "audio-bitmask", |
---|
518 |
"BFrames" => "bframes", |
---|
519 |
"DNRMode" => "dnrmode", |
---|
520 |
"DNRSpatial" => "dnrspatial", |
---|
521 |
"DNRTemporal" => "dnrtemporal", |
---|
522 |
"DNRType" => "dnrtype", |
---|
523 |
"Framerate" => "framerate", |
---|
524 |
"FramesPerGOP" => "framespergop", |
---|
525 |
"GOPClosure" => "gopclosure", |
---|
526 |
"Pulldown" => "pulldown", |
---|
527 |
"StreamType" => "streamtype", |
---|
528 |
"OutputFileName" => "o|output", |
---|
529 |
"FrequencyTable" => "f|freqtable", |
---|
530 |
"Frequency" => "F|frequency", |
---|
531 |
"ResetCardSettings" => "R|noreset", |
---|
532 |
"DirectoryFormatString" => "directory-format", |
---|
533 |
"DateTimeFormatString" => "date-format", |
---|
534 |
"Debug" => "debug", |
---|
535 |
"TunerNum" => "tuner-num", |
---|
536 |
"SetMSPMatrix" => "set-msp-matrix", |
---|
537 |
"MSPInput" => "msp-input", |
---|
538 |
"MSPOutput" => "msp-output", |
---|
539 |
"MSPSleep" => "msp-sleep", |
---|
540 |
"OutputMPGFileName" => "outputmpgfilename", |
---|
541 |
); |
---|
542 |
|
---|
543 |
my %codecMappings = ( |
---|
544 |
"Aspect" => "aspect", |
---|
545 |
"AudioBitmask" => "audio_bitmask", |
---|
546 |
"BFrames" => "bframes", |
---|
547 |
"Bitrate" => "bitrate", |
---|
548 |
"PeakBitrate" => "bitrate_peak", |
---|
549 |
"DNRMode" => "dnr_mode", |
---|
550 |
"DNRSpatial" => "dnr_spatial", |
---|
551 |
"DNRTemporal" => "dnr_temporal", |
---|
552 |
"DNRType" => "dnr_type", |
---|
553 |
"Framerate" => "framerate", |
---|
554 |
"FramesPerGOP" => "framespergop", |
---|
555 |
"GOPClosure" => "gop_closure", |
---|
556 |
"Pulldown" => "pulldown", |
---|
557 |
"StreamType" => "stream_type", |
---|
558 |
); |
---|
559 |
|
---|
560 |
|
---|
561 |
if ( -e "/dev/.devfsd" ) |
---|
562 |
{ |
---|
563 |
$settings{VideoDevice} = "/dev/v4l/video0"; |
---|
564 |
} |
---|
565 |
|
---|
566 |
|
---|
567 |
|
---|
568 |
|
---|
569 |
|
---|
570 |
|
---|
571 |
|
---|
572 |
|
---|
573 |
|
---|
574 |
|
---|
575 |
|
---|
576 |
|
---|
577 |
|
---|
578 |
|
---|
579 |
|
---|
580 |
|
---|
581 |
|
---|
582 |
|
---|
583 |
|
---|
584 |
|
---|
585 |
|
---|
586 |
|
---|
587 |
|
---|
588 |
|
---|
589 |
|
---|
590 |
|
---|
591 |
|
---|
592 |
|
---|
593 |
|
---|
594 |
|
---|
595 |
|
---|
596 |
|
---|
597 |
|
---|
598 |
|
---|
599 |
|
---|
600 |
|
---|
601 |
|
---|
602 |
|
---|
603 |
|
---|
604 |
|
---|
605 |
|
---|
606 |
|
---|
607 |
|
---|
608 |
|
---|
609 |
|
---|
610 |
|
---|
611 |
|
---|
612 |
|
---|
613 |
|
---|
614 |
|
---|
615 |
|
---|
616 |
|
---|
617 |
|
---|
618 |
|
---|
619 |
|
---|
620 |
|
---|
621 |
|
---|
622 |
|
---|
623 |
|
---|
624 |
|
---|
625 |
|
---|
626 |
|
---|
627 |
|
---|
628 |
|
---|
629 |
|
---|
630 |
|
---|
631 |
|
---|
632 |
|
---|
633 |
|
---|
634 |
|
---|
635 |
|
---|
636 |
|
---|
637 |
|
---|
638 |
|
---|
639 |
|
---|
640 |
|
---|
641 |
|
---|
642 |
|
---|
643 |
|
---|
644 |
|
---|
645 |
|
---|
646 |
|
---|
647 |
|
---|
648 |
|
---|
649 |
|
---|
650 |
|
---|
651 |
|
---|
652 |
|
---|
653 |
|
---|
654 |
|
---|
655 |
|
---|
656 |
|
---|
657 |
|
---|
658 |
|
---|
659 |
|
---|
660 |
|
---|
661 |
|
---|
662 |
my %customMap = (); |
---|
663 |
foreach my $profileName (keys %configIni) |
---|
664 |
{ |
---|
665 |
next if $profileName =~ /^(defaults)$/; |
---|
666 |
|
---|
667 |
if (exists $configIni{$profileName}{Frequency}) |
---|
668 |
{ |
---|
669 |
$customMap{$profileName} = $configIni{$profileName}{Frequency}; |
---|
670 |
} |
---|
671 |
} |
---|
672 |
$CHANLIST{custom} = \%customMap; |
---|
673 |
|
---|
674 |
|
---|
675 |
my @standards; |
---|
676 |
my %name2std; |
---|
677 |
my @inputs; |
---|
678 |
my %name2input; |
---|
679 |
my @codecInfo; |
---|
680 |
my @newCodecInfo; |
---|
681 |
|
---|
682 |
my $curinput; |
---|
683 |
my $curinputName; |
---|
684 |
my $std; |
---|
685 |
my $curstd = "???"; |
---|
686 |
my $curStandard = 0; |
---|
687 |
my $curChannel = 0; |
---|
688 |
my $curFrequency = 0; |
---|
689 |
|
---|
690 |
my $tuner; |
---|
691 |
my $err; |
---|
692 |
my $v4l2input; |
---|
693 |
|
---|
694 |
my $tmpDirectoryStr = formatDirectoryString(); |
---|
695 |
my $versionStr = "record-v4l2.pl $version for use with http://ivtv.sf.net/"; |
---|
696 |
my $usageStr = <<"END_OF_USAGE"; |
---|
697 |
$versionStr |
---|
698 |
|
---|
699 |
Usage: record-v4l2.pl [--channel CHANNEL] [--duration TIME] |
---|
700 |
[--directory DIRECTORY] [--output OUTPUT] |
---|
701 |
[--directory-format FORMAT] [--date-format FORMAT] |
---|
702 |
[--input VIDEO_DEV][--width WIDTH --height HEIGHT] |
---|
703 |
[--standard STANDARD] [--type TYPE] |
---|
704 |
[--inputnum INPUT |
---|
705 |
[--freqtable FREQENCY MAP] [--frequency FREQUENCY] |
---|
706 |
[--bitrate BITRATE] [--peakbitrate PEAK_BITRATE] |
---|
707 |
[--set-msp-matrix BOOL] [--msp-sleep SLEEP] |
---|
708 |
[--msp-input INPUT] [--msp-output OUTPUT] |
---|
709 |
[--profile PROFILE] [--list-freqtable] [--list-channels] |
---|
710 |
[--no-record] [--noreset] [--save] [--help] [--version] |
---|
711 |
[--aspect ASPECT] [--audio-bitmask AUDIO-BITMASK] [--bframes BFRAMES] |
---|
712 |
[--dnrmode DNRMODE] [--dnrspatial DNRSPATIAL] |
---|
713 |
[--dnrtemporal DNRTEMPORAL] [--dnrtype DNRTYPE] |
---|
714 |
[--framerate FRAMERATE] [--framespergop FRAMESPERGOP] |
---|
715 |
[--gopclosure GOPCLOSURE] [--pulldown PULLDOWN] |
---|
716 |
[--streamtype STREAMTYPE] [--debug] |
---|
717 |
[--tuner-num TUNERNUM] |
---|
718 |
[--list-inputs] [--list-standards] [CHANNEL] |
---|
719 |
|
---|
720 |
-c/--channel CHANNEL: channel number to switch to |
---|
721 |
NOTE: You can also specify the channel by itself. |
---|
722 |
Ex. record-v4l2.pl 73 |
---|
723 |
would change to channel 73 using the default settings |
---|
724 |
or the settings from your ~/.ivtvrc config file. |
---|
725 |
-t/--duration TIME: number of seconds to record |
---|
726 |
-D/--directory DIRECTORY: Base directory to record into |
---|
727 |
--directory-format FORMAT: format string that specifies the |
---|
728 |
sub-directory to create under the base directory that |
---|
729 |
the output file will be created in. This can be empty |
---|
730 |
to indicate no sub-directory should be created. |
---|
731 |
|
---|
732 |
Available tokens are: |
---|
733 |
%d - date formatted by --date-format |
---|
734 |
%I - input name recorded from |
---|
735 |
Any white space in the name is converted to |
---|
736 |
underscores (_). Ex. 'Tuner 0' => 'Tuner_0' |
---|
737 |
|
---|
738 |
%c - channel or "freq-#" frequency |
---|
739 |
|
---|
740 |
--date-format FORMAT: format string that specifies the |
---|
741 |
date format string to generate and substitute for |
---|
742 |
%d in the --directory-format string. |
---|
743 |
|
---|
744 |
Available tokens: see the date commands man page. |
---|
745 |
The string must start with a + (plus). |
---|
746 |
|
---|
747 |
-o/--output OUTPUT: name of file to create |
---|
748 |
-d/--input VIDEO_DEV: video device to capture from |
---|
749 |
-W/--width WIDTH: width of screen (720 for NTSC fullscreen) |
---|
750 |
-H/--height HEIGHT: height of screen (480 for NTSC fullscreen) |
---|
751 |
-s/--standard STANDARD: NTSC, PAL or SECAM - video standard to record in |
---|
752 |
-T/--type TYPE: mpeg or yuv output |
---|
753 |
-i/--inputnum INPUT |
---|
754 |
The index number of the input you want to use (0 -> n-1) |
---|
755 |
-I/--inputname INPUT NAME: The name of the input you want to use. |
---|
756 |
-f/--freqtable FREQUENCY MAP: Specify the frequency mapping to use. |
---|
757 |
-F/--frequency FREQUENCY: Specify the frequency to tune to. |
---|
758 |
ex. 517250 = NTSC Cable 73 (SCiFi) |
---|
759 |
--tuner-num TUNERNUM: Specify the tuner to use. |
---|
760 |
--set-msp-matrix BOOL: 1 - set the msp matrix after Video Standard changes |
---|
761 |
0 - never set the msp matrix |
---|
762 |
Uses the --msp-input and --msp-output options. |
---|
763 |
--msp-sleep SLEEP: number of seconds the card needs before we can program |
---|
764 |
the msp matrix. |
---|
765 |
--msp-input INPUT: Specify the input parameter to program the msp matrix. |
---|
766 |
Valid values are from 1 - 8. |
---|
767 |
--msp-output OUTPUT: Specify the output parameter to program the msp matrix. |
---|
768 |
Valid values are from 0 - 3. |
---|
769 |
-L/--list-freqtable: |
---|
770 |
list all available frequency mappings that Video::Frequencies knows |
---|
771 |
--list-channels: lists all channels and their frequencies for the |
---|
772 |
specified frequency table being used. |
---|
773 |
--list-inputs: lists all inputs the v4l2 driver reports. |
---|
774 |
--list-standards: lists all Video Standards the v4l2 driver supports. |
---|
775 |
-R/--noreset: Do not Reset anything that was changed |
---|
776 |
(standard, channel, resolution, etc.) |
---|
777 |
--no-record: Do not create any directories, capture data or reset the card |
---|
778 |
back to original settings. This is the ptune.pl mode. |
---|
779 |
-h/--help: display this help |
---|
780 |
-v/--version: display the version of this program |
---|
781 |
--debug: turns on debug output |
---|
782 |
|
---|
783 |
Codec related options: |
---|
784 |
-b/--bitrate BITRATE: Specify the Bitrate to capture at |
---|
785 |
-B/--peakbitrate PEAK_BITRATE: Specify the Peak Bitrate to capture at |
---|
786 |
--aspect ASPECT: Specify the aspect value |
---|
787 |
--audio-bitmask AUDIO-BITMASK: Specify the audio bitmask value |
---|
788 |
--bframes BFRAMES: Specify the bframes value |
---|
789 |
--dnrmode DNRMODE: Specify the dnr_mode value |
---|
790 |
--dnrspatial DNRSPATIAL: Specify the dnr_spatial value |
---|
791 |
--dnrtemporal DNRTEMPORAL: Specify the dnr_temporal value |
---|
792 |
--dnrtype DNRTYPE: Specify the dnr_type value |
---|
793 |
--framerate FRAMERATE: Specify the framerate value |
---|
794 |
--framespergop FRAMESPERGOP: Specify the framespergop value |
---|
795 |
--gopclosure GOPCLOSURE: Specify the gop_closure value |
---|
796 |
--pulldown PULLDOWN: Specify the pulldown value |
---|
797 |
--streamtype STREAMTYPE: Specify the stream_type value |
---|
798 |
|
---|
799 |
Config file related options: |
---|
800 |
-P/--profile PROFILE: Override defaults and command line values with the |
---|
801 |
config entries in the section labeled [PROFILE] from the |
---|
802 |
config file $settings{ConfigFileName}. |
---|
803 |
Examples: -P NTSC-DVD, -P PAL-DVD, --profile MY-SETTINGS |
---|
804 |
|
---|
805 |
You can specify this option multiple times and each successive |
---|
806 |
profile will overlay the defaults and any previous profiles. |
---|
807 |
You will not be able to create/update a profile if you do |
---|
808 |
specify multiple profiles. |
---|
809 |
-S/--save: save the current values as the defaults in |
---|
810 |
$settings{ConfigFileName}. |
---|
811 |
If -P/--profile PROFILE is specified, then those values that exist in |
---|
812 |
the specified profile will be updated. If the profile doesn't exist, |
---|
813 |
then it will be created, but will have all possible config items |
---|
814 |
defined in it. It will be your responsibility to hand check the |
---|
815 |
config file and remove any config items you do not want set for |
---|
816 |
that profile. |
---|
817 |
Any options specified on the command line will override options |
---|
818 |
defined in the config file. |
---|
819 |
|
---|
820 |
Notes: |
---|
821 |
If you specify both -i/--inputnum and -I/--inputname then |
---|
822 |
-i/--inputnum will take precedence. |
---|
823 |
|
---|
824 |
If you specify both -c/--channel and -F/--frequency then |
---|
825 |
-F/--frequency will take precedence. |
---|
826 |
|
---|
827 |
If you use a Profile, it has the ability to override all command line |
---|
828 |
arguments, so check your Profile first if things seem to be ignored. |
---|
829 |
|
---|
830 |
Defaults: |
---|
831 |
--duration $settings{RecordDuration} --input $settings{VideoDevice} --width $settings{VideoWidth} --height $settings{VideoHeight} --standard $settings{VideoStandard} |
---|
832 |
--type $settings{VideoType} --directory $settings{OutputDirectory} --output $settings{OutputFileName} |
---|
833 |
--directory-format "$settings{DirectoryFormatString}" --date-format "$settings{DateTimeFormatString}" |
---|
834 |
--inputnum $settings{InputNum} --inputname '$settings{InputName}' --freqtable $settings{FrequencyTable} |
---|
835 |
--set-msp-matrix $settings{SetMSPMatrix} --msp-sleep $settings{MSPSleep} --msp-input $settings{MSPInput} --msp-output $settings{MSPOutput} |
---|
836 |
--bitrate $settings{Bitrate} --peakbitrate $settings{PeakBitrate} --aspect $settings{Aspect} --audio-bitmask $settings{AudioBitmask} --bframes $settings{BFrames} |
---|
837 |
--dnrmode $settings{DNRMode} --dnrspatial $settings{DNRSpatial} --dnrtemporal $settings{DNRTemporal} --dnrtype $settings{DNRType} |
---|
838 |
--framerate $settings{Framerate} --framespergop $settings{FramesPerGOP} --gopclosure $settings{GOPClosure} --pulldown $settings{Pulldown} --streamtype $settings{StreamType} |
---|
839 |
--tuner-num $settings{TunerNum} |
---|
840 |
|
---|
841 |
config file = '$settings{ConfigFileName}' |
---|
842 |
|
---|
843 |
If Channel = $settings{Channel}, this would create: |
---|
844 |
$tmpDirectoryStr$settings{OutputFileName} |
---|
845 |
|
---|
846 |
Note: This script relies on Perl Modules: Video::Frequencies, Video::ivtv, |
---|
847 |
Config::IniFiles and Getopt::Long. |
---|
848 |
END_OF_USAGE |
---|
849 |
|
---|
850 |
# handle user input here |
---|
851 |
my %opts; |
---|
852 |
#getopts('c:t:o:hd:W:H:s:T:D:vi:I:f:F:LRb:B:P:S', \%opts); |
---|
853 |
GetOptions(\%opts, "channel|c=s", "duration|t=i", "output|o=s", "help|h", "input|d=s", "width|W=i", "height|H=i", "standard|s=s", |
---|
854 |
"type|T=s", "directory|D=s", "version|v", "inputnum|i=i", "inputname|I=s", "freqtable|f=s", "frequency|F=i", "list-freqtable|L", |
---|
855 |
"noreset|R", "bitrate|b=i", "peakbitrate|B=i", "profile|P=s@", "save|S", "aspect=i", "audio-bitmask=s", "bframes=i", "dnrmode=i", "dnrspatial=i", |
---|
856 |
"dnrtemporal=i", "dnrtype=i", "framerate=i", "framespergop=i", "gopclosure=i", "pulldown=i", |
---|
857 |
"streamtype=i", "no-record", "directory-format=s", "date-format=s", "debug", "list-channels", |
---|
858 |
"tuner-num=i", "list-inputs", "list-standards", "set-msp-matrix=i", "msp-input=i", "msp-output=i", "outputmpgfilename=s"); |
---|
859 |
if (scalar keys %opts == 0 && @ARGV == 0) |
---|
860 |
{ |
---|
861 |
usage(0, ""); |
---|
862 |
} |
---|
863 |
foreach my $option (sort keys %opts) |
---|
864 |
{ |
---|
865 |
my $found = 0; |
---|
866 |
foreach my $mapName (keys %mappings) |
---|
867 |
{ |
---|
868 |
if ($option =~ /^($mappings{$mapName})$/) |
---|
869 |
{ |
---|
870 |
$settings{$mapName} = $opts{$option}; |
---|
871 |
$found = 1; |
---|
872 |
print "$mapName = '$opts{$option}'\n" if $settings{Debug}; |
---|
873 |
} |
---|
874 |
} |
---|
875 |
if (!$found) |
---|
876 |
{ |
---|
877 |
# handle the non-settings cases. |
---|
878 |
if ($option =~ /^(L|list-freqtable)$/) |
---|
879 |
{ |
---|
880 |
my $errStr = "\nAvailable Frequency Mappings:\n"; |
---|
881 |
foreach my $name (sort keys %CHANLIST) |
---|
882 |
{ |
---|
883 |
$errStr .= "$name\n"; |
---|
884 |
} |
---|
885 |
print "$versionStr\n$errStr"; |
---|
886 |
exit 0; |
---|
887 |
} |
---|
888 |
elsif ($option eq "list-channels") |
---|
889 |
{ |
---|
890 |
my $errStr = "\nAvailable Channels for $settings{FrequencyTable}:\n"; |
---|
891 |
foreach my $name (sort { $a <=> $b } keys %{$CHANLIST{$settings{FrequencyTable}}}) |
---|
892 |
{ |
---|
893 |
$errStr .= "$name\t= $CHANLIST{$settings{FrequencyTable}}->{$name}\n"; |
---|
894 |
} |
---|
895 |
print "$versionStr\n$errStr"; |
---|
896 |
exit 0; |
---|
897 |
} |
---|
898 |
elsif ($option =~ /^(no-record)$/) |
---|
899 |
{ |
---|
900 |
$settings{DontRecord} = 1; |
---|
901 |
} |
---|
902 |
elsif ($option =~ /^(S|save)$/) |
---|
903 |
{ |
---|
904 |
$settings{UpdateConfigFile} = 1; |
---|
905 |
} |
---|
906 |
elsif ($option =~ /^(P|profile)$/) |
---|
907 |
{ |
---|
908 |
@profileNames = @{$opts{$option}}; |
---|
909 |
} |
---|
910 |
elsif ($option =~ /^(v|version)$/) |
---|
911 |
{ |
---|
912 |
print "$versionStr\n"; |
---|
913 |
exit 0; |
---|
914 |
} |
---|
915 |
elsif ($option =~ /^(h|help)$/) |
---|
916 |
{ |
---|
917 |
usage(0, ""); |
---|
918 |
} |
---|
919 |
elsif ($option =~ /^(list-inputs|list-standards)$/) |
---|
920 |
{ |
---|
921 |
# do nothing for now since they will be handled later. |
---|
922 |
} |
---|
923 |
|
---|
924 |
else |
---|
925 |
{ |
---|
926 |
usage(1, "-$option is an unknown option!"); |
---|
927 |
} |
---|
928 |
} |
---|
929 |
} |
---|
930 |
|
---|
931 |
if (@profileNames) |
---|
932 |
{ |
---|
933 |
# loop over all profiles the user specified. |
---|
934 |
foreach my $profileName (@profileNames) |
---|
935 |
{ |
---|
936 |
print "profile = '$profileName'\n" if $settings{Debug}; |
---|
937 |
# for now the profile can not be "defaults". |
---|
938 |
if ($profileName eq "defaults") |
---|
939 |
{ |
---|
940 |
error(1, "Profile = '$profileName' is invalid!"); |
---|
941 |
} |
---|
942 |
if (exists $configIni{$profileName}) |
---|
943 |
{ |
---|
944 |
# update defaults/override command line arguments that exist in this profile. |
---|
945 |
my $profileUpdating = (((exists $opts{S} || exists $opts{save}) && @profileNames == 1) ? 1 : 0); |
---|
946 |
my $profile = $profileName; |
---|
947 |
|
---|
948 |
foreach my $arg (keys %mappings) |
---|
949 |
{ |
---|
950 |
foreach my $option (split(/\|/, $mappings{$arg})) # handle the long/short command option versions |
---|
951 |
{ |
---|
952 |
#print "arg = '$arg', option = '$option'\n" if $settings{Debug}; |
---|
953 |
if (exists $configIni{$profile}{$arg} && !($profileUpdating && exists $opts{$option})) |
---|
954 |
{ |
---|
955 |
$settings{$arg} = $configIni{$profile}{$arg}; |
---|
956 |
print "settings{$arg} = '" . $settings{$arg} . "'\n" if $settings{Debug}; |
---|
957 |
last; |
---|
958 |
} |
---|
959 |
} |
---|
960 |
} |
---|
961 |
} |
---|
962 |
else |
---|
963 |
{ |
---|
964 |
if ($settings{UpdateConfigFile} && @profileNames == 1) |
---|
965 |
{ |
---|
966 |
print "Warning: Profile = '$profileName' will be created.\n" if ($settings{Debug}); |
---|
967 |
} |
---|
968 |
else |
---|
969 |
{ |
---|
970 |
error(1, "Profile = '$profileName' does not exist! You must specify -S/--save to create it."); |
---|
971 |
} |
---|
972 |
} |
---|
973 |
} |
---|
974 |
} |
---|
975 |
|
---|
976 |
# verify input |
---|
977 |
|
---|
978 |
if (@ARGV) |
---|
979 |
{ |
---|
980 |
if (exists $opts{c} || exists $opts{channel}) |
---|
981 |
{ |
---|
982 |
print "Warning: ignoring channel argument and using '$ARGV[0]' instead.\n"; |
---|
983 |
} |
---|
984 |
$settings{Channel} = $ARGV[0]; |
---|
985 |
} |
---|
986 |
|
---|
987 |
if (!$settings{DontRecord}) |
---|
988 |
{ |
---|
989 |
print "RecordDuration = $settings{RecordDuration}\n" if $settings{Debug}; |
---|
990 |
|
---|
991 |
if ($settings{VideoType} !~ /^(mpeg|yuv)$/) |
---|
992 |
{ |
---|
993 |
error(1, "Video Type = '$settings{VideoType}' is invalid!"); |
---|
994 |
} |
---|
995 |
if ($settings{VideoType} eq "yuv") |
---|
996 |
{ |
---|
997 |
# see if we need to change our defaults. |
---|
998 |
if (!exists $opts{o} && !exists $opts{output}) |
---|
999 |
{ |
---|
1000 |
$settings{OutputFileName} = "video.yuv"; |
---|
1001 |
} |
---|
1002 |
if (!exists $opts{d} && !exists $opts{input}) |
---|
1003 |
{ |
---|
1004 |
if ( -e "/dev/.devfsd" ) |
---|
1005 |
{ |
---|
1006 |
$settings{VideoDevice} = "/dev/v4l/yuv0"; |
---|
1007 |
} |
---|
1008 |
else |
---|
1009 |
{ |
---|
1010 |
$settings{VideoDevice} = "/dev/yuv0"; |
---|
1011 |
} |
---|
1012 |
} |
---|
1013 |
} |
---|
1014 |
} |
---|
1015 |
|
---|
1016 |
if ( ! -c "$settings{VideoDevice}") |
---|
1017 |
{ |
---|
1018 |
error(1, "Video Dev = '$settings{VideoDevice}' is invalid! $!"); |
---|
1019 |
} |
---|
1020 |
|
---|
1021 |
# now that the video device has been semi validated, we can use it to lookup |
---|
1022 |
# the inputs, standards, etc. and use that for validating some of the following |
---|
1023 |
# pieces of user input. |
---|
1024 |
sysopen($tuner, $settings{VideoDevice}, O_RDWR) or die "Error unable to open '$settings{VideoDevice}': $!"; |
---|
1025 |
my $tunerFD = fileno($tuner); |
---|
1026 |
|
---|
1027 |
# get the current capabilities. |
---|
1028 |
@capabilities = $ivtvObj->getCapabilities($tunerFD); |
---|
1029 |
if (@capabilities != keys %{$ivtvObj->{capIndexes}}) |
---|
1030 |
{ |
---|
1031 |
error(1, "getCapabilities() failed!"); |
---|
1032 |
} |
---|
1033 |
if ($capabilities[$ivtvObj->{capIndexes}{driver}] ne "ivtv") |
---|
1034 |
{ |
---|
1035 |
$settings{UsingIvtvDriver} = 0; # we can't use the ivtv "enhancements". |
---|
1036 |
print "Warning: V4l2 driver = '$capabilities[$ivtvObj->{capIndexes}{driver}]' does not support the ivtv \"enhancements\"!\n"; |
---|
1037 |
print " All codec related options will be ignored.\n\n"; |
---|
1038 |
} |
---|
1039 |
|
---|
1040 |
my $i; |
---|
1041 |
|
---|
1042 |
|
---|
1043 |
$std = $ivtvObj->getStandard($tunerFD); |
---|
1044 |
if ($std > 0) |
---|
1045 |
{ |
---|
1046 |
printf("Standard: 0x%08x\n",$std) if ($settings{Debug}); |
---|
1047 |
} |
---|
1048 |
else |
---|
1049 |
{ |
---|
1050 |
die "Error: getStandard() failed!\n"; |
---|
1051 |
} |
---|
1052 |
|
---|
1053 |
|
---|
1054 |
$curinput = $ivtvObj->getInput($tunerFD); |
---|
1055 |
if ($curinput < 0) |
---|
1056 |
{ |
---|
1057 |
die "Error: getInput() failed!\n"; |
---|
1058 |
} |
---|
1059 |
printf("Input: 0x%08x\n",$curinput) if ($settings{Debug}); |
---|
1060 |
|
---|
1061 |
my $done=0; |
---|
1062 |
|
---|
1063 |
for ($i=0; !$done; ++$i) |
---|
1064 |
{ |
---|
1065 |
my($index,$std_id,$name,$frameperiod_n,$frameperiod_d,$framelines) = $ivtvObj->enumerateStandard($tunerFD, $i); |
---|
1066 |
if ($index == -1) |
---|
1067 |
{ |
---|
1068 |
$done = 1; |
---|
1069 |
} |
---|
1070 |
else |
---|
1071 |
{ |
---|
1072 |
printf("%d 0x%08x %s %d/%d %d\n",$index,$std_id,$name,$frameperiod_n,$frameperiod_d,$framelines) if ($settings{Debug}); |
---|
1073 |
push @standards, [($name,$std_id)]; |
---|
1074 |
$name2std{$name} = $std_id; |
---|
1075 |
if( (($std_id & $std) == $std)) |
---|
1076 |
{ |
---|
1077 |
$curstd = $name; |
---|
1078 |
$curStandard = $std; |
---|
1079 |
} |
---|
1080 |
} |
---|
1081 |
} |
---|
1082 |
|
---|
1083 |
if (exists $opts{'list-standards'}) |
---|
1084 |
{ |
---|
1085 |
print "$versionStr\n"; |
---|
1086 |
print "Available Video Standards:\n"; |
---|
1087 |
foreach my $standard (@standards) |
---|
1088 |
{ |
---|
1089 |
print "$standard->[0]\n"; |
---|
1090 |
} |
---|
1091 |
exit 0; |
---|
1092 |
} |
---|
1093 |
|
---|
1094 |
$done=0; |
---|
1095 |
|
---|
1096 |
for ($i=0; !$done; ++$i) |
---|
1097 |
{ |
---|
1098 |
my($index,$name,$type,$audioset,$tuner,$std,$status) = $ivtvObj->enumerateInput($tunerFD, $i); |
---|
1099 |
if ($index == -1) |
---|
1100 |
{ |
---|
1101 |
$done = 1; |
---|
1102 |
} |
---|
1103 |
else |
---|
1104 |
{ |
---|
1105 |
push @inputs, $name; |
---|
1106 |
$name2input{$name} = $index; |
---|
1107 |
} |
---|
1108 |
} |
---|
1109 |
$curinputName = $inputs[$curinput]; |
---|
1110 |
|
---|
1111 |
if (exists $opts{'list-inputs'}) |
---|
1112 |
{ |
---|
1113 |
print "$versionStr\n"; |
---|
1114 |
print "Available Inputs:\n"; |
---|
1115 |
my $counter = 0; |
---|
1116 |
foreach my $input (@inputs) |
---|
1117 |
{ |
---|
1118 |
print "$counter: $input\n"; |
---|
1119 |
$counter++; |
---|
1120 |
} |
---|
1121 |
exit 0; |
---|
1122 |
} |
---|
1123 |
|
---|
1124 |
if ($settings{UsingIvtvDriver}) |
---|
1125 |
{ |
---|
1126 |
|
---|
1127 |
@codecInfo = $ivtvObj->getCodecInfo($tunerFD); |
---|
1128 |
if (@codecInfo != keys %{$ivtvObj->{codecIndexes}}) |
---|
1129 |
{ |
---|
1130 |
error(1, "getCodecInfo() failed!"); |
---|
1131 |
} |
---|
1132 |
@newCodecInfo = $ivtvObj->getCodecInfo($tunerFD); |
---|
1133 |
if (@newCodecInfo != keys %{$ivtvObj->{codecIndexes}}) |
---|
1134 |
{ |
---|
1135 |
error(1, "getCodecInfo() failed!"); |
---|
1136 |
} |
---|
1137 |
} |
---|
1138 |
|
---|
1139 |
|
---|
1140 |
|
---|
1141 |
if (!$settings{DontRecord}) |
---|
1142 |
{ |
---|
1143 |
if ($settings{RecordDuration} !~ /^(\d+)$/) |
---|
1144 |
{ |
---|
1145 |
error(1, "Time = '$settings{RecordDuration}' is invalid!"); |
---|
1146 |
} |
---|
1147 |
|
---|
1148 |
if ( ! -d "$settings{OutputDirectory}") |
---|
1149 |
{ |
---|
1150 |
error(1, "Directory = '$settings{OutputDirectory}' is invalid! $!"); |
---|
1151 |
} |
---|
1152 |
|
---|
1153 |
|
---|
1154 |
|
---|
1155 |
|
---|
1156 |
|
---|
1157 |
|
---|
1158 |
|
---|
1159 |
if ($settings{DateTimeFormatString} !~ /^(\+((\%.)|.)+)$/) |
---|
1160 |
{ |
---|
1161 |
usage(1, "Date Format String = '$settings{DateTimeFormatString}' is invalid!"); |
---|
1162 |
} |
---|
1163 |
} |
---|
1164 |
|
---|
1165 |
if ($settings{VideoWidth} !~ /^(\d+)$/) |
---|
1166 |
{ |
---|
1167 |
error(1, "Width = '$settings{VideoWidth}' is invalid!"); |
---|
1168 |
} |
---|
1169 |
|
---|
1170 |
if ($settings{VideoHeight} !~ /^(\d+)$/) |
---|
1171 |
{ |
---|
1172 |
error(1, "Height = '$settings{VideoHeight}' is invalid!"); |
---|
1173 |
} |
---|
1174 |
|
---|
1175 |
if (!exists $name2std{$settings{VideoStandard}}) |
---|
1176 |
{ |
---|
1177 |
my $validStandards = join(", ", keys(%name2std)); |
---|
1178 |
error(1, "Video Standard = '$settings{VideoStandard}' is invalid!\nValid Standards are: $validStandards"); |
---|
1179 |
} |
---|
1180 |
|
---|
1181 |
if (exists $opts{i} || exists $opts{inputnum}) |
---|
1182 |
{ |
---|
1183 |
if ($settings{InputNum} < 0 || $settings{InputNum} >= scalar(@inputs)) |
---|
1184 |
{ |
---|
1185 |
error(1, "Video Input = '$settings{InputNum}' is invalid!\nValid Inputs are from 0 - " . int(scalar(@inputs) - 1)); |
---|
1186 |
} |
---|
1187 |
$settings{InputName} = $inputs[$settings{InputNum}]; |
---|
1188 |
} |
---|
1189 |
|
---|
1190 |
if ((exists $opts{I} || exists $opts{inputname}) && !(exists $opts{i} || exists $opts{inputnum})) |
---|
1191 |
{ |
---|
1192 |
if (!exists $name2input{$settings{InputName}}) |
---|
1193 |
{ |
---|
1194 |
my $validInputs = join(", ", @inputs); |
---|
1195 |
error(1, "Video Input Name = '$settings{InputName}' is invalid!\nValid Input Names are: $validInputs"); |
---|
1196 |
} |
---|
1197 |
$settings{InputNum} = $name2input{$settings{InputName}}; |
---|
1198 |
} |
---|
1199 |
|
---|
1200 |
if (!exists $CHANLIST{$settings{FrequencyTable}}) |
---|
1201 |
{ |
---|
1202 |
error(1, "Frequency Table = '$settings{FrequencyTable}' is invalid!"); |
---|
1203 |
} |
---|
1204 |
|
---|
1205 |
|
---|
1206 |
if ($inputs[$settings{InputNum}] =~ /Tuner/) |
---|
1207 |
{ |
---|
1208 |
if ($settings{TunerNum} !~ /^(\d)$/) |
---|
1209 |
{ |
---|
1210 |
error(1, "TunerNum = '$settings{TunerNum}' is invalid!"); |
---|
1211 |
} |
---|
1212 |
if (exists $opts{F} || exists $opts{frequency} || $settings{Frequency}) |
---|
1213 |
{ |
---|
1214 |
if ($settings{Frequency} !~ /^(\d+)$/) |
---|
1215 |
{ |
---|
1216 |
error(1, "Frequency = '$settings{Frequency}' is invalid!"); |
---|
1217 |
} |
---|
1218 |
$settings{Channel} = "freq-$settings{Frequency}"; |
---|
1219 |
} |
---|
1220 |
|
---|
1221 |
else |
---|
1222 |
{ |
---|
1223 |
if (!$settings{Channel}) |
---|
1224 |
{ |
---|
1225 |
error(1, "channel = '$settings{Channel}' is invalid!"); |
---|
1226 |
} |
---|
1227 |
|
---|
1228 |
|
---|
1229 |
if ($settings{FrequencyTable} !~ /^(custom|$settings{VideoStandard})/i) |
---|
1230 |
{ |
---|
1231 |
error(1, "You specified Video Standard '$settings{VideoStandard}' which is incompatible with Frequency Table '$settings{FrequencyTable}'!"); |
---|
1232 |
} |
---|
1233 |
if (!exists $CHANLIST{$settings{FrequencyTable}}->{$settings{Channel}}) |
---|
1234 |
{ |
---|
1235 |
error(1, "Channel = '$settings{Channel}' does not exist in Frequency Table '$settings{FrequencyTable}'!"); |
---|
1236 |
} |
---|
1237 |
} |
---|
1238 |
|
---|
1239 |
|
---|
1240 |
my $Frequency; |
---|
1241 |
if(($Frequency = $ivtvObj->getFrequency($tunerFD, $settings{TunerNum})) >= 0) |
---|
1242 |
{ |
---|
1243 |
my $freq = ($Frequency * 1000) / 16; |
---|
1244 |
print "freq = $freq\n" if ($settings{Debug}); |
---|
1245 |
|
---|
1246 |
if ((!exists $opts{F} && !exists $opts{frequency} && !$settings{Frequency}) && ($curstd eq $settings{VideoStandard}) ) |
---|
1247 |
{ |
---|
1248 |
foreach my $chan (keys %{$CHANLIST{$settings{FrequencyTable}}}) |
---|
1249 |
{ |
---|
1250 |
if ($CHANLIST{$settings{FrequencyTable}}->{$chan} == $freq) |
---|
1251 |
{ |
---|
1252 |
$curChannel = $chan; |
---|
1253 |
} |
---|
1254 |
} |
---|
1255 |
print "curChannel = $curChannel\n" if ($settings{Debug}); |
---|
1256 |
} |
---|
1257 |
else |
---|
1258 |
{ |
---|
1259 |
$curFrequency = $freq; |
---|
1260 |
} |
---|
1261 |
} |
---|
1262 |
else |
---|
1263 |
{ |
---|
1264 |
die "Error: getFrequency() failed!\n"; |
---|
1265 |
} |
---|
1266 |
} |
---|
1267 |
else |
---|
1268 |
{ |
---|
1269 |
|
---|
1270 |
$settings{Channel} = ""; |
---|
1271 |
} |
---|
1272 |
|
---|
1273 |
if ($settings{UsingIvtvDriver}) |
---|
1274 |
{ |
---|
1275 |
|
---|
1276 |
if ($settings{Bitrate} < $settings{minBitrate} || $settings{Bitrate} > $settings{maxBitrate}) |
---|
1277 |
{ |
---|
1278 |
error(1, "Bitrate = '$settings{Bitrate}' is invalid!"); |
---|
1279 |
} |
---|
1280 |
if ($settings{PeakBitrate} <= $settings{Bitrate}) |
---|
1281 |
{ |
---|
1282 |
error(1, "PeakBitrate can not be less than or equal to Bitrate!"); |
---|
1283 |
} |
---|
1284 |
elsif ($settings{PeakBitrate} < $settings{minPeakBitrate} || $settings{PeakBitrate} > $settings{maxPeakBitrate}) |
---|
1285 |
{ |
---|
1286 |
error(1, "PeakBitrate = '$settings{PeakBitrate}' is invalid!"); |
---|
1287 |
} |
---|
1288 |
|
---|
1289 |
if ($settings{VideoStandard} !~ /^(NTSC)/) |
---|
1290 |
{ |
---|
1291 |
my $warn = 0; |
---|
1292 |
if ($settings{Framerate} == 0) |
---|
1293 |
{ |
---|
1294 |
$settings{Framerate} = 1; |
---|
1295 |
$warn = 1; |
---|
1296 |
} |
---|
1297 |
if ($settings{FramesPerGOP} == 15) |
---|
1298 |
{ |
---|
1299 |
$settings{FramesPerGOP} = 12; |
---|
1300 |
$warn = 1; |
---|
1301 |
} |
---|
1302 |
if ($warn) |
---|
1303 |
{ |
---|
1304 |
print "Warning: Setting Framerate/FramesPerGOP to PAL settings for Video Standard '$settings{VideoStandard}'!\n\nYou should either specify on the command line or in the ~/.ivtvrc config file.\n"; |
---|
1305 |
} |
---|
1306 |
} |
---|
1307 |
elsif ($settings{VideoStandard} =~ /^(NTSC)/) |
---|
1308 |
{ |
---|
1309 |
my $warn = 0; |
---|
1310 |
if ($settings{Framerate} == 1) |
---|
1311 |
{ |
---|
1312 |
$settings{Framerate} = 0; |
---|
1313 |
$warn = 1; |
---|
1314 |
} |
---|
1315 |
if ($settings{FramesPerGOP} == 12) |
---|
1316 |
{ |
---|
1317 |
$settings{FramesPerGOP} = 15; |
---|
1318 |
$warn = 1; |
---|
1319 |
} |
---|
1320 |
if ($warn) |
---|
1321 |
{ |
---|
1322 |
print "Warning: Setting Framerate/FramesPerGOP to NTSC settings for Video Standard '$settings{VideoStandard}'!\n\nYou should either specify on the command line or in the ~/.ivtvrc config file.\n"; |
---|
1323 |
} |
---|
1324 |
} |
---|
1325 |
|
---|
1326 |
if ($settings{SetMSPMatrix} !~ /^(0|1)$/) |
---|
1327 |
{ |
---|
1328 |
error(1, "SetMSPMatrix = '$settings{SetMSPMatrix}' is invalid! It can only be 0 or 1."); |
---|
1329 |
} |
---|
1330 |
if ($settings{MSPInput} < 1 || $settings{MSPInput} > 8) |
---|
1331 |
{ |
---|
1332 |
error(1, "MSPInput = '$settings{MSPInput}' is invalid! It can only be 1 - 8."); |
---|
1333 |
} |
---|
1334 |
if ($settings{MSPOutput} < 0 || $settings{MSPOutput} > 3) |
---|
1335 |
{ |
---|
1336 |
error(1, "MSPOutput = '$settings{MSPOutput}' is invalid! It can only be 0 - 3."); |
---|
1337 |
} |
---|
1338 |
} |
---|
1339 |
|
---|
1340 |
|
---|
1341 |
if ($settings{UpdateConfigFile}) |
---|
1342 |
{ |
---|
1343 |
my $profile; |
---|
1344 |
if (@profileNames > 1) |
---|
1345 |
{ |
---|
1346 |
print "Warning: Not updating config file as you have more than 1 profile specified!\n"; |
---|
1347 |
} |
---|
1348 |
elsif (@profileNames == 1) |
---|
1349 |
{ |
---|
1350 |
$profile = $profileNames[0]; |
---|
1351 |
} |
---|
1352 |
else |
---|
1353 |
{ |
---|
1354 |
$profile = "defaults"; |
---|
1355 |
} |
---|
1356 |
if ($profile) |
---|
1357 |
{ |
---|
1358 |
my $createProfile = (exists $configIni{$profile} ? 0 : 1); |
---|
1359 |
print "Creating Profile = '$profile': $createProfile\n" if ($settings{Debug}); |
---|
1360 |
|
---|
1361 |
if (!$settings{UseConfigFile}) |
---|
1362 |
{ |
---|
1363 |
|
---|
1364 |
tie %configIni, 'Config::IniFiles', () or die "Error: Initializing config file '$settings{ConfigFileName}' failed! $!\n"; |
---|
1365 |
|
---|
1366 |
|
---|
1367 |
tied(%configIni)->SetFileName($settings{ConfigFileName}) or die "Error: Setting config file to '$settings{ConfigFileName}' failed! $!\n"; |
---|
1368 |
|
---|
1369 |
$configIni{$profile} = {}; |
---|
1370 |
} |
---|
1371 |
|
---|
1372 |
foreach my $arg (keys %mappings) |
---|
1373 |
{ |
---|
1374 |
foreach my $option (split(/\|/, $mappings{$arg})) |
---|
1375 |
{ |
---|
1376 |
if (exists $configIni{$profile}{$arg} || $createProfile || exists $opts{$option}) |
---|
1377 |
{ |
---|
1378 |
$configIni{$profile}{$arg} = $settings{$arg}; |
---|
1379 |
print "configIni{$profile}{$arg} = '" . $settings{$arg} . "'\n" if $settings{Debug}; |
---|
1380 |
last; |
---|
1381 |
} |
---|
1382 |
} |
---|
1383 |
} |
---|
1384 |
|
---|
1385 |
|
---|
1386 |
tied(%configIni)->RewriteConfig or die "Error: Writing config file '$settings{ConfigFileName}' failed! $!\n"; |
---|
1387 |
} |
---|
1388 |
} |
---|
1389 |
|
---|
1390 |
|
---|
1391 |
my %changedSettings = ( |
---|
1392 |
resolution => 0, |
---|
1393 |
standard => 0, |
---|
1394 |
VideoType => 0, |
---|
1395 |
InputNum => 0, |
---|
1396 |
Channel => 0, |
---|
1397 |
Frequency => 0, |
---|
1398 |
codec => 0, |
---|
1399 |
); |
---|
1400 |
|
---|
1401 |
my $directoryName; |
---|
1402 |
if (!$settings{DontRecord}) |
---|
1403 |
{ |
---|
1404 |
|
---|
1405 |
|
---|
1406 |
|
---|
1407 |
$directoryName = $settings{DirectoryFormatString}; |
---|
1408 |
} |
---|
1409 |
|
---|
1410 |
|
---|
1411 |
if ($inputs[$settings{InputNum}] =~ /Tuner/) |
---|
1412 |
{ |
---|
1413 |
if (exists $opts{F} || exists $opts{frequency} || $settings{Frequency}) |
---|
1414 |
{ |
---|
1415 |
if ($settings{Frequency} != $curFrequency) |
---|
1416 |
{ |
---|
1417 |
$changedSettings{Frequency} = 1; |
---|
1418 |
tuneFrequency($settings{Frequency}); |
---|
1419 |
} |
---|
1420 |
} |
---|
1421 |
else |
---|
1422 |
{ |
---|
1423 |
if ($curstd ne $settings{VideoStandard}) |
---|
1424 |
{ |
---|
1425 |
|
---|
1426 |
|
---|
1427 |
$changedSettings{Frequency} = 1; |
---|
1428 |
changeChannel($settings{Channel}); |
---|
1429 |
} |
---|
1430 |
elsif ($settings{Channel} ne $curChannel) |
---|
1431 |
{ |
---|
1432 |
|
---|
1433 |
$changedSettings{Channel} = 1; |
---|
1434 |
changeChannel($settings{Channel}); |
---|
1435 |
} |
---|
1436 |
} |
---|
1437 |
} |
---|
1438 |
|
---|
1439 |
|
---|
1440 |
if ($settings{VideoStandard} ne $curstd) |
---|
1441 |
{ |
---|
1442 |
$changedSettings{standard} = 1; |
---|
1443 |
change_standard(); |
---|
1444 |
|
---|
1445 |
|
---|
1446 |
if ($settings{UsingIvtvDriver}) |
---|
1447 |
{ |
---|
1448 |
if ($settings{SetMSPMatrix}) |
---|
1449 |
{ |
---|
1450 |
print "Setting msp matrix: input = $settings{MSPInput}, output = $settings{MSPOutput}\n" if $settings{Debug}; |
---|
1451 |
sleep ($settings{MSPSleep}); |
---|
1452 |
$result = $ivtvObj->mspMatrixSet($tunerFD, $settings{MSPInput}, $settings{MSPOutput}); |
---|
1453 |
if (not defined $result) |
---|
1454 |
{ |
---|
1455 |
die "Error calling mspMatrixSet!\n"; |
---|
1456 |
} |
---|
1457 |
if (!$result) |
---|
1458 |
{ |
---|
1459 |
die "Error in mspMatrixSet ioctl call!\n"; |
---|
1460 |
} |
---|
1461 |
} |
---|
1462 |
} |
---|
1463 |
} |
---|
1464 |
|
---|
1465 |
|
---|
1466 |
if ($settings{InputNum} != $curinput || $settings{InputName} ne $curinputName) |
---|
1467 |
{ |
---|
1468 |
$changedSettings{InputNum} = 1; |
---|
1469 |
if (!(exists $opts{i} || exists $opts{inputnum} || exists $opts{I} || exists $opts{inputname})) |
---|
1470 |
{ |
---|
1471 |
|
---|
1472 |
&writelog("tvrecording: Changing input from $curinputName to $settings{InputName}"); |
---|
1473 |
} |
---|
1474 |
change_input(); |
---|
1475 |
} |
---|
1476 |
|
---|
1477 |
|
---|
1478 |
|
---|
1479 |
|
---|
1480 |
my ($oldWidth, $oldHeight) = $ivtvObj->getResolution($tunerFD); |
---|
1481 |
print "oldWidth = '$oldWidth', oldHeight = '$oldHeight'\n" if ($settings{Debug}); |
---|
1482 |
|
---|
1483 |
if ($settings{VideoWidth} != $oldWidth || $settings{VideoHeight} != $oldHeight) |
---|
1484 |
{ |
---|
1485 |
$changedSettings{resolution} = 1; |
---|
1486 |
} |
---|
1487 |
|
---|
1488 |
|
---|
1489 |
if ($changedSettings{resolution}) |
---|
1490 |
{ |
---|
1491 |
$result = $ivtvObj->setResolution($tunerFD, $settings{VideoWidth}, $settings{VideoHeight}); |
---|
1492 |
if (not defined $result) |
---|
1493 |
{ |
---|
1494 |
die "Error calling setResolution!\n"; |
---|
1495 |
} |
---|
1496 |
if (!$result) |
---|
1497 |
{ |
---|
1498 |
die "Error in setResolution ioctl call!\n"; |
---|
1499 |
} |
---|
1500 |
} |
---|
1501 |
|
---|
1502 |
if ($settings{UsingIvtvDriver}) |
---|
1503 |
{ |
---|
1504 |
|
---|
1505 |
foreach my $codecName (keys %codecMappings) |
---|
1506 |
{ |
---|
1507 |
my $codecIndex = $ivtvObj->{codecIndexes}{$codecMappings{$codecName}}; |
---|
1508 |
if ($codecInfo[$codecIndex] != $settings{$codecName}) |
---|
1509 |
{ |
---|
1510 |
$changedSettings{codec} = 1; |
---|
1511 |
$newCodecInfo[$codecIndex] = $settings{$codecName}; |
---|
1512 |
print "new $codecName = '$settings{$codecName}', old $codecName = '$codecInfo[$codecIndex]'\n" if $settings{Debug}; |
---|
1513 |
} |
---|
1514 |
} |
---|
1515 |
} |
---|
1516 |
|
---|
1517 |
if ($changedSettings{codec}) |
---|
1518 |
{ |
---|
1519 |
$result = $ivtvObj->setCodecInfo($tunerFD, @newCodecInfo); |
---|
1520 |
if (!$result) |
---|
1521 |
{ |
---|
1522 |
die "Error calling setCodecInfo()!\n"; |
---|
1523 |
} |
---|
1524 |
} |
---|
1525 |
|
---|
1526 |
if (!$settings{DontRecord}) |
---|
1527 |
{ |
---|
1528 |
|
---|
1529 |
|
---|
1530 |
|
---|
1531 |
captureVideo(directoryName => $directoryName, RecordDuration => $settings{RecordDuration}, |
---|
1532 |
OutputFileName => $settings{OutputFileName}, tuner => $tuner ,OutputMPGFileName => $settings{OutputMPGFileName}); |
---|
1533 |
} |
---|
1534 |
|
---|
1535 |
if ($settings{ResetCardSettings} && !$settings{DontRecord}) |
---|
1536 |
{ |
---|
1537 |
|
---|
1538 |
if ($changedSettings{codec}) |
---|
1539 |
{ |
---|
1540 |
$result = $ivtvObj->setCodecInfo($tunerFD, @codecInfo); |
---|
1541 |
if (!$result) |
---|
1542 |
{ |
---|
1543 |
die "Error calling setCodecInfo()!\n"; |
---|
1544 |
} |
---|
1545 |
} |
---|
1546 |
|
---|
1547 |
|
---|
1548 |
if ($changedSettings{resolution}) |
---|
1549 |
{ |
---|
1550 |
$result = $ivtvObj->setResolution($tunerFD, $oldWidth, $oldHeight); |
---|
1551 |
if (not defined $result) |
---|
1552 |
{ |
---|
1553 |
die "Error calling setResolution!\n"; |
---|
1554 |
} |
---|
1555 |
if (!$result) |
---|
1556 |
{ |
---|
1557 |
die "Error in setResolution ioctl call!\n"; |
---|
1558 |
} |
---|
1559 |
} |
---|
1560 |
|
---|
1561 |
|
---|
1562 |
if ($changedSettings{InputNum}) |
---|
1563 |
{ |
---|
1564 |
|
---|
1565 |
$settings{InputName} = $curinputName; |
---|
1566 |
change_input(); |
---|
1567 |
} |
---|
1568 |
|
---|
1569 |
|
---|
1570 |
if ($changedSettings{standard}) |
---|
1571 |
{ |
---|
1572 |
$settings{VideoStandard} = $curstd; |
---|
1573 |
change_standard(); |
---|
1574 |
|
---|
1575 |
|
---|
1576 |
if ($settings{UsingIvtvDriver}) |
---|
1577 |
{ |
---|
1578 |
if ($settings{SetMSPMatrix}) |
---|
1579 |
{ |
---|
1580 |
print "Setting msp matrix: input = $settings{MSPInput}, output = $settings{MSPOutput}\n" if $settings{Debug}; |
---|
1581 |
sleep ($settings{MSPSleep}); |
---|
1582 |
$result = $ivtvObj->mspMatrixSet($tunerFD, $settings{MSPInput}, $settings{MSPOutput}); |
---|
1583 |
if (not defined $result) |
---|
1584 |
{ |
---|
1585 |
die "Error calling mspMatrixSet!\n"; |
---|
1586 |
} |
---|
1587 |
if (!$result) |
---|
1588 |
{ |
---|
1589 |
die "Error in mspMatrixSet ioctl call!\n"; |
---|
1590 |
} |
---|
1591 |
} |
---|
1592 |
} |
---|
1593 |
} |
---|
1594 |
|
---|
1595 |
|
---|
1596 |
if ($changedSettings{Channel}) |
---|
1597 |
{ |
---|
1598 |
changeChannel($curChannel); |
---|
1599 |
} |
---|
1600 |
if ($changedSettings{Frequency}) |
---|
1601 |
{ |
---|
1602 |
tuneFrequency($curFrequency); |
---|
1603 |
} |
---|
1604 |
} |
---|
1605 |
|
---|
1606 |
|
---|
1607 |
close($tuner); |
---|
1608 |
|
---|
1609 |
|
---|
1610 |
exit 0; |
---|
1611 |
|
---|
1612 |
|
---|
1613 |
|
---|
1614 |
|
---|
1615 |
sub usage |
---|
1616 |
{ |
---|
1617 |
my $errorCode = shift; |
---|
1618 |
my $error = shift; |
---|
1619 |
|
---|
1620 |
print $usageStr; |
---|
1621 |
print "\nError: $error\n" if ($errorCode == 1); |
---|
1622 |
print "$error\n" if ($errorCode == 2); |
---|
1623 |
|
---|
1624 |
exit $errorCode; |
---|
1625 |
} |
---|
1626 |
|
---|
1627 |
|
---|
1628 |
|
---|
1629 |
|
---|
1630 |
sub error |
---|
1631 |
{ |
---|
1632 |
my $errorCode = shift; |
---|
1633 |
my $error = shift; |
---|
1634 |
|
---|
1635 |
print "$versionStr"; |
---|
1636 |
print "\nError: $error\n"; |
---|
1637 |
|
---|
1638 |
exit $errorCode; |
---|
1639 |
} |
---|
1640 |
|
---|
1641 |
|
---|
1642 |
sub change_input { |
---|
1643 |
my $preinput = $name2input{$settings{InputName}}; |
---|
1644 |
if($preinput != $curinput) |
---|
1645 |
{ |
---|
1646 |
$curinput = $preinput; |
---|
1647 |
print "input now $settings{InputName}, #$preinput\n" if ($settings{Debug}); |
---|
1648 |
my $result = $ivtvObj->setInput($tunerFD, $preinput); |
---|
1649 |
if (!$result) |
---|
1650 |
{ |
---|
1651 |
die "Error: setInput($preinput) failed!\n"; |
---|
1652 |
} |
---|
1653 |
} |
---|
1654 |
} |
---|
1655 |
|
---|
1656 |
|
---|
1657 |
sub change_standard { |
---|
1658 |
my $standard = $name2std{$settings{VideoStandard}}; |
---|
1659 |
if($standard != $curStandard) |
---|
1660 |
{ |
---|
1661 |
$curStandard = $standard; |
---|
1662 |
print "standard now $settings{VideoStandard}, #$standard\n" if ($settings{Debug}); |
---|
1663 |
my $result = $ivtvObj->setStandard($tunerFD, $standard); |
---|
1664 |
if (!$result) |
---|
1665 |
{ |
---|
1666 |
die "Error: setStandard($standard) failed!\n"; |
---|
1667 |
} |
---|
1668 |
} |
---|
1669 |
} |
---|
1670 |
|
---|
1671 |
|
---|
1672 |
|
---|
1673 |
sub changeChannel |
---|
1674 |
{ |
---|
1675 |
my $ch = shift; |
---|
1676 |
my $freq = $CHANLIST{$settings{FrequencyTable}}->{$ch}; |
---|
1677 |
my $driverf = ($freq * 16)/1000; |
---|
1678 |
|
---|
1679 |
print "Ch.$ch: $freq $driverf\n" if ($settings{Debug}); |
---|
1680 |
|
---|
1681 |
if (!$ivtvObj->setFrequency($tunerFD, $settings{TunerNum}, $driverf)) |
---|
1682 |
{ |
---|
1683 |
die "Error: changeChannel($ch) failed!\n"; |
---|
1684 |
} |
---|
1685 |
} |
---|
1686 |
|
---|
1687 |
|
---|
1688 |
|
---|
1689 |
sub tuneFrequency |
---|
1690 |
{ |
---|
1691 |
my $freq = shift; |
---|
1692 |
my $driverf = ($freq * 16)/1000; |
---|
1693 |
|
---|
1694 |
print "freq: $freq $driverf\n" if ($settings{Debug}); |
---|
1695 |
|
---|
1696 |
if (!$ivtvObj->setFrequency($tunerFD, $settings{TunerNum}, $driverf)) |
---|
1697 |
{ |
---|
1698 |
die "Error: tuneFrequency($freq) failed!\n"; |
---|
1699 |
} |
---|
1700 |
} |
---|
1701 |
|
---|
1702 |
my $done = 0; |
---|
1703 |
|
---|
1704 |
sub catch_alarm { |
---|
1705 |
$done = 1; |
---|
1706 |
} |
---|
1707 |
sub get_next_file_name |
---|
1708 |
{ |
---|
1709 |
|
---|
1710 |
my $file_name = shift(@_); |
---|
1711 |
$file_name =~ m/^(.+?)\-(\d{4})(\d{2})(\d{2})\-(\d{2})(\d{2})\-(\d{3})\.(.+?)$/; |
---|
1712 |
|
---|
1713 |
my $station = $1; |
---|
1714 |
my $year = $2; |
---|
1715 |
my $month = $3; |
---|
1716 |
my $day = $4; |
---|
1717 |
my $hour = $5; |
---|
1718 |
my $min = $6; |
---|
1719 |
my $seq = $7; |
---|
1720 |
my $ext = $8; |
---|
1721 |
$seq++; |
---|
1722 |
my $new_file_name = sprintf("%s-%04d%02d%02d-%02d%02d-%03d.%s", |
---|
1723 |
$station,$year,$month,$day,$hour,$min,$seq,$ext); |
---|
1724 |
return $new_file_name |
---|
1725 |
} |
---|
1726 |
|
---|
1727 |
|
---|
1728 |
|
---|
1729 |
sub captureVideo |
---|
1730 |
{ |
---|
1731 |
my %args = ( @_ ); |
---|
1732 |
my $directoryName = $args{directoryName}; |
---|
1733 |
my $RecordDuration = $args{RecordDuration}; |
---|
1734 |
my $OutputFileName = $args{OutputFileName}; |
---|
1735 |
my $tuner = $args{tuner}; |
---|
1736 |
my $fname = "$directoryName/$OutputFileName"; |
---|
1737 |
|
---|
1738 |
|
---|
1739 |
my $OutputFileName = $args{OutputFileName}; |
---|
1740 |
|
---|
1741 |
my $fname = $args{OutputFileName}; |
---|
1742 |
|
---|
1743 |
|
---|
1744 |
|
---|
1745 |
|
---|
1746 |
$SIG{ALRM} = \&catch_alarm; |
---|
1747 |
$SIG{INT} = \&catch_alarm; |
---|
1748 |
|
---|
1749 |
|
---|
1750 |
|
---|
1751 |
|
---|
1752 |
|
---|
1753 |
|
---|
1754 |
|
---|
1755 |
|
---|
1756 |
sysopen(OUTPUT, "$fname", O_CREAT | O_WRONLY | O_LARGEFILE) or die "Error creating file '$fname': $!\n"; |
---|
1757 |
|
---|
1758 |
alarm($RecordDuration); |
---|
1759 |
my $buf = ""; |
---|
1760 |
my $len = 0; |
---|
1761 |
while (!$done && read($tuner, $buf, 16384)) |
---|
1762 |
{ |
---|
1763 |
$len += length($buf); |
---|
1764 |
|
---|
1765 |
|
---|
1766 |
|
---|
1767 |
|
---|
1768 |
|
---|
1769 |
|
---|
1770 |
|
---|
1771 |
|
---|
1772 |
|
---|
1773 |
|
---|
1774 |
|
---|
1775 |
|
---|
1776 |
|
---|
1777 |
print OUTPUT $buf; |
---|
1778 |
} |
---|
1779 |
|
---|
1780 |
|
---|
1781 |
close(OUTPUT); |
---|
1782 |
|
---|
1783 |
|
---|
1784 |
} |
---|
1785 |
|
---|
1786 |
|
---|
1787 |
sub formatDirectoryString |
---|
1788 |
{ |
---|
1789 |
my $temp = $settings{DirectoryFormatString}; |
---|
1790 |
my $result = $settings{OutputDirectory}; |
---|
1791 |
my %lookupTable = ( |
---|
1792 |
"d" => `/bin/date "$settings{DateTimeFormatString}"`, |
---|
1793 |
"I" => $settings{InputName}, |
---|
1794 |
"c" => $settings{Channel}, |
---|
1795 |
); |
---|
1796 |
|
---|
1797 |
|
---|
1798 |
$lookupTable{I} =~ s/\s/_/g; |
---|
1799 |
|
---|
1800 |
chomp $lookupTable{d}; |
---|
1801 |
|
---|
1802 |
foreach my $option ("d", "I", "c") |
---|
1803 |
{ |
---|
1804 |
$temp =~ s/\%$option/$lookupTable{$option}/g; |
---|
1805 |
} |
---|
1806 |
|
---|
1807 |
$result .= "/" . ($temp ? "$temp/" : ""); |
---|
1808 |
|
---|
1809 |
return $result; |
---|
1810 |
} |
---|
1811 |
|
---|
1812 |
|
---|
1813 |
|
---|
1814 |
|
---|
1815 |
|
---|