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