| 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 |
$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 |
|
|---|
| 45 |
$startupsleeptime = 37; |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
require 'foltialib.pl'; |
|---|
| 51 |
|
|---|
| 52 |
&writelog("tvrecording: DEBUG $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] "); |
|---|
| 53 |
|
|---|
| 54 |
sub getChCallsign { |
|---|
| 55 |
if ($ARGV[5] ne ""){ |
|---|
| 56 |
$recchname = $ARGV[5] ; |
|---|
| 57 |
}else{ |
|---|
| 58 |
$recchname = $recch."ch"; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
sub getRecPath{ |
|---|
| 64 |
$recfolderpath = '/home/foltia/php/tv'; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
&prepare; |
|---|
| 70 |
|
|---|
| 71 |
$reclengthsec = &chkrecprocess(); |
|---|
| 72 |
&setbitrate; |
|---|
| 73 |
&chkextinput; |
|---|
| 74 |
|
|---|
| 75 |
$reclengthsec = $reclengthsec + $extendrecendsec ; |
|---|
| 76 |
|
|---|
| 77 |
&callrecordv4l; |
|---|
| 78 |
|
|---|
| 79 |
&writelog("tvrecording:$recch:$reclengthsec:$outputfile:$recdevice:$capturedeviceinputnum:$ivtvrecch:$stdbitrate:$peakbitrate"); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
sub chkextinput{ |
|---|
| 83 |
|
|---|
| 84 |
if ($recch == 0){ |
|---|
| 85 |
if ($svideoinputnum > -1 && $svideoinputnum < 30){ |
|---|
| 86 |
$capturedeviceinputnum = $svideoinputnum ; |
|---|
| 87 |
}else{ |
|---|
| 88 |
$capturedeviceinputnum = 7 ; |
|---|
| 89 |
} |
|---|
| 90 |
$capturedeviceinputName = "S-Video 1"; |
|---|
| 91 |
$ivtvrecch = ''; |
|---|
| 92 |
}elsif($recch == -1){ |
|---|
| 93 |
if ($comvideoinputnum > -1 && $comvideoinputnum < 30){ |
|---|
| 94 |
$capturedeviceinputnum = $comvideoinputnum; |
|---|
| 95 |
}else{ |
|---|
| 96 |
$capturedeviceinputnum = 8; |
|---|
| 97 |
} |
|---|
| 98 |
$capturedeviceinputName = "Composite 1"; |
|---|
| 99 |
$ivtvrecch = ''; |
|---|
| 100 |
}else{ |
|---|
| 101 |
if ($tunerinputnum > -1 && $tunerinputnum < 30){ |
|---|
| 102 |
$capturedeviceinputnum = $tunerinputnum ; |
|---|
| 103 |
}else{ |
|---|
| 104 |
$capturedeviceinputnum = 6 ; |
|---|
| 105 |
} |
|---|
| 106 |
$capturedeviceinputName = "Tuner 1"; |
|---|
| 107 |
$ivtvrecch = $recch; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
if($recch > 12){ |
|---|
| 111 |
if ($uhfbandtype == 1){ |
|---|
| 112 |
$frequencyTable = "ntsc-cable-jp"; |
|---|
| 113 |
}else{ |
|---|
| 114 |
$frequencyTable = "ntsc-bcast-jp"; |
|---|
| 115 |
} |
|---|
| 116 |
}else{ |
|---|
| 117 |
$frequencyTable = "ntsc-bcast-jp"; |
|---|
| 118 |
} |
|---|
| 119 |
&writelog ("tvrecording DEBUG $frequencyTable $recch"); |
|---|
| 120 |
|
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
sub chkrecprocessOLD{ |
|---|
| 126 |
|
|---|
| 127 |
my $mencoderkillcmd = ""; |
|---|
| 128 |
|
|---|
| 129 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp $recdevice`; |
|---|
| 130 |
$mencoderkillcmd =~ s/p//; |
|---|
| 131 |
|
|---|
| 132 |
if ($mencoderkillcmd != ""){ |
|---|
| 133 |
|
|---|
| 134 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
|---|
| 135 |
system ($mencoderkillcmd); |
|---|
| 136 |
chomp($mencoderkillcmd); |
|---|
| 137 |
&writelog ("tvrecording Killed current recording process. process:$mencoderkillcmd"); |
|---|
| 138 |
sleep(1); |
|---|
| 139 |
my $videodevice =`/usr/sbin/lsof $recdevice`; |
|---|
| 140 |
|
|---|
| 141 |
while ($videodevice =~ /tvrecording/){ |
|---|
| 142 |
|
|---|
| 143 |
$videodevice =`/usr/sbin/lsof $recdevice`; |
|---|
| 144 |
sleep(1); |
|---|
| 145 |
$sleepcounter++; |
|---|
| 146 |
$reclengthsec = $reclengthsec - $sleepcounter; |
|---|
| 147 |
&writelog ("tvrecording videodevice wait:$sleepcounter"); |
|---|
| 148 |
} |
|---|
| 149 |
$sleepcounter = 0; |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
return $reclengthsec; |
|---|
| 153 |
|
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 156 |
sub chkrecprocess{ |
|---|
| 157 |
my $mencoderkillcmd = ""; |
|---|
| 158 |
my $j = $recunits -1; |
|---|
| 159 |
my $i = 0; |
|---|
| 160 |
my $testrecdevice = ""; |
|---|
| 161 |
my @usedevices ; |
|---|
| 162 |
my @unusedevices; |
|---|
| 163 |
my $n = 0; |
|---|
| 164 |
$recdevice = ""; |
|---|
| 165 |
if ($ARGV[7] ne ""){ |
|---|
| 166 |
$recdevice = $ARGV[7] ; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
for ($i = 0 ;$i <= $j ; $i++){ |
|---|
| 171 |
|
|---|
| 172 |
$testrecdevice = "/dev/video$i"; |
|---|
| 173 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp $testrecdevice`; |
|---|
| 174 |
$mencoderkillcmd =~ s/p//; |
|---|
| 175 |
if ($mencoderkillcmd != ""){ |
|---|
| 176 |
push (@usedevices , $testrecdevice); |
|---|
| 177 |
&writelog ("tvrecording now using:$testrecdevice"); |
|---|
| 178 |
}else{ |
|---|
| 179 |
push (@unusedevices , $testrecdevice); |
|---|
| 180 |
&writelog ("tvrecording unused:$testrecdevice"); |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
$i = 0; |
|---|
| 185 |
$n = @unusedevices; |
|---|
| 186 |
|
|---|
| 187 |
if ($recdevice ne ""){ |
|---|
| 188 |
|
|---|
| 189 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp $recdevice`; |
|---|
| 190 |
$mencoderkillcmd =~ s/p//; |
|---|
| 191 |
if ($mencoderkillcmd != ""){ |
|---|
| 192 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
|---|
| 193 |
system ($mencoderkillcmd); |
|---|
| 194 |
chomp($mencoderkillcmd); |
|---|
| 195 |
&writelog ("tvrecording Killed current recording process. $recdevice:$mencoderkillcmd"); |
|---|
| 196 |
sleep(1); |
|---|
| 197 |
} |
|---|
| 198 |
}else{ |
|---|
| 199 |
|
|---|
| 200 |
if (($n == 0) and ($recch > 0)) { |
|---|
| 201 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp /dev/video$i`; |
|---|
| 202 |
$mencoderkillcmd =~ s/p//; |
|---|
| 203 |
if ($mencoderkillcmd != ""){ |
|---|
| 204 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
|---|
| 205 |
system ($mencoderkillcmd); |
|---|
| 206 |
chomp($mencoderkillcmd); |
|---|
| 207 |
&writelog ("tvrecording Killed current recording process. /dev/video$i:$mencoderkillcmd"); |
|---|
| 208 |
sleep(1); |
|---|
| 209 |
} |
|---|
| 210 |
$recdevice = "/dev/video$i"; |
|---|
| 211 |
&writelog ("tvrecording select device:$recdevice"); |
|---|
| 212 |
|
|---|
| 213 |
}elsif ($recch <= 0) { |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
$mencoderkillcmd =`/usr/sbin/lsof -Fp /dev/video$j`; |
|---|
| 217 |
$mencoderkillcmd =~ s/p//; |
|---|
| 218 |
if ($mencoderkillcmd != ""){ |
|---|
| 219 |
$mencoderkillcmd = "kill ".$mencoderkillcmd; |
|---|
| 220 |
system ($mencoderkillcmd); |
|---|
| 221 |
chomp($mencoderkillcmd); |
|---|
| 222 |
&writelog ("tvrecording Killed current recording process. /dev/video$j:$mencoderkillcmd"); |
|---|
| 223 |
sleep(1); |
|---|
| 224 |
} |
|---|
| 225 |
$recdevice = "/dev/video$j"; |
|---|
| 226 |
}else{ |
|---|
| 227 |
|
|---|
| 228 |
$recdevice = shift(@unusedevices ); |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
if ($recdevice eq ""){ |
|---|
| 235 |
$recdevice = "/dev/video0"; |
|---|
| 236 |
&writelog ( "Rec Device un defined. / $recch "); |
|---|
| 237 |
} |
|---|
| 238 |
return $reclengthsec; |
|---|
| 239 |
|
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
sub prepare{ |
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
$recch = $ARGV[0] ; |
|---|
| 248 |
$reclengthsec = $ARGV[1]; |
|---|
| 249 |
if (($recch eq "" )|| ($reclengthsec eq "")){ |
|---|
| 250 |
print "usage tvrecording.pl ch length(sec) [clip No(000-)] [filename] [bitrate(5)] [TID] [NO] [/dev/video0]\n"; |
|---|
| 251 |
exit; |
|---|
| 252 |
} |
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
my $intval = $recch % 35; |
|---|
| 268 |
my $startupsleep = $startupsleeptime - $intval; |
|---|
| 269 |
$reclengthsec = $reclengthsec + (60 - $startupsleep) + 1; |
|---|
| 270 |
|
|---|
| 271 |
if ( $ARGV[2] ne "N"){ |
|---|
| 272 |
&writelog("tvrecording: DEBUG SLEEP $startupsleeptime:$intval:$startupsleep:$reclengthsec"); |
|---|
| 273 |
sleep ( $startupsleep); |
|---|
| 274 |
}else{ |
|---|
| 275 |
&writelog("tvrecording: DEBUG RAPID START"); |
|---|
| 276 |
|
|---|
| 277 |
} |
|---|
| 278 |
if ($recunits > 1){ |
|---|
| 279 |
my $deviceno = $recunits - 1; |
|---|
| 280 |
$recdevice = "/dev/video$deviceno"; |
|---|
| 281 |
$recch = $ARGV[0] ; |
|---|
| 282 |
}else{ |
|---|
| 283 |
|
|---|
| 284 |
$recdevice = "/dev/video0"; |
|---|
| 285 |
$recch = $ARGV[0] ; |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
&getChCallsign(); |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
$outputpath = "$recfolderpath"."/"; |
|---|
| 292 |
|
|---|
| 293 |
if ($ARGV[6] eq "0"){ |
|---|
| 294 |
$outputfile = $outputpath.$ARGV[5]."--"; |
|---|
| 295 |
}else{ |
|---|
| 296 |
$outputfile = $outputpath.$ARGV[5]."-".$ARGV[6]."-"; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
if ($ARGV[3] ne ""){ |
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
$outputfile = $ARGV[3]; |
|---|
| 306 |
$outputfile = &filenameinjectioncheck($outputfile); |
|---|
| 307 |
$outputfilewithoutpath = $outputfile ; |
|---|
| 308 |
$outputfile = $outputpath.$outputfile ; |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
&writelog("tvrecording: DEBUG ARGV[2] ne null \$outputfile $outputfile "); |
|---|
| 312 |
}else{ |
|---|
| 313 |
$outputfile .= `date +%Y%m%d-%H%M --date "1 min "`; |
|---|
| 314 |
chomp($outputfile); |
|---|
| 315 |
$outputfile .= ".m2p"; |
|---|
| 316 |
$outputfilewithoutpath = $outputfile ; |
|---|
| 317 |
&writelog("tvrecording: DEBUG ARGV[2] is null \$outputfile $outputfile "); |
|---|
| 318 |
} |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
@wday_name = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat"); |
|---|
| 322 |
$sleepcounter = 0; |
|---|
| 323 |
$cmd=""; |
|---|
| 324 |
|
|---|
| 325 |
|
|---|
| 326 |
if ( -e "$outputfile" ){ |
|---|
| 327 |
if ( -s "$outputfile" ){ |
|---|
| 328 |
&writelog("tvrecording :ABORT :recfile $outputfile exist."); |
|---|
| 329 |
exit 1; |
|---|
| 330 |
} |
|---|
| 331 |
} |
|---|
| 332 |
|
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
sub setbitrate{ |
|---|
| 336 |
$bitrate = $ARGV[4] ; |
|---|
| 337 |
$bitrate = $bitrate * 1024*1024; |
|---|
| 338 |
$peakbitrate = $bitrate + 350000; |
|---|
| 339 |
$recordbitrate = " --bitrate $bitrate --peakbitrate $peakbitrate "; |
|---|
| 340 |
$stdbitrate = "$bitrate"; |
|---|
| 341 |
$peakbitrate = "$peakbitrate"; |
|---|
| 342 |
} |
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
sub callrecordv4l{ |
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
my $ivtvtuneftype = ''; |
|---|
| 349 |
if ($frequencyTable eq "ntsc-cable-jp"){ |
|---|
| 350 |
$ivtvtuneftype = 'japan-cable'; |
|---|
| 351 |
}else{ |
|---|
| 352 |
$ivtvtuneftype = 'japan-bcast'; |
|---|
| 353 |
} |
|---|
| 354 |
|
|---|
| 355 |
&writelog("tvrecording DEBUG ivtv-tune -d $recdevice -t $ivtvtuneftype -c $ivtvrecch"); |
|---|
| 356 |
&writelog("tvrecording DEBUG $ENV{PATH}"); |
|---|
| 357 |
|
|---|
| 358 |
$frequency = `env PATH=PATH=/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/bin:/usr/bin:/home/foltia/bin ivtv-tune -d $recdevice -t $ivtvtuneftype -c $ivtvrecch`; |
|---|
| 359 |
&writelog("tvrecording DEBUG frequency:$frequency"); |
|---|
| 360 |
@frequency = split(/\s/,$frequency); |
|---|
| 361 |
$frequency[1] =~ s/\.//gi; |
|---|
| 362 |
$frequency = $frequency[1] ; |
|---|
| 363 |
&writelog("tvrecording DEBUG frequency:$frequency"); |
|---|
| 364 |
|
|---|
| 365 |
my $recordv4lcallstring = "$toolpath/perl/record-v4l2.pl --frequency $frequency --duration $reclengthsec --input $recdevice --directory $recfolderpath --inputnum $capturedeviceinputnum --inputname '$capturedeviceinputName' --freqtable $frequencyTable --bitrate $stdbitrate --peakbitrate $peakbitrate --output $outputfilewithoutpath "; |
|---|
| 366 |
|
|---|
| 367 |
&writelog("tvrecording $recordv4lcallstring"); |
|---|
| 368 |
&writelog("tvrecording DEBUG $ENV{HOME}/.ivtvrc"); |
|---|
| 369 |
$oserr = `env HOME=$toolpath $recordv4lcallstring`; |
|---|
| 370 |
&writelog("tvrecording DEBUG $oserr"); |
|---|
| 371 |
|
|---|
| 372 |
} |
|---|
| 373 |
|
|---|