root/trunk/install/perl/ipodtranscode.pl

リビジョン 125, 22.4 kB (コミッタ: sorshi, コミット時期: 13 年 前)

MP4変換時に、
・tss.pyでHDストリーム分離
・それに失敗したらWINE経由でTsSplitter?.exeで分離
という工程を踏むように変更。
HDストリームのみのTSは変換終了後破棄。

  • svn:executable 属性の設定値: *
Line 
1 #!/usr/bin/perl
2 #usage ipodtranscode.pl
3 #
4 # Anime recording system foltia
5 # http://www.dcc-jpl.com/soft/foltia/
6 #
7 # iPod MPEG4/H.264トラコン
8 # ffmpegを呼び出して変換
9 #
10 # DCC-JPL Japan/foltia project
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 #$processes = $processes +  &processfind("ffmpeg");
29
30 if ($processes > 1 ){
31 &writelog("ipodtranscode processes exist. exit:");
32 exit;
33 }else{
34 #&writelog("ipodtranscode.pl  Normal launch.");
35 }
36
37 #DB初期化
38 $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
39
40 # タイトル取得
41 #トラコンフラグがたっていてステータス50以上150未満のファイルを古い順にひとつ探す
42 # 数数える
43 #$DBQuery =  "SELECT count(*) FROM foltia_subtitle, foltia_program, foltia_m2pfiles
44 #WHERE filestatus >= $FILESTATUSRECEND AND filestatus < $FILESTATUSTRANSCODECOMPLETE  AND foltia_program.tid = foltia_subtitle.TID AND foltia_program.PSP = 1  AND foltia_m2pfiles.m2pfilename = foltia_subtitle.m2pfilename  ";
45 #$sth = $dbh->prepare($DBQuery);
46 #$sth->execute();
47 #@titlecount= $sth->fetchrow_array;
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 #print "$dbparam[0],$dbparam[1],$dbparam[2],$dbparam[3],$dbparam[4],$dbparam[5]\n";
62 #&writelog("ipodtranscode DEBUG $DBQuery");
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]; # path付き
67 $mpeg2filename = $dbparam[2]; # pathなし
68 $filestatus = $dbparam[3];
69 $aspect = $dbparam[4];# 16,1 (超額縁),4,3
70 $countno = $dbparam[5];
71 $mp4filenamestring = &mp4filenamestringbuild($pid);
72
73 if (-e $inputmpeg2){#MPEG2ファイルが存在していれば
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         #EPG
98                 $movietitle = " -title \"$programtitle[2]\" ";
99                 $movietitleeuc = " -t \"$programtitle[2]\" ";
100         }else{# 0
101         #空白
102         $movietitle = "";
103         $movietitleeuc = "";
104         }
105 #Jcode::convert(\$movietitle,'utf8');# Title入れるとiTunes7.0.2がクラッシュする
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 #unlink
120 # Starlight breaker向けキャプチャ画像作成
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         # H.264出力
151         $trcnmpegfile = $inputmpeg2 ;
152         # アスペクト比
153         if ($aspect == 1){#超額縁
154         $cropopt = " -croptop 150 -cropbottom 150 -cropleft 200 -cropright 200 ";
155         }elsif($aspect == 4){#SD
156         $cropopt = " -croptop 6 -cropbottom 6 -cropleft 8 -cropright 8 ";
157         }else{#16:9
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 #       $ffmpegencopt = " -s 480x272 -deinterlace -r 29.97 -vcodec libx264 -g 300 -b 400000 -level 13 -loop 1 -sc_threshold 60 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -refs 3 -maxrate 700000 -async 50 -f h264 $filenamebody.264";
165 # for ffmpeg 0.5 or later
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){#640x352
168 #       $ffmpegencopt = " -s 640x352 -deinterlace -r 29.97 -vcodec libx264 -g 100 -b 600000 -level 13 -loop 1 -sc_threshold 60 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -refs 3 -maxrate 700000 -async 50 -f h264 $filenamebody.264";
169 # for ffmpeg 0.5 or later
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 #       &writelog("ipodtranscode ffmpeg $filenamebody.264");
174 #       system ("ffmpeg -y -i $trcnmpegfile $cropopt $ffmpegencopt");
175 #まずTsSplitする →ワンセグをソースにしてしまわないように
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                 # TsSplit
185 #               &writelog("ipodtranscode TsSplitter $inputmpeg2");
186 #               system("wine $toolpath/perl/tool/TsSplitter.exe  -EIT -ECM  -EMM -SD -1SEG -WAIT2 $inputmpeg2");
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                 #Splitファイルの確認
197                 $trcnmpegfile = &validationsplitfile($inputmpeg2,$trcnmpegfile);
198                 #tss.pyに失敗してたなら強制的にWINEでTsSplit.exe
199                 if($trcnmpegfile eq $inputmpeg2){
200                
201                 # TsSplit
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                         #Splitファイルの確認
207                         $trcnmpegfile = &validationsplitfile($inputmpeg2,$trcnmpegfile);
208 #                       if($trcnmpegfile ne $inputmpeg2){
209 #                       &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
210 #                       &writelog("ipodtranscode ffmpeg retry ; WINE TsSplitter.exe $trcnmpegfile");
211 #                       system ("ffmpeg -y -i $trcnmpegfile $cropopt $ffmpegencopt");
212 #                       }else{
213 #                       &writelog("ipodtranscode WINE TsSplit.exe fail");
214 #                       }
215                 }else{
216                 &writelog("ipodtranscode WINE TsSplitter.exe ;Not exist ${filenamebody}_HD.m2t");
217                 }#endif -e ${filenamebody}_HD.m2t
218                 
219                 }#endif $trcnmpegfile eq $inputmpeg2
220                 
221                
222                 #再ffmpeg
223                 &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
224                 &writelog("ipodtranscode ffmpeg retry $filenamebody.264");
225                 system ("ffmpeg -y -i $trcnmpegfile $cropopt $ffmpegencopt");
226         }
227         #もしエラーになったらcropやめる
228         if (! -e "$filenamebody.264"){
229                 #再ffmpeg
230                 &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
231                 &writelog("ipodtranscode ffmpeg retry no crop $filenamebody.264");
232                 system ("ffmpeg -y -i $trcnmpegfile $ffmpegencopt");
233         }
234         #強制的にWINEでTsSplit.exe
235         if (! -e "$filenamebody.264"){
236         }
237         #それでもエラーならsplitしてないファイルをターゲットに
238         if (! -e "$filenamebody.264"){
239                 #再ffmpeg
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         # WAVE出力
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         # AAC変換
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         #print "DEBUG $toolpath/perl/tool/neroAacEnc\n\n";
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         # MP4ビルド
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 }#endif #デジタルラジオなら
313         
314 #}
315
316 #if ($filestatus <= $FILESTATUSTRANSCODEATOM){
317         if (-e "$toolpath/perl/tool/MP4Box"){
318                 # iPodヘッダ付加
319 #               &changefilestatus($pid,$FILESTATUSTRANSCODEATOM);
320                 &writelog("ipodtranscode ATOM $filenamebody");
321                 #system ("/usr/local/bin/ffmpeg -y -i $filenamebody.base.mp4 -vcodec copy -acodec copy -f ipod ${mp4outdir}MAQ${mp4filenamestring}.MP4");
322 #               system ("cd $recfolderpath ; MP4Box -ipod $filenamebody.base.mp4");
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         # ipodtranscode mv /home/foltia/php/tv/1329-21-20080829-0017.base.mp4 /home/foltia/php/tv/1329.localized/mp4/MAQ-/home/foltia/php/tv/1329-21-20080829-0017.MP4
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 # ConfigによってTSファイルは常にsplitした状態にするかどうか選択
351 # B25失敗したときにここが走るとファイルぶっ壊れるので検証を入れる
352 #
353 #       if (-e "${filenamebody}_tss.m2t"){
354 #               unlink("${filenamebody}.m2t");
355 #               unless (rename "${filenamebody}_tss.m2t", "${filenamebody}.m2t") {
356 #               &writelog("ipodtranscode WARNING RENAME FAILED ${filenamebody}_tss.m2t ${filenamebody}.m2t");
357 #               }else{
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         #print "MPEG2\n";
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 #$encodeoption = "-y -i $inputmpeg2 -vcodec xvid $cropopt -s 320x240 -b 300 -bt 128 -r 14.985 -bufsize 192 -maxrate 512 -minrate 0 -deinterlace -acodec aac -ab 128 -ar 24000 -ac 2 $movietitle ${mp4outdir}M4V${mp4filenamestring}.MP4";
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 #time ffmpeg -y  -i /home/foltia/php/tv/trcntest/nanoha-As-op.mpg -vcodec libxvid -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 -s 320x240 -b 300 -bt 128 -r 14.985 -deinterlace -acodec libfaac -f ipod M4V-Nanoha-As-OP.MP4
382 # 32sec
383 # 2.1MB
384 }elsif($trconqty == 2){
385 #$encodeoption = "-y -i $inputmpeg2  -target ipod -profile 51 -level 30 $cropopt -s 320x240 -b 300 -r 24 -acodec aac -ar 32000 -ac 2 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4";
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 #time ffmpeg -y  -i /home/foltia/php/tv/trcntest/nanoha-As-op.mpg -vcodec libx264 -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 -s 320x240 -b 300 -bt 128 -r 24 -deinterlace -acodec libfaac -f ipod MAQ-Nanoha-As-OP.MP4
389 # 2min22sec
390 # 6.4MB
391 }elsif($trconqty == 3){
392 #$encodeoption = "-y -i $inputmpeg2  -target ipod -profile 51 -level 30 $cropopt  -acodec aac -ab 96 -vcodec h264  -maxrate 700 -minrate 0 -deinterlace -b 300 -ar 32000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 320x240 -r 30000/1001  -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4";
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 #time ffmpeg -y  -i /home/foltia/php/tv/trcntest/nanoha-As-op.mpg -vcodec libx264 -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 -s 320x240 -b 380 -bt 128 -r 29.97 -deinterlace -acodec libfaac -f ipod MAQ-Nanoha-As-OP.MP4
396 #  2m53.912s
397 # 7MB
398 }elsif($trconqty == 4){
399 #$encodeoption = "-y -i $inputmpeg2  -target ipod -profile 51 -level 30 $cropopt -s 480x360 -b 400 -r 24 -acodec aac -ar 32000 -ac 2 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4";
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 #time ffmpeg -y  -i /home/foltia/php/tv/trcntest/nanoha-As-op.mpg -vcodec libx264 -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 -s 640x480 -b 500  -maxrate 700 -bt 128 -r 29.97 -deinterlace -acodec libfaac -f ipod MAQ-Nanoha-As-OP.MP4
403 # 11m0.294s
404 # 20MB
405 }elsif($trconqty == 5){
406 #$encodeoption = "-y -i $inputmpeg2  -target ipod -profile 51 -level 30 $cropopt  -acodec aac -ab 96 -vcodec h264  -maxrate 700 -minrate 0 -deinterlace -b 400 -ar 32000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 480x360 -r 30000/1001  -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4";
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 #time ffmpeg -y  -i /home/foltia/php/tv/trcntest/nanoha-As-op.mpg -vcodec libx264 -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 -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 MAQ-Nanoha-As-OP.MP4
410 #  14m14.033s
411 # 18MB
412 }
413
414 $encodeoptionlog = $encodeoption;
415 Jcode::convert(\$encodeoptionlog,'euc');
416
417 &writelog("ipodtranscode START QTY=$trconqty $encodeoptionlog");
418 #print "ffmpeg $encodeoptionlog \n";
419 &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
420 system ("ffmpeg  $encodeoption ");
421 &writelog("ipodtranscode FFEND $inputmpeg2");
422 &changefilestatus($pid,$FILESTATUSTRANSCODECOMPLETE);
423 #もう要らなくなった #2008/11/14
424 #&writelog("ipodtranscode mp4psp -p $mp4file $movietitleeuc");
425 #system("/usr/local/bin/mp4psp -p $mp4file '$movietitleeuc' ");
426 #&writelog("ipodtranscode mp4psp COMPLETE  $mp4file ");
427
428 &updatemp4file();
429 }#endif #デジタルかアナログか
430
431 $counttranscodefiles = &counttranscodefiles();
432 ############################
433 #一回で終らせるように
434 #exit;
435
436
437 }else{#ファイルがなければ
438 &writelog("ipodtranscode NO $inputmpeg2 file.Skip.");
439 }#end if
440
441 }# end while
442 #残りファイルがゼロなら
443 &writelog("ipodtranscode ALL COMPLETE");
444 exit;
445
446
447 #-----------------------------------------------------------------------
448 sub mp4filenamestringbuild(){
449 #ファイル名決定
450 #1329-19-20080814-2337.m2t
451 my @mpegfilename = split(/\./,$dbparam[2]) ;
452 my $pspfilname = "-".$mpegfilename[0] ;
453 return("$pspfilname");
454 }#end sub mp4filenamestringbuild
455
456
457 sub makethumbnail(){
458 #サムネール
459 my $outputfilename = $inputmpeg2 ;#フルパス
460 my $thmfilename = "MAQ${mp4filenamestring}.THM";
461 &writelog("ipodtranscode DEBUG thmfilename $thmfilename");
462
463 #system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $outputfilename");
464 #
465 #&writelog("ipodtranscode DEBUG mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $outputfilename");
466 if($outputfilename =~ /.m2t$/){
467 #ハイビジョンTS
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 #if (-e "$pspdirname/$thmfilename"){
476 #       $timestamp = strftime("%Y%m%d-%H%M%S", localtime);
477 #chomp $timestamp;
478 #       system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename".$timestamp.".THM");
479 #}else{
480 #       system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename");
481 #}
482 #&writelog("ipodtranscode DEBUG convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename");
483
484 #system("rm -rf $pspdirname/0000000*.jpg ");
485 #&writelog("ipodtranscode DEBUG rm -rf $pspdirname/0000000*.jpg");
486 system("mv $pspdirname/00000001.jpg $pspdirname/$thmfilename");
487
488 }#endsub makethumbnail
489
490 sub updatemp4file(){
491 my $mp4filename = "MAQ${mp4filenamestring}.MP4";
492
493 if (-e "${mp4outdir}MAQ${mp4filenamestring}.MP4"){
494 # MP4ファイル名をPIDレコードに書き込み
495         $sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.1'});
496         $sth->execute($mp4filename, $pid);
497         &writelog("ipodtranscode UPDATEsubtitleDB $stmt{'ipodtranscode.updatemp4file.1'}");
498
499 # MP4ファイル名をfoltia_mp4files挿入
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 }#updatemp4file
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 }#end sub counttranscodefiles
521
522
523 sub validationsplitfile{
524 my $inputmpeg2 = $_[0];
525 my $trcnmpegfile = $_[1];
526
527                 #Split結果確認
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                                 #print "Fail split may be fail.\n";
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                                 #print "Fail split may be good.\n";
542                                 return ($trcnmpegfile);
543                         }
544                 }else{
545                 #Fail
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 }#end sub validationsplitfile
553
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed