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 |
|
---|
268 |
# トラコンキューイング #2007/7/10 |
---|
269 |
my $trcnprocesses = ""; |
---|
270 |
my $cpucores = `ls /proc/acpi/processor | wc -l`; |
---|
271 |
$cpucores =~ s/[^0-9]//gi; |
---|
272 |
unless ($cpucores >= 1 ){ |
---|
273 |
$cpucores = 1; |
---|
274 |
} |
---|
275 |
do { |
---|
276 |
$trcnprocesses = `ps ax | grep ffmpeg | grep -v grep | wc -l `; |
---|
277 |
$trcnprocesses =~ s/[^0-9]//gi; |
---|
278 |
# 既にトラコンプロセスが走っているなら適当に待機 |
---|
279 |
if ($trcnprocesses >= $cpucores){ |
---|
280 |
if (-e "/proc/uptime" ){ |
---|
281 |
$loadaverage = `uptime`; |
---|
282 |
chomp($loadaverage); |
---|
283 |
}else{ |
---|
284 |
$loadaverage = ""; |
---|
285 |
} |
---|
286 |
&writelog("recwrap TRCN WAITING :$trcnprocesses / $cpucores :$outputfilename $loadaverage"); |
---|
287 |
sleep 113; |
---|
288 |
sleep ($recch)*5; |
---|
289 |
} |
---|
290 |
} until ($trcnprocesses < $cpucores); |
---|
291 |
|
---|
292 |
|
---|
293 |
if (($trconqty eq "")||($trconqty == 0 )){ |
---|
294 |
&writelog("recwrap TRCNSTART vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
295 |
system("$toolpath/perl/transcode/vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
296 |
&writelog("recwrap TRCNEND vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
297 |
#最適化 |
---|
298 |
$DBQuery = "SELECT subtitle FROM foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' "; |
---|
299 |
$sth = $dbh->prepare($DBQuery); |
---|
300 |
$sth->execute(); |
---|
301 |
@programtitle = $sth->fetchrow_array; |
---|
302 |
if ( $countno == "0" ){ |
---|
303 |
$pspcountno = ""; |
---|
304 |
}else{ |
---|
305 |
$pspcountno = $countno ; |
---|
306 |
} |
---|
307 |
&writelog("recwrap OPTIMIZE mp4psp -p $pspdirname/M4V$pspfilname.MP4 -t '$psptrcn[2] $pspcountno $programtitle[0]' "); |
---|
308 |
Jcode::convert(\$programtitle[0],'euc'); |
---|
309 |
system ("/usr/local/bin/mp4psp -p $pspdirname/M4V$pspfilname.MP4 -t '$psptrcn[2] $pspcountno $programtitle[0]'") ; |
---|
310 |
$mp4filename = "M4V${pspfilname}.MP4"; |
---|
311 |
$thmfilename = "M4V${pspfilname}.THM"; |
---|
312 |
}else{# #2006/12/6 新エンコーダ |
---|
313 |
|
---|
314 |
&writelog("recwrap TRCNSTART ipodtranscode.pl $recfolderpath/$outputfilename $pspfilname $pspdirname $pid $psptrcn[1]"); |
---|
315 |
system("$toolpath/perl/ipodtranscode.pl $recfolderpath/$outputfilename $pspfilname $pspdirname $pid $psptrcn[1]"); |
---|
316 |
&writelog("recwrap TRCNEND ipodtranscode.pl $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
317 |
|
---|
318 |
if($trconqty >= 2){#H.264/AVCなら |
---|
319 |
$mp4filename = "MAQ${pspfilname}.MP4"; |
---|
320 |
$thmfilename = "MAQ${pspfilname}.THM"; |
---|
321 |
}else{ |
---|
322 |
$mp4filename = "M4V${pspfilname}.MP4"; |
---|
323 |
$thmfilename = "M4V${pspfilname}.THM"; |
---|
324 |
} |
---|
325 |
} |
---|
326 |
|
---|
327 |
#サムネール |
---|
328 |
|
---|
329 |
# 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 |
---|
330 |
#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 |
---|
331 |
&writelog("recwrap THAMJ mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3 -v 3 $recfolderpath/$outputfilename "); |
---|
332 |
system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3 -v 3 $recfolderpath/$outputfilename"); |
---|
333 |
&writelog("recwrap THAMI convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V$pspdirname.THM "); |
---|
334 |
|
---|
335 |
if (-e "$pspdirname/$thmfilename"){ |
---|
336 |
$timestamp =`date "+%Y%m%d-%H%M%S"`; |
---|
337 |
chomp $timestamp; |
---|
338 |
system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename".$timestamp.".THM"); |
---|
339 |
|
---|
340 |
}else{ |
---|
341 |
system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename"); |
---|
342 |
} |
---|
343 |
# rm -rf 00000001.jpg |
---|
344 |
# convert -resize 160x120\! 00000002.jpg M4V44307.THM |
---|
345 |
# rm -rf 00000002.jpg |
---|
346 |
system("rm -rf $pspdirname/0000000*.jpg "); |
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|
351 |
# MP4ファイル名をPIDレコードに書き込み |
---|
352 |
$DBQuery = "UPDATE foltia_subtitle SET |
---|
353 |
PSPfilename = '$mp4filename' |
---|
354 |
WHERE pid = '$pid' "; |
---|
355 |
$sth = $dbh->prepare($DBQuery); |
---|
356 |
$sth->execute(); |
---|
357 |
&writelog("recwrap UPDATEsubtitleDB $DBQuery"); |
---|
358 |
|
---|
359 |
# MP4ファイル名をfoltia_mp4files挿入 |
---|
360 |
$DBQuery = "insert into foltia_mp4files values ('$tid','$mp4filename') "; |
---|
361 |
$sth = $dbh->prepare($DBQuery); |
---|
362 |
$sth->execute(); |
---|
363 |
&writelog("recwrap UPDATEmp4DB $DBQuery"); |
---|
364 |
|
---|
365 |
}#PSPトラコンあり |
---|
366 |
|
---|
367 |
|
---|
368 |
|
---|
369 |
|
---|
370 |
|
---|