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