1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
use DBI; |
---|
14 |
use DBD::Pg; |
---|
15 |
use DBD::SQLite; |
---|
16 |
use Jcode; |
---|
17 |
|
---|
18 |
$path = $0; |
---|
19 |
$path =~ s/ipodtranscode.pl$//i; |
---|
20 |
if ($path ne "./"){ |
---|
21 |
push( @INC, "$path"); |
---|
22 |
} |
---|
23 |
require "foltialib.pl"; |
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 |
$processes = &processfind("ipodtranscode.pl"); |
---|
28 |
|
---|
29 |
|
---|
30 |
if ($processes > 1 ){ |
---|
31 |
&writelog("ipodtranscode processes exist. exit:"); |
---|
32 |
exit; |
---|
33 |
}else{ |
---|
34 |
|
---|
35 |
} |
---|
36 |
|
---|
37 |
|
---|
38 |
$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;; |
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
&writelog("ipodtranscode starting up."); |
---|
49 |
|
---|
50 |
$counttranscodefiles = &counttranscodefiles(); |
---|
51 |
if ($counttranscodefiles == 0){ |
---|
52 |
&writelog("ipodtranscode No MPEG2 files to transcode."); |
---|
53 |
exit; |
---|
54 |
} |
---|
55 |
sleep 30; |
---|
56 |
|
---|
57 |
while ($counttranscodefiles >= 1){ |
---|
58 |
$sth = $dbh->prepare($stmt{'ipodtranscode.1'}); |
---|
59 |
$sth->execute($FILESTATUSRECEND, $FILESTATUSTRANSCODECOMPLETE, ); |
---|
60 |
@dbparam = $sth->fetchrow_array; |
---|
61 |
|
---|
62 |
|
---|
63 |
&writelog("ipodtranscode DEBUG $dbparam[0],$dbparam[1],$dbparam[2],$dbparam[3],$dbparam[4],$dbparam[5]"); |
---|
64 |
$pid = $dbparam[0]; |
---|
65 |
$tid = $dbparam[1]; |
---|
66 |
$inputmpeg2 = $recfolderpath."/".$dbparam[2]; |
---|
67 |
$mpeg2filename = $dbparam[2]; |
---|
68 |
$filestatus = $dbparam[3]; |
---|
69 |
$aspect = $dbparam[4]; |
---|
70 |
$countno = $dbparam[5]; |
---|
71 |
$mp4filenamestring = &mp4filenamestringbuild($pid); |
---|
72 |
|
---|
73 |
if (-e $inputmpeg2){ |
---|
74 |
|
---|
75 |
&writelog("ipodtranscode DEBUG mp4filenamestring $mp4filenamestring"); |
---|
76 |
|
---|
77 |
$pspdirname = &makemp4dir($tid); |
---|
78 |
$mp4outdir = $pspdirname ; |
---|
79 |
|
---|
80 |
|
---|
81 |
if ($pid ne ""){ |
---|
82 |
$sth = $dbh->prepare($stmt{'ipodtranscode.2'}); |
---|
83 |
$sth->execute($pid); |
---|
84 |
@programtitle = $sth->fetchrow_array; |
---|
85 |
$programtitle[0] =~ s/\"/\\"/gi; |
---|
86 |
$programtitle[2] =~ s/\"/\\"/gi; |
---|
87 |
|
---|
88 |
if ($pid > 0){ |
---|
89 |
if ($programtitle[1] ne ""){ |
---|
90 |
$movietitle = " -title \"$programtitle[0] 第$programtitle[1]話 $programtitle[2]\" "; |
---|
91 |
$movietitleeuc = " -t \"$programtitle[0] 第$programtitle[1]話 $programtitle[2]\" "; |
---|
92 |
}else{ |
---|
93 |
$movietitle = " -title \"$programtitle[0] $programtitle[2]\" "; |
---|
94 |
$movietitleeuc = " -t \"$programtitle[0] $programtitle[2]\" "; |
---|
95 |
} |
---|
96 |
}elsif($pid < 0){ |
---|
97 |
|
---|
98 |
$movietitle = " -title \"$programtitle[2]\" "; |
---|
99 |
$movietitleeuc = " -t \"$programtitle[2]\" "; |
---|
100 |
}else{ |
---|
101 |
|
---|
102 |
$movietitle = ""; |
---|
103 |
$movietitleeuc = ""; |
---|
104 |
} |
---|
105 |
|
---|
106 |
$movietitle = ""; |
---|
107 |
$movietitleeuc = ""; |
---|
108 |
|
---|
109 |
} |
---|
110 |
|
---|
111 |
if ($filestatus <= $FILESTATUSRECEND){ |
---|
112 |
} |
---|
113 |
|
---|
114 |
if ($filestatus <= $FILESTATUSWAITINGCAPTURE){ |
---|
115 |
|
---|
116 |
} |
---|
117 |
|
---|
118 |
if ($filestatus <= $FILESTATUSCAPTURE){ |
---|
119 |
|
---|
120 |
|
---|
121 |
if (-e "$toolpath/perl/captureimagemaker.pl"){ |
---|
122 |
&writelog("ipodtranscode Call captureimagemaker $mpeg2filename"); |
---|
123 |
&changefilestatus($pid,$FILESTATUSCAPTURE); |
---|
124 |
system ("$toolpath/perl/captureimagemaker.pl $mpeg2filename"); |
---|
125 |
&changefilestatus($pid,$FILESTATUSCAPEND); |
---|
126 |
} |
---|
127 |
} |
---|
128 |
|
---|
129 |
if ($filestatus <= $FILESTATUSCAPEND){ |
---|
130 |
|
---|
131 |
&makethumbnail(); |
---|
132 |
&changefilestatus($pid,$FILESTATUSTHMCREATE); |
---|
133 |
} |
---|
134 |
|
---|
135 |
if ($filestatus <= $FILESTATUSWAITINGTRANSCODE){ |
---|
136 |
} |
---|
137 |
|
---|
138 |
$filenamebody = $inputmpeg2 ; |
---|
139 |
$filenamebody =~ s/.m2t$|.ts$|.m2p$|.mpg$|.aac$//gi; |
---|
140 |
|
---|
141 |
|
---|
142 |
if ($inputmpeg2 =~ /m2t$|ts$|aac$/i){ |
---|
143 |
|
---|
144 |
if ($filestatus <= $FILESTATUSTRANSCODETSSPLITTING){ |
---|
145 |
unlink("${filenamebody}_tss.m2t"); |
---|
146 |
unlink("${filenamebody}_HD.m2t"); |
---|
147 |
} |
---|
148 |
if ($filestatus <= $FILESTATUSTRANSCODEFFMPEG){ |
---|
149 |
unlink("$filenamebody.264"); |
---|
150 |
|
---|
151 |
$trcnmpegfile = $inputmpeg2 ; |
---|
152 |
|
---|
153 |
if ($aspect == 1){ |
---|
154 |
$cropopt = " -croptop 150 -cropbottom 150 -cropleft 200 -cropright 200 "; |
---|
155 |
}elsif($aspect == 4){ |
---|
156 |
$cropopt = " -croptop 6 -cropbottom 6 -cropleft 8 -cropright 8 "; |
---|
157 |
}else{ |
---|
158 |
$cropopt = " -croptop 6 -cropbottom 6 -cropleft 8 -cropright 8 "; |
---|
159 |
} |
---|
160 |
|
---|
161 |
if (($trconqty eq "")||($trconqty == 1)){ |
---|
162 |
$ffmpegencopt = " -threads 0 -s 360x202 -deinterlace -r 24.00 -vcodec libx264 -g 300 -b 330000 -level 13 -loop 1 -sc_threshold 60 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -refs 3 -maxrate 700000 -async 50 -f h264 $filenamebody.264"; |
---|
163 |
}elsif($trconqty == 2){ |
---|
164 |
|
---|
165 |
|
---|
166 |
$ffmpegencopt = " -threads 0 -s 480x272 -deinterlace -r 29.97 -vcodec libx264 -vpre default -g 300 -b 400000 -level 13 -sc_threshold 60 -rc_eq 'blurCplx^(1-qComp)' -refs 3 -maxrate 700000 -async 50 -f h264 $filenamebody.264"; |
---|
167 |
}elsif($trconqty == 3){ |
---|
168 |
|
---|
169 |
|
---|
170 |
$ffmpegencopt = " -threads 0 -s 640x352 -deinterlace -r 29.97 -vcodec libx264 -vpre default -g 100 -b 600000 -level 13 -sc_threshold 60 -rc_eq 'blurCplx^(1-qComp)' -refs 3 -maxrate 700000 -async 50 -f h264 $filenamebody.264"; |
---|
171 |
} |
---|
172 |
&changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG); |
---|
173 |
|
---|
174 |
|
---|
175 |
|
---|
176 |
if (! -e "$filenamebody.264"){ |
---|
177 |
&changefilestatus($pid,$FILESTATUSTRANSCODETSSPLITTING); |
---|
178 |
unlink("${filenamebody}_tss.m2t"); |
---|
179 |
unlink("${filenamebody}_HD.m2t"); |
---|
180 |
if (-e "$toolpath/perl/tool/tss.py"){ |
---|
181 |
&writelog("ipodtranscode tss $inputmpeg2"); |
---|
182 |
system("$toolpath/perl/tool/tss.py $inputmpeg2"); |
---|
183 |
}else{ |
---|
184 |
|
---|
185 |
|
---|
186 |
|
---|
187 |
} |
---|
188 |
if(-e "${filenamebody}_tss.m2t"){ |
---|
189 |
$trcnmpegfile = "${filenamebody}_tss.m2t"; |
---|
190 |
}elsif (-e "${filenamebody}_HD.m2t"){ |
---|
191 |
$trcnmpegfile = "${filenamebody}_HD.m2t"; |
---|
192 |
}else{ |
---|
193 |
&writelog("ipodtranscode ERR NOT Exist ${filenamebody}_HD.m2t"); |
---|
194 |
$trcnmpegfile = $inputmpeg2 ; |
---|
195 |
} |
---|
196 |
|
---|
197 |
$trcnmpegfile = &validationsplitfile($inputmpeg2,$trcnmpegfile); |
---|
198 |
|
---|
199 |
if($trcnmpegfile eq $inputmpeg2){ |
---|
200 |
|
---|
201 |
|
---|
202 |
&writelog("ipodtranscode WINE TsSplitter.exe $inputmpeg2"); |
---|
203 |
system("wine $toolpath/perl/tool/TsSplitter.exe -EIT -ECM -EMM -SD -1SEG -WAIT2 $inputmpeg2"); |
---|
204 |
if (-e "${filenamebody}_HD.m2t"){ |
---|
205 |
$trcnmpegfile = "${filenamebody}_HD.m2t"; |
---|
206 |
|
---|
207 |
$trcnmpegfile = &validationsplitfile($inputmpeg2,$trcnmpegfile); |
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|
214 |
|
---|
215 |
}else{ |
---|
216 |
&writelog("ipodtranscode WINE TsSplitter.exe ;Not exist ${filenamebody}_HD.m2t"); |
---|
217 |
} |
---|
218 |
|
---|
219 |
} |
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
&changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG); |
---|
224 |
&writelog("ipodtranscode ffmpeg retry $filenamebody.264"); |
---|
225 |
system ("ffmpeg -y -i $trcnmpegfile $cropopt $ffmpegencopt"); |
---|
226 |
} |
---|
227 |
|
---|
228 |
if (! -e "$filenamebody.264"){ |
---|
229 |
|
---|
230 |
&changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG); |
---|
231 |
&writelog("ipodtranscode ffmpeg retry no crop $filenamebody.264"); |
---|
232 |
system ("ffmpeg -y -i $trcnmpegfile $ffmpegencopt"); |
---|
233 |
} |
---|
234 |
|
---|
235 |
if (! -e "$filenamebody.264"){ |
---|
236 |
} |
---|
237 |
|
---|
238 |
if (! -e "$filenamebody.264"){ |
---|
239 |
|
---|
240 |
&changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG); |
---|
241 |
&writelog("ipodtranscode ffmpeg retry No splited originalTS file $filenamebody.264"); |
---|
242 |
system ("ffmpeg -y -i $inputmpeg2 $ffmpegencopt"); |
---|
243 |
} |
---|
244 |
} |
---|
245 |
if ($filestatus <= $FILESTATUSTRANSCODEWAVE){ |
---|
246 |
|
---|
247 |
unlink("${filenamebody}.wav"); |
---|
248 |
&changefilestatus($pid,$FILESTATUSTRANSCODEWAVE); |
---|
249 |
&writelog("ipodtranscode mplayer $filenamebody.wav"); |
---|
250 |
system ("mplayer $trcnmpegfile -vc null -vo null -ao pcm:file=$filenamebody.wav:fast"); |
---|
251 |
|
---|
252 |
} |
---|
253 |
if ($filestatus <= $FILESTATUSTRANSCODEAAC){ |
---|
254 |
|
---|
255 |
unlink("${filenamebody}.aac"); |
---|
256 |
&changefilestatus($pid,$FILESTATUSTRANSCODEAAC); |
---|
257 |
if (-e "$toolpath/perl/tool/neroAacEnc"){ |
---|
258 |
if (-e "$filenamebody.wav"){ |
---|
259 |
&writelog("ipodtranscode neroAacEnc $filenamebody.wav"); |
---|
260 |
system ("$toolpath/perl/tool/neroAacEnc -br 128000 -if $filenamebody.wav -of $filenamebody.aac"); |
---|
261 |
}else{ |
---|
262 |
&writelog("ipodtranscode ERR Not Found $filenamebody.wav"); |
---|
263 |
} |
---|
264 |
}else{ |
---|
265 |
|
---|
266 |
&writelog("ipodtranscode faac $filenamebody.wav"); |
---|
267 |
system ("faac -b 128 -o $filenamebody.aac $filenamebody.wav "); |
---|
268 |
} |
---|
269 |
|
---|
270 |
} |
---|
271 |
if ($filestatus <= $FILESTATUSTRANSCODEMP4BOX){ |
---|
272 |
|
---|
273 |
unlink("${filenamebody}.base.mp4"); |
---|
274 |
|
---|
275 |
|
---|
276 |
if ($inputmpeg2 =~ /aac$/i){ |
---|
277 |
if (-e "$toolpath/perl/tool/MP4Box"){ |
---|
278 |
&writelog("ipodtranscode MP4Box $filenamebody"); |
---|
279 |
system ("cd $recfolderpath ;$toolpath/perl/tool/MP4Box -add $filenamebody.aac -new $filenamebody.base.mp4"); |
---|
280 |
$exit_value = $? >> 8; |
---|
281 |
$signal_num = $? & 127; |
---|
282 |
$dumped_core = $? & 128; |
---|
283 |
&writelog("ipodtranscode DEBUG MP4Box -add $filenamebody.aac -new $filenamebody.base.mp4:$exit_value:$signal_num:$dumped_core"); |
---|
284 |
}else{ |
---|
285 |
&writelog("ipodtranscode WARN; Pls. install $toolpath/perl/tool/MP4Box"); |
---|
286 |
} |
---|
287 |
}else{ |
---|
288 |
|
---|
289 |
if (-e "$toolpath/perl/tool/MP4Box"){ |
---|
290 |
&changefilestatus($pid,$FILESTATUSTRANSCODEMP4BOX); |
---|
291 |
&writelog("ipodtranscode MP4Box $filenamebody"); |
---|
292 |
system ("cd $recfolderpath ;$toolpath/perl/tool/MP4Box -fps 29.97 -add $filenamebody.264 -new $filenamebody.base.mp4"); |
---|
293 |
$exit_value = $? >> 8; |
---|
294 |
$signal_num = $? & 127; |
---|
295 |
$dumped_core = $? & 128; |
---|
296 |
&writelog("ipodtranscode DEBUG MP4Box -fps 29.97 -add $filenamebody.264 -new $filenamebody.base.mp4:$exit_value:$signal_num:$dumped_core"); |
---|
297 |
if (-e "$filenamebody.base.mp4"){ |
---|
298 |
system ("cd $recfolderpath ;$toolpath/perl/tool/MP4Box -add $filenamebody.aac $filenamebody.base.mp4"); |
---|
299 |
$exit_value = $? >> 8; |
---|
300 |
$signal_num = $? & 127; |
---|
301 |
$dumped_core = $? & 128; |
---|
302 |
&writelog("ipodtranscode DEBUG MP4Box -add $filenamebody.aac:$exit_value:$signal_num:$dumped_core"); |
---|
303 |
}else{ |
---|
304 |
$filelist = `ls -lhtr $recfolderpath/${filenamebody}*`; |
---|
305 |
$debugenv = `env`; |
---|
306 |
&writelog("ipodtranscode ERR File not exist.$debugenv.$filelist ;$filenamebody.base.mp4;$filelist;cd $recfolderpath ;$toolpath/perl/tool/MP4Box -fps 29.97 -add $filenamebody.264 -new $filenamebody.base.mp4"); |
---|
307 |
} |
---|
308 |
}else{ |
---|
309 |
&writelog("ipodtranscode WARN; Pls. install $toolpath/perl/tool/MP4Box"); |
---|
310 |
} |
---|
311 |
unlink("$filenamebody.aac"); |
---|
312 |
} |
---|
313 |
|
---|
314 |
|
---|
315 |
|
---|
316 |
|
---|
317 |
if (-e "$toolpath/perl/tool/MP4Box"){ |
---|
318 |
|
---|
319 |
|
---|
320 |
&writelog("ipodtranscode ATOM $filenamebody"); |
---|
321 |
|
---|
322 |
|
---|
323 |
system ("cd $recfolderpath ; $toolpath/perl/tool/MP4Box -ipod $filenamebody.base.mp4"); |
---|
324 |
$exit_value = $? >> 8; |
---|
325 |
$signal_num = $? & 127; |
---|
326 |
$dumped_core = $? & 128; |
---|
327 |
&writelog("ipodtranscode DEBUG MP4Box -ipod $filenamebody.base.mp4:$exit_value:$signal_num:$dumped_core"); |
---|
328 |
if (-e "$filenamebody.base.mp4"){ |
---|
329 |
unlink("${mp4outdir}MAQ${mp4filenamestring}.MP4"); |
---|
330 |
system("mv $filenamebody.base.mp4 ${mp4outdir}MAQ${mp4filenamestring}.MP4"); |
---|
331 |
&writelog("ipodtranscode mv $filenamebody.base.mp4 ${mp4outdir}MAQ${mp4filenamestring}.MP4"); |
---|
332 |
}else{ |
---|
333 |
&writelog("ipodtranscode ERR $filenamebody.base.mp4 Not found."); |
---|
334 |
} |
---|
335 |
|
---|
336 |
}else{ |
---|
337 |
&writelog("ipodtranscode WARN; Pls. install $toolpath/perl/tool/MP4Box"); |
---|
338 |
} |
---|
339 |
} |
---|
340 |
if ($filestatus <= $FILESTATUSTRANSCODECOMPLETE){ |
---|
341 |
if (-e "${mp4outdir}MAQ${mp4filenamestring}.MP4"){ |
---|
342 |
|
---|
343 |
&changefilestatus($pid,$FILESTATUSTRANSCODECOMPLETE); |
---|
344 |
&updatemp4file(); |
---|
345 |
}else{ |
---|
346 |
&writelog("ipodtranscode ERR ; Fail.Giving up! MAQ${mp4filenamestring}.MP4"); |
---|
347 |
&changefilestatus($pid,999); |
---|
348 |
} |
---|
349 |
unlink("${filenamebody}_HD.m2t"); |
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 |
|
---|
357 |
|
---|
358 |
|
---|
359 |
|
---|
360 |
|
---|
361 |
unlink("${filenamebody}_tss.m2t"); |
---|
362 |
unlink("$filenamebody.264"); |
---|
363 |
unlink("$filenamebody.wav"); |
---|
364 |
unlink("$filenamebody.base.mp4"); |
---|
365 |
|
---|
366 |
} |
---|
367 |
|
---|
368 |
}else{ |
---|
369 |
|
---|
370 |
|
---|
371 |
if ($aspect == 16){ |
---|
372 |
$cropopt = " -croptop 70 -cropbottom 60 -cropleft 8 -cropright 14 -aspect 16:9 "; |
---|
373 |
}else{ |
---|
374 |
$cropopt = " -croptop 8 -cropbottom 8 -cropleft 8 -cropright 14 "; |
---|
375 |
} |
---|
376 |
|
---|
377 |
if (($trconqty eq "")||($trconqty == 1)){ |
---|
378 |
|
---|
379 |
$mp4file = "${mp4outdir}M4V${mp4filenamestring}.MP4"; |
---|
380 |
$encodeoption = "-y -i $inputmpeg2 vcodec libxvid $cropopt -s 320x240 -b 300 -bt 128 -r 14.985 -deinterlace -acodec libfaac -f ipod ${mp4outdir}M4V${mp4filenamestring}.MP4"; |
---|
381 |
|
---|
382 |
|
---|
383 |
|
---|
384 |
}elsif($trconqty == 2){ |
---|
385 |
|
---|
386 |
$mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
387 |
$encodeoption = "-y -i $inputmpeg2 -vcodec libx264 -croptop 8 $cropopt -s 320x240 -b 300 -bt 128 -r 24 -deinterlace -acodec libfaac -f ipod ${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
388 |
|
---|
389 |
|
---|
390 |
|
---|
391 |
}elsif($trconqty == 3){ |
---|
392 |
|
---|
393 |
$mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
394 |
$encodeoption = "-y -i $inputmpeg2 -vcodec libx264 $cropopt -s 320x240 -b 380 -bt 128 -r 29.97 -deinterlace -acodec libfaac -f ipod ${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
395 |
|
---|
396 |
|
---|
397 |
|
---|
398 |
}elsif($trconqty == 4){ |
---|
399 |
|
---|
400 |
$mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
401 |
$encodeoption = "-y -i $inputmpeg2 -vcodec libx264 $cropopt -s 640x480 -b 500 -maxrate 700 -bt 128 -r 29.97 -deinterlace -acodec libfaac -f ipod ${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
402 |
|
---|
403 |
|
---|
404 |
|
---|
405 |
}elsif($trconqty == 5){ |
---|
406 |
|
---|
407 |
$mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
408 |
$encodeoption = "-y -i $inputmpeg2 -vcodec libx264 -croptop 8 $cropopt -s 640x480 -b 500 -maxrate 700 -bt 128 -r 29.97 -deinterlace -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -acodec libfaac -f ipod ${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
409 |
|
---|
410 |
|
---|
411 |
|
---|
412 |
} |
---|
413 |
|
---|
414 |
$encodeoptionlog = $encodeoption; |
---|
415 |
Jcode::convert(\$encodeoptionlog,'euc'); |
---|
416 |
|
---|
417 |
&writelog("ipodtranscode START QTY=$trconqty $encodeoptionlog"); |
---|
418 |
|
---|
419 |
&changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG); |
---|
420 |
system ("ffmpeg $encodeoption "); |
---|
421 |
&writelog("ipodtranscode FFEND $inputmpeg2"); |
---|
422 |
&changefilestatus($pid,$FILESTATUSTRANSCODECOMPLETE); |
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 |
|
---|
428 |
&updatemp4file(); |
---|
429 |
} |
---|
430 |
|
---|
431 |
$counttranscodefiles = &counttranscodefiles(); |
---|
432 |
|
---|
433 |
|
---|
434 |
|
---|
435 |
|
---|
436 |
|
---|
437 |
}else{ |
---|
438 |
&writelog("ipodtranscode NO $inputmpeg2 file.Skip."); |
---|
439 |
} |
---|
440 |
|
---|
441 |
} |
---|
442 |
|
---|
443 |
&writelog("ipodtranscode ALL COMPLETE"); |
---|
444 |
exit; |
---|
445 |
|
---|
446 |
|
---|
447 |
|
---|
448 |
sub mp4filenamestringbuild(){ |
---|
449 |
|
---|
450 |
|
---|
451 |
my @mpegfilename = split(/\./,$dbparam[2]) ; |
---|
452 |
my $pspfilname = "-".$mpegfilename[0] ; |
---|
453 |
return("$pspfilname"); |
---|
454 |
} |
---|
455 |
|
---|
456 |
|
---|
457 |
sub makethumbnail(){ |
---|
458 |
|
---|
459 |
my $outputfilename = $inputmpeg2 ; |
---|
460 |
my $thmfilename = "MAQ${mp4filenamestring}.THM"; |
---|
461 |
&writelog("ipodtranscode DEBUG thmfilename $thmfilename"); |
---|
462 |
|
---|
463 |
|
---|
464 |
|
---|
465 |
|
---|
466 |
if($outputfilename =~ /.m2t$/){ |
---|
467 |
|
---|
468 |
system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -vf framestep=300step,scale=160:90,expand=160:120 -frames 1 $outputfilename"); |
---|
469 |
&writelog("ipodtranscode DEBUG mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -vf framestep=300step,scale=160:90,expand=160:120 -frames 1 $outputfilename"); |
---|
470 |
}else{ |
---|
471 |
|
---|
472 |
system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -vf framestep=300step,scale=165:126,crop=160:120 -frames 1 $outputfilename"); |
---|
473 |
&writelog("ipodtranscode DEBUG mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -vf framestep=300step,scale=165:126,crop=160:120 -frames 1 $outputfilename"); |
---|
474 |
} |
---|
475 |
|
---|
476 |
|
---|
477 |
|
---|
478 |
|
---|
479 |
|
---|
480 |
|
---|
481 |
|
---|
482 |
|
---|
483 |
|
---|
484 |
|
---|
485 |
|
---|
486 |
system("mv $pspdirname/00000001.jpg $pspdirname/$thmfilename"); |
---|
487 |
|
---|
488 |
} |
---|
489 |
|
---|
490 |
sub updatemp4file(){ |
---|
491 |
my $mp4filename = "MAQ${mp4filenamestring}.MP4"; |
---|
492 |
|
---|
493 |
if (-e "${mp4outdir}MAQ${mp4filenamestring}.MP4"){ |
---|
494 |
|
---|
495 |
$sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.1'}); |
---|
496 |
$sth->execute($mp4filename, $pid); |
---|
497 |
&writelog("ipodtranscode UPDATEsubtitleDB $stmt{'ipodtranscode.updatemp4file.1'}"); |
---|
498 |
|
---|
499 |
|
---|
500 |
$sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.2'}); |
---|
501 |
$sth->execute($tid, $mp4filename); |
---|
502 |
&writelog("ipodtranscode UPDATEmp4DB $stmt{'ipodtranscode.updatemp4file.2'}"); |
---|
503 |
|
---|
504 |
&changefilestatus($pid,$FILESTATUSALLCOMPLETE); |
---|
505 |
}else{ |
---|
506 |
&writelog("ipodtranscode ERR MP4 NOT EXIST $pid/$mp4filename"); |
---|
507 |
} |
---|
508 |
|
---|
509 |
|
---|
510 |
} |
---|
511 |
|
---|
512 |
sub counttranscodefiles(){ |
---|
513 |
$sth = $dbh->prepare($stmt{'ipodtranscode.counttranscodefiles.1'}); |
---|
514 |
$sth->execute($FILESTATUSRECEND, $FILESTATUSTRANSCODECOMPLETE); |
---|
515 |
my @titlecount= $sth->fetchrow_array; |
---|
516 |
|
---|
517 |
return ($titlecount[0]); |
---|
518 |
|
---|
519 |
|
---|
520 |
} |
---|
521 |
|
---|
522 |
|
---|
523 |
sub validationsplitfile{ |
---|
524 |
my $inputmpeg2 = $_[0]; |
---|
525 |
my $trcnmpegfile = $_[1]; |
---|
526 |
|
---|
527 |
|
---|
528 |
my $filesizeoriginal = -s $inputmpeg2 ; |
---|
529 |
my $filesizesplit = -s $trcnmpegfile; |
---|
530 |
my $validation = 0; |
---|
531 |
if ($filesizesplit > 0){ |
---|
532 |
$validation = $filesizeoriginal / $filesizesplit ; |
---|
533 |
if ($validation > 2 ){ |
---|
534 |
|
---|
535 |
&writelog("ipodtranscode ERR File split may be fail: $filesizeoriginal:$filesizesplit"); |
---|
536 |
$trcnmpegfile = $inputmpeg2 ; |
---|
537 |
unlink("${filenamebody}_tss.m2t"); |
---|
538 |
unlink("${filenamebody}_HD.m2tt"); |
---|
539 |
return ($trcnmpegfile); |
---|
540 |
}else{ |
---|
541 |
|
---|
542 |
return ($trcnmpegfile); |
---|
543 |
} |
---|
544 |
}else{ |
---|
545 |
|
---|
546 |
&writelog("ipodtranscode ERR File split may be fail: $filesizeoriginal:$filesizesplit"); |
---|
547 |
$trcnmpegfile = $inputmpeg2 ; |
---|
548 |
unlink("${filenamebody}_tss.m2t"); |
---|
549 |
unlink("${filenamebody}_HD.m2tt"); |
---|
550 |
return ($trcnmpegfile); |
---|
551 |
} |
---|
552 |
} |
---|
553 |
|
---|