| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 |  | 
|---|
| 4 |  | 
|---|
| 5 |  | 
|---|
| 6 |  | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | use DBI; | 
|---|
| 16 | use DBD::Pg; | 
|---|
| 17 | use Schedule::At; | 
|---|
| 18 | use Time::Local; | 
|---|
| 19 | use Jcode; | 
|---|
| 20 |  | 
|---|
| 21 | $path = $0; | 
|---|
| 22 | $path =~ s/recwrap.pl$//i; | 
|---|
| 23 | if ($pwd  ne "./"){ | 
|---|
| 24 | push( @INC, "$path"); | 
|---|
| 25 | } | 
|---|
| 26 |  | 
|---|
| 27 | require "foltialib.pl"; | 
|---|
| 28 |  | 
|---|
| 29 | $recch = $ARGV[0] ; | 
|---|
| 30 | if ($recch eq "" ){ | 
|---|
| 31 |  | 
|---|
| 32 | print "usage recwrap.pl  ch length(sec) [bitrate(5)] [TID] [NO] [PID]\n"; | 
|---|
| 33 | exit; | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | $recch = $ARGV[0] ; | 
|---|
| 37 | $reclength = $ARGV[1] ; | 
|---|
| 38 | $bitrate  = $ARGV[2] ; | 
|---|
| 39 | $tid  = $ARGV[3] ; | 
|---|
| 40 | $countno  = $ARGV[4] ; | 
|---|
| 41 | $pid  = $ARGV[5] ; | 
|---|
| 42 |  | 
|---|
| 43 | $outputfile = `date  +%Y%m%d-%H%M --date "1 min "`; | 
|---|
| 44 | chomp($outputfile); | 
|---|
| 45 | if ($tid == 0){ | 
|---|
| 46 | $outputfilename = "0--".$outputfile."-".$recch.".m2p"; | 
|---|
| 47 | $mp4newstylefilename = "-0--".$outputfile."-".$recch; | 
|---|
| 48 | }else{ | 
|---|
| 49 | if ($countno == 0){ | 
|---|
| 50 | $outputfilename = $tid ."--".$outputfile.".m2p"; | 
|---|
| 51 | $mp4newstylefilename = "-" . $tid ."--".$outputfile; | 
|---|
| 52 | }else{ | 
|---|
| 53 | $outputfilename = $tid ."-".$countno."-".$outputfile.".m2p"; | 
|---|
| 54 | $mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile; | 
|---|
| 55 | } | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | if ($haveirdaunit == 1){ | 
|---|
| 60 |  | 
|---|
| 61 | if ($recch == 0){ | 
|---|
| 62 |  | 
|---|
| 63 | &writelog("recwrap Call Change STB CH :$pid"); | 
|---|
| 64 | system ("$toolpath/perl/changestbch.pl $pid &"); | 
|---|
| 65 | } | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | if($recch == -10){ | 
|---|
| 69 |  | 
|---|
| 70 | &writelog("recwrap Not recordable channel;exit:PID $pid"); | 
|---|
| 71 | exit; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | &writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid"); | 
|---|
| 75 |  | 
|---|
| 76 |  | 
|---|
| 77 | $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno"); | 
|---|
| 78 | $oserr = $oserr / 256; | 
|---|
| 79 | if ($oserr == 1){ | 
|---|
| 80 | &writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); | 
|---|
| 81 | exit; | 
|---|
| 82 | }else{ | 
|---|
| 83 | &writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", | 
|---|
| 87 | $DBDriv,$DBName,$DBHost,$DBPort); | 
|---|
| 88 | $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; | 
|---|
| 89 |  | 
|---|
| 90 |  | 
|---|
| 91 | $DBQuery =  "UPDATE  foltia_subtitle  SET | 
|---|
| 92 | m2pfilename      = '$outputfilename' | 
|---|
| 93 | WHERE pid =  '$pid' "; | 
|---|
| 94 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 95 | $sth->execute(); | 
|---|
| 96 | &writelog("recwrap UPDATEDB  $DBQuery"); | 
|---|
| 97 |  | 
|---|
| 98 |  | 
|---|
| 99 | $DBQuery =  "insert into  foltia_m2pfiles values ('$outputfilename')"; | 
|---|
| 100 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 101 | $sth->execute(); | 
|---|
| 102 | &writelog("recwrap UPDATEDB  $DBQuery"); | 
|---|
| 103 |  | 
|---|
| 104 |  | 
|---|
| 105 | if (-e "$toolpath/perl/captureimagemaker.pl"){ | 
|---|
| 106 | &writelog("recwrap Call captureimagemaker $outputfilename"); | 
|---|
| 107 | system ("$toolpath/perl/captureimagemaker.pl $outputfilename"); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 |  | 
|---|
| 113 |  | 
|---|
| 114 | $DBQuery =  "SELECT psp,aspect,title FROM  foltia_program WHERE tid = '$tid' "; | 
|---|
| 115 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 116 | $sth->execute(); | 
|---|
| 117 | @psptrcn= $sth->fetchrow_array; | 
|---|
| 118 | if ($psptrcn[0]  == 1 ){ | 
|---|
| 119 |  | 
|---|
| 120 |  | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 | my $pspfilnamehd = ""; | 
|---|
| 125 |  | 
|---|
| 126 | $pspfilnamehd = $tid; | 
|---|
| 127 | $pspdirname = "$tid.localized/"; | 
|---|
| 128 | $pspdirname = $recfolderpath."/".$pspdirname; | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | unless (-e $pspdirname ){ | 
|---|
| 132 | system("$toolpath/perl/mklocalizeddir.pl $tid"); | 
|---|
| 133 |  | 
|---|
| 134 | } | 
|---|
| 135 | $pspdirname = "$tid.localized/mp4/"; | 
|---|
| 136 | $pspdirname = $recfolderpath."/".$pspdirname; | 
|---|
| 137 |  | 
|---|
| 138 | unless (-e $pspdirname ){ | 
|---|
| 139 | mkdir $pspdirname ,0777; | 
|---|
| 140 |  | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 |  | 
|---|
| 144 | if ($mp4filenamestyle == 1){ | 
|---|
| 145 | $pspfilname = $mp4newstylefilename ; | 
|---|
| 146 |  | 
|---|
| 147 | }else{ | 
|---|
| 148 |  | 
|---|
| 149 |  | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|
| 155 |  | 
|---|
| 156 |  | 
|---|
| 157 | my $pspfilnameft = ""; | 
|---|
| 158 | my $pspfilnameyearhd = ""; | 
|---|
| 159 | my $pspfilnameyearft = ""; | 
|---|
| 160 |  | 
|---|
| 161 | $btid = $tid % 3600; | 
|---|
| 162 |  | 
|---|
| 163 |  | 
|---|
| 164 | if($btid >= 0 && $btid < 1000){ | 
|---|
| 165 |  | 
|---|
| 166 | $pspfilnamehd = sprintf("%03d",$btid); | 
|---|
| 167 |  | 
|---|
| 168 | }elsif ($btid >= 1000 && $btid < 3600){ | 
|---|
| 169 | $pspfilnameyearhd = substr($btid, 0, 2); | 
|---|
| 170 | $pspfilnameyearhd =~ s/10/A/; | 
|---|
| 171 | $pspfilnameyearhd =~ s/11/B/; | 
|---|
| 172 | $pspfilnameyearhd =~ s/12/C/; | 
|---|
| 173 | $pspfilnameyearhd =~ s/13/D/; | 
|---|
| 174 | $pspfilnameyearhd =~ s/14/E/; | 
|---|
| 175 | $pspfilnameyearhd =~ s/15/F/; | 
|---|
| 176 | $pspfilnameyearhd =~ s/16/G/; | 
|---|
| 177 | $pspfilnameyearhd =~ s/17/H/; | 
|---|
| 178 | $pspfilnameyearhd =~ s/18/I/; | 
|---|
| 179 | $pspfilnameyearhd =~ s/19/J/; | 
|---|
| 180 | $pspfilnameyearhd =~ s/20/K/; | 
|---|
| 181 | $pspfilnameyearhd =~ s/21/L/; | 
|---|
| 182 | $pspfilnameyearhd =~ s/22/M/; | 
|---|
| 183 | $pspfilnameyearhd =~ s/23/N/; | 
|---|
| 184 | $pspfilnameyearhd =~ s/24/O/; | 
|---|
| 185 | $pspfilnameyearhd =~ s/25/P/; | 
|---|
| 186 | $pspfilnameyearhd =~ s/26/Q/; | 
|---|
| 187 | $pspfilnameyearhd =~ s/27/R/; | 
|---|
| 188 | $pspfilnameyearhd =~ s/28/S/; | 
|---|
| 189 | $pspfilnameyearhd =~ s/29/T/; | 
|---|
| 190 | $pspfilnameyearhd =~ s/30/U/; | 
|---|
| 191 | $pspfilnameyearhd =~ s/31/V/; | 
|---|
| 192 | $pspfilnameyearhd =~ s/32/W/; | 
|---|
| 193 | $pspfilnameyearhd =~ s/33/X/; | 
|---|
| 194 | $pspfilnameyearhd =~ s/34/Y/; | 
|---|
| 195 | $pspfilnameyearhd =~ s/35/Z/; | 
|---|
| 196 |  | 
|---|
| 197 | $pspfilnameyearft = substr($btid, 2, 2); | 
|---|
| 198 | $pspfilnameyearft = sprintf("%02d",$pspfilnameyearft); | 
|---|
| 199 | $pspfilnamehd = $pspfilnameyearhd . $pspfilnameyearft; | 
|---|
| 200 |  | 
|---|
| 201 | } | 
|---|
| 202 |  | 
|---|
| 203 |  | 
|---|
| 204 | if (0 < $countno && $countno < 100 ){ | 
|---|
| 205 |  | 
|---|
| 206 | $pspfilnameft = sprintf("%02d",$countno); | 
|---|
| 207 | }elsif(100 <= $countno && $countno < 1000 ){ | 
|---|
| 208 |  | 
|---|
| 209 | $pspfilnameft = sprintf("%03d",$countno); | 
|---|
| 210 | $pspfilnamehd = substr($pspfilnamehd, 0, 2); | 
|---|
| 211 | }elsif(1000 <= $countno && $countno < 10000 ){ | 
|---|
| 212 |  | 
|---|
| 213 | $pspfilnameft = sprintf("%04d",$countno); | 
|---|
| 214 | $pspfilnamehd = substr($pspfilnamehd, 0, 1); | 
|---|
| 215 |  | 
|---|
| 216 |  | 
|---|
| 217 | }elsif($countno == 0){ | 
|---|
| 218 |  | 
|---|
| 219 | my $newestmp4filename = `cd $pspdirname ; ls -t *.MP4 | head -1`; | 
|---|
| 220 | if ($newestmp4filename =~ /M4V$tid/){ | 
|---|
| 221 | $nowcountno = $' ; | 
|---|
| 222 | $nowcountno++; | 
|---|
| 223 | $pspfilnameft = sprintf("%02d",$nowcountno); | 
|---|
| 224 | while (-e "$pspdirname/M4V".$pspfilnamehd.$pspfilnameft.".MP4"){ | 
|---|
| 225 | $nowcountno++; | 
|---|
| 226 | $pspfilnameft = sprintf("%02d",$nowcountno); | 
|---|
| 227 | print "File exist:$nowcountno\n"; | 
|---|
| 228 | } | 
|---|
| 229 | #print "NeXT\n"; | 
|---|
| 230 | }else{ | 
|---|
| 231 | # 0の場合 週番号を100から引いたもの | 
|---|
| 232 | # week number of year with Monday as first day of week (01..53) | 
|---|
| 233 | #だったけど常に0に | 
|---|
| 234 | #       my $weeno = `date "+%V"`; | 
|---|
| 235 | #       $weeno = 100 - $weeno ; | 
|---|
| 236 | #       $pspfilnameft = sprintf("%02d",$weeno); | 
|---|
| 237 | $pspfilnameft = sprintf("%02d",0); | 
|---|
| 238 | #print "WEEKNO\n"; | 
|---|
| 239 | } | 
|---|
| 240 |  | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 | my $pspfilname = $pspfilnamehd.$pspfilnameft  ; | 
|---|
| 244 | # print "$pspfilname($pspfilnamehd/$pspfilnameft)\n"; | 
|---|
| 245 | }# endif MP4ファイル名が新styleなら | 
|---|
| 246 | #2006/12/03_10:30:24 recwrap TRCNSTART vfr4psp.sh /home/foltia/php/tv/591-87-20061203-1000.m2p -591-87-20061203-1000 /home/foltia/php/tv/591.localized/mp4/ 3 | 
|---|
| 247 |  | 
|---|
| 248 | if (($trconqty eq "")||($trconqty == 0 )){ | 
|---|
| 249 | &writelog("recwrap TRCNSTART vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); | 
|---|
| 250 | system("$toolpath/perl/transcode/vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); | 
|---|
| 251 | &writelog("recwrap TRCNEND  vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); | 
|---|
| 252 | #最適化 | 
|---|
| 253 | $DBQuery =  "SELECT subtitle  FROM  foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' "; | 
|---|
| 254 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 255 | $sth->execute(); | 
|---|
| 256 | @programtitle = $sth->fetchrow_array; | 
|---|
| 257 | if ( $countno == "0" ){ | 
|---|
| 258 | $pspcountno = ""; | 
|---|
| 259 | }else{ | 
|---|
| 260 | $pspcountno = $countno ; | 
|---|
| 261 | } | 
|---|
| 262 | &writelog("recwrap OPTIMIZE  mp4psp -p $pspdirname/M4V$pspfilname.MP4   -t  '$psptrcn[2] $pspcountno $programtitle[0]' "); | 
|---|
| 263 | Jcode::convert(\$programtitle[0],'euc'); | 
|---|
| 264 | system ("/usr/local/bin/mp4psp -p $pspdirname/M4V$pspfilname.MP4   -t  '$psptrcn[2] $pspcountno $programtitle[0]'") ; | 
|---|
| 265 | $mp4filename = "M4V${pspfilname}.MP4"; | 
|---|
| 266 | $thmfilename = "M4V${pspfilname}.THM"; | 
|---|
| 267 | }else{# #2006/12/6 新エンコーダ | 
|---|
| 268 |  | 
|---|
| 269 | &writelog("recwrap TRCNSTART ipodtranscode.pl $recfolderpath/$outputfilename $pspfilname $pspdirname $pid $psptrcn[1]"); | 
|---|
| 270 | system("$toolpath/perl/ipodtranscode.pl $recfolderpath/$outputfilename $pspfilname $pspdirname $pid $psptrcn[1]"); | 
|---|
| 271 | &writelog("recwrap TRCNEND  ipodtranscode.pl $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); | 
|---|
| 272 |  | 
|---|
| 273 | if($trconqty >= 2){#H.264/AVCなら | 
|---|
| 274 | $mp4filename = "MAQ${pspfilname}.MP4"; | 
|---|
| 275 | $thmfilename = "MAQ${pspfilname}.THM"; | 
|---|
| 276 | }else{ | 
|---|
| 277 | $mp4filename = "M4V${pspfilname}.MP4"; | 
|---|
| 278 | $thmfilename = "M4V${pspfilname}.THM"; | 
|---|
| 279 | } | 
|---|
| 280 | } | 
|---|
| 281 |  | 
|---|
| 282 | #サムネール | 
|---|
| 283 |  | 
|---|
| 284 | # mplayer -ss 00:01:20 -vo jpeg:outdir=/home/foltia/php/tv/443MNV01 -ao null -sstep 1 -frames 3  -v 3 /home/foltia/php/tv/443-07-20050218-0030.m2p | 
|---|
| 285 | #2005/02/22_18:30:05 recwrap TRCNSTART vfr4psp.sh /home/foltia/php/tv/447-21-20050222-1800.m2p 44721 /home/foltia/php/tv/447MNV01 3 | 
|---|
| 286 | &writelog("recwrap THAMJ  mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $recfolderpath/$outputfilename "); | 
|---|
| 287 | system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $recfolderpath/$outputfilename"); | 
|---|
| 288 | &writelog("recwrap THAMI  convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V$pspdirname.THM "); | 
|---|
| 289 |  | 
|---|
| 290 | if (-e "$pspdirname/$thmfilename"){ | 
|---|
| 291 | $timestamp =`date "+%Y%m%d-%H%M%S"`; | 
|---|
| 292 | chomp $timestamp; | 
|---|
| 293 | system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename".$timestamp.".THM"); | 
|---|
| 294 |  | 
|---|
| 295 | }else{ | 
|---|
| 296 | system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename"); | 
|---|
| 297 | } | 
|---|
| 298 | # rm -rf 00000001.jpg | 
|---|
| 299 | # convert -resize 160x120\! 00000002.jpg M4V44307.THM | 
|---|
| 300 | # rm -rf 00000002.jpg | 
|---|
| 301 | system("rm -rf $pspdirname/0000000*.jpg "); | 
|---|
| 302 |  | 
|---|
| 303 |  | 
|---|
| 304 |  | 
|---|
| 305 |  | 
|---|
| 306 | # MP4ファイル名をPIDレコードに書き込み | 
|---|
| 307 | $DBQuery =  "UPDATE  foltia_subtitle  SET | 
|---|
| 308 | PSPfilename      = '$mp4filename' | 
|---|
| 309 | WHERE pid =  '$pid' "; | 
|---|
| 310 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 311 | $sth->execute(); | 
|---|
| 312 | &writelog("recwrap UPDATEsubtitleDB  $DBQuery"); | 
|---|
| 313 |  | 
|---|
| 314 | # MP4ファイル名をfoltia_mp4files挿入 | 
|---|
| 315 | $DBQuery =  "insert into  foltia_mp4files values ('$tid','$mp4filename') "; | 
|---|
| 316 | $sth = $dbh->prepare($DBQuery); | 
|---|
| 317 | $sth->execute(); | 
|---|
| 318 | &writelog("recwrap UPDATEmp4DB  $DBQuery"); | 
|---|
| 319 |  | 
|---|
| 320 | }#PSPトラコンあり | 
|---|
| 321 |  | 
|---|
| 322 |  | 
|---|
| 323 |  | 
|---|
| 324 |  | 
|---|
| 325 |  | 
|---|