root/trunk/install/perl/ipodtranscode.pl

リビジョン 97, 19.5 kB (コミッタ: sorshi, コミット時期: 15 年 前)

radiko録音対応

  • 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 &writelog("ipodtranscode DEBUG mp4filenamestring $mp4filenamestring");
74 #展開ディレクトリ作成
75 $pspdirname = &makemp4dir($tid);
76 $mp4outdir = $pspdirname ;
77 # 実際のトラコン
78 # タイトル取得
79 if ($pid ne ""){
80         $sth = $dbh->prepare($stmt{'ipodtranscode.2'});
81         $sth->execute($pid);
82 @programtitle = $sth->fetchrow_array;
83 $programtitle[0] =~ s/\"/\\"/gi;
84 $programtitle[2] =~ s/\"/\\"/gi;
85
86         if ($pid > 0){
87                 if ($programtitle[1] ne ""){
88                         $movietitle = " -title \"$programtitle[0] 第$programtitle[1]話 $programtitle[2]\" ";
89                         $movietitleeuc = " -t \"$programtitle[0] 第$programtitle[1]話 $programtitle[2]\" ";
90                 }else{
91                         $movietitle = " -title \"$programtitle[0] $programtitle[2]\" ";
92                         $movietitleeuc = " -t \"$programtitle[0] $programtitle[2]\" ";
93                 }
94         }elsif($pid < 0){
95         #EPG
96                 $movietitle = " -title \"$programtitle[2]\" ";
97                 $movietitleeuc = " -t \"$programtitle[2]\" ";
98         }else{# 0
99         #空白
100         $movietitle = "";
101         $movietitleeuc = "";
102         }
103 #Jcode::convert(\$movietitle,'utf8');# Title入れるとiTunes7.0.2がクラッシュする
104         $movietitle = "";
105         $movietitleeuc = "";
106
107 }
108
109 if ($filestatus <= $FILESTATUSRECEND){
110 }
111
112 if ($filestatus <= $FILESTATUSWAITINGCAPTURE){
113 #なにもしない
114 }
115
116 if ($filestatus <= $FILESTATUSCAPTURE){
117 #unlink
118 # Starlight breaker向けキャプチャ画像作成
119 if (-e "$toolpath/perl/captureimagemaker.pl"){
120         &writelog("ipodtranscode Call captureimagemaker $mpeg2filename");
121 &changefilestatus($pid,$FILESTATUSCAPTURE);
122         system ("$toolpath/perl/captureimagemaker.pl $mpeg2filename");
123 &changefilestatus($pid,$FILESTATUSCAPEND);
124 }
125 }
126
127 if ($filestatus <= $FILESTATUSCAPEND){
128 # サムネイル作る
129 &makethumbnail();
130 &changefilestatus($pid,$FILESTATUSTHMCREATE);
131 }
132
133 if ($filestatus <= $FILESTATUSWAITINGTRANSCODE){
134 }
135
136 $filenamebody = $inputmpeg2 ;
137 $filenamebody =~ s/.m2t$|.ts$|.m2p$|.mpg$|.aac$//gi;
138
139 #デジタルかアナログか
140 if ($inputmpeg2 =~ /m2t$|ts$|aac$/i){
141
142 if ($filestatus <= $FILESTATUSTRANSCODETSSPLITTING){
143                 unlink("${filenamebody}_tss.m2t");
144                 unlink("${filenamebody}_HD.m2t");
145 }
146 if ($filestatus <= $FILESTATUSTRANSCODEFFMPEG){
147
148         # H.264出力
149         $trcnmpegfile = $inputmpeg2 ;
150         # アスペクト比
151         if ($aspect == 1){#超額縁
152         $cropopt = " -croptop 150 -cropbottom 150 -cropleft 200 -cropright 200 ";
153         }elsif($aspect == 4){#SD
154         $cropopt = " -croptop 6 -cropbottom 6 -cropleft 8 -cropright 8 ";
155         }else{#16:9
156         $cropopt = " -croptop 6 -cropbottom 6 -cropleft 8 -cropright 8 ";
157         }
158         # クオリティごとに
159         if (($trconqty eq "")||($trconqty == 1)){
160         $ffmpegencopt = " -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";
161         }elsif($trconqty == 2){
162 #       $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";
163 # for ffmpeg 0.5 or later
164         $ffmpegencopt = " -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";
165         }elsif($trconqty == 3){#640x352
166 #       $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";
167 # for ffmpeg 0.5 or later
168         $ffmpegencopt = " -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";
169         }
170         &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
171         &writelog("ipodtranscode ffmpeg $filenamebody.264");
172         system ("ffmpeg -y -i $trcnmpegfile $cropopt $ffmpegencopt");
173        
174         #もしエラーになったらTsSplitする
175         if (! -e "$filenamebody.264"){
176                 &changefilestatus($pid,$FILESTATUSTRANSCODETSSPLITTING);
177                 unlink("${filenamebody}_tss.m2t");
178                 unlink("${filenamebody}_HD.m2t");
179                 if (-e "$toolpath/perl/tool/tss.py"){
180                 &writelog("ipodtranscode tss $inputmpeg2");
181                 system("$toolpath/perl/tool/tss.py $inputmpeg2");
182                
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                 #再ffmpeg
197                 &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
198                 &writelog("ipodtranscode ffmpeg retry $filenamebody.264");
199                 system ("ffmpeg -y -i $trcnmpegfile $cropopt $ffmpegencopt");
200         }
201         #もしエラーになったらcropやめる
202         if (! -e "$filenamebody.264"){
203                 #再ffmpeg
204                 &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
205                 &writelog("ipodtranscode ffmpeg retry no crop $filenamebody.264");
206                 system ("ffmpeg -y -i $trcnmpegfile $ffmpegencopt");
207         }
208 }
209 if ($filestatus <= $FILESTATUSTRANSCODEWAVE){
210         # WAVE出力
211         unlink("${filenamebody}.wav");
212         &changefilestatus($pid,$FILESTATUSTRANSCODEWAVE);
213         &writelog("ipodtranscode mplayer $filenamebody.wav");
214         system ("mplayer $trcnmpegfile -vc null -vo null -ao pcm:file=$filenamebody.wav:fast");
215
216 }
217 if ($filestatus <= $FILESTATUSTRANSCODEAAC){
218         # AAC変換
219         unlink("${filenamebody}.aac");
220         &changefilestatus($pid,$FILESTATUSTRANSCODEAAC);
221         if (-e "$toolpath/perl/tool/neroAacEnc"){
222                 if (-e "$filenamebody.wav"){
223         &writelog("ipodtranscode neroAacEnc $filenamebody.wav");
224         system ("$toolpath/perl/tool/neroAacEnc -br 128000  -if $filenamebody.wav  -of $filenamebody.aac");
225                 }else{
226                 &writelog("ipodtranscode ERR Not Found $filenamebody.wav");
227                 }
228         }else{
229         #print "DEBUG $toolpath/perl/tool/neroAacEnc\n\n";
230         &writelog("ipodtranscode faac $filenamebody.wav");
231         system ("faac -b 128  -o $filenamebody.aac $filenamebody.wav ");
232         }
233
234 }
235 if ($filestatus <= $FILESTATUSTRANSCODEMP4BOX){
236
237 unlink("${filenamebody}.base.mp4");
238
239 #デジタルラジオなら
240 if ($inputmpeg2 =~ /aac$/i){
241         if (-e "$toolpath/perl/tool/MP4Box"){
242                 &writelog("ipodtranscode MP4Box $filenamebody");
243                 system ("cd $recfolderpath ;$toolpath/perl/tool/MP4Box -add $filenamebody.aac  -new $filenamebody.base.mp4");
244         $exit_value = $? >> 8;
245         $signal_num = $? & 127;
246         $dumped_core = $? & 128;
247         &writelog("ipodtranscode DEBUG MP4Box -add $filenamebody.aac  -new $filenamebody.base.mp4:$exit_value:$signal_num:$dumped_core");
248         }else{
249                 &writelog("ipodtranscode WARN; Pls. install $toolpath/perl/tool/MP4Box");
250         }
251 }else{
252         # MP4ビルド
253         if (-e "$toolpath/perl/tool/MP4Box"){
254                 &changefilestatus($pid,$FILESTATUSTRANSCODEMP4BOX);
255                 &writelog("ipodtranscode MP4Box $filenamebody");
256                 system ("cd $recfolderpath ;$toolpath/perl/tool/MP4Box -fps 29.97 -add $filenamebody.264 -new $filenamebody.base.mp4");
257         $exit_value = $? >> 8;
258         $signal_num = $? & 127;
259         $dumped_core = $? & 128;
260         &writelog("ipodtranscode DEBUG MP4Box -fps 29.97 -add $filenamebody.264 -new $filenamebody.base.mp4:$exit_value:$signal_num:$dumped_core");
261                 if (-e "$filenamebody.base.mp4"){
262                 system ("cd $recfolderpath ;$toolpath/perl/tool/MP4Box -add $filenamebody.aac $filenamebody.base.mp4");
263         $exit_value = $? >> 8;
264         $signal_num = $? & 127;
265         $dumped_core = $? & 128;
266         &writelog("ipodtranscode DEBUG MP4Box -add $filenamebody.aac:$exit_value:$signal_num:$dumped_core");
267                 }else{
268                 $filelist = `ls -lhtr $recfolderpath/${filenamebody}*`;
269                 $debugenv = `env`;
270                 &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");
271                 }
272         }else{
273                 &writelog("ipodtranscode WARN; Pls. install $toolpath/perl/tool/MP4Box");
274         }
275 unlink("$filenamebody.aac");
276 }#endif #デジタルラジオなら
277         
278 #}
279
280 #if ($filestatus <= $FILESTATUSTRANSCODEATOM){
281         if (-e "$toolpath/perl/tool/MP4Box"){
282                 # iPodヘッダ付加
283 #               &changefilestatus($pid,$FILESTATUSTRANSCODEATOM);
284                 &writelog("ipodtranscode ATOM $filenamebody");
285                 #system ("/usr/local/bin/ffmpeg -y -i $filenamebody.base.mp4 -vcodec copy -acodec copy -f ipod ${mp4outdir}MAQ${mp4filenamestring}.MP4");
286 #               system ("cd $recfolderpath ; MP4Box -ipod $filenamebody.base.mp4");
287                 system ("cd $recfolderpath ; $toolpath/perl/tool/MP4Box -ipod $filenamebody.base.mp4");
288         $exit_value = $? >> 8;
289         $signal_num = $? & 127;
290         $dumped_core = $? & 128;
291         &writelog("ipodtranscode DEBUG MP4Box -ipod $filenamebody.base.mp4:$exit_value:$signal_num:$dumped_core");
292                 if (-e "$filenamebody.base.mp4"){
293                 unlink("${mp4outdir}MAQ${mp4filenamestring}.MP4");
294                 system("mv $filenamebody.base.mp4 ${mp4outdir}MAQ${mp4filenamestring}.MP4");
295                 &writelog("ipodtranscode mv $filenamebody.base.mp4 ${mp4outdir}MAQ${mp4filenamestring}.MP4");
296                 }else{
297                 &writelog("ipodtranscode ERR $filenamebody.base.mp4 Not found.");
298                 }
299         # 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
300         }else{
301                 &writelog("ipodtranscode WARN; Pls. install $toolpath/perl/tool/MP4Box");
302         }
303 }
304 if ($filestatus <= $FILESTATUSTRANSCODECOMPLETE){
305         if (-e "${mp4outdir}MAQ${mp4filenamestring}.MP4"){
306         # 中間ファイル消す
307         &changefilestatus($pid,$FILESTATUSTRANSCODECOMPLETE);
308         unlink("${filenamebody}_HD.m2t");
309         unlink("${filenamebody}_tss.m2t");
310         unlink("$filenamebody.264");
311         unlink("$filenamebody.wav");
312         unlink("$filenamebody.base.mp4");
313        
314         &updatemp4file();
315         }else{
316                 &writelog("ipodtranscode ERR ; Fail MAQ${mp4filenamestring}.MP4");
317         }
318 }
319
320 }else{ #デジタルかアナログか
321         #print "MPEG2\n";
322         # アスペクト比
323         if ($aspect == 16){
324         $cropopt = " -croptop 70 -cropbottom 60 -cropleft  8 -cropright 14 -aspect 16:9 ";
325         }else{
326         $cropopt = " -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 ";
327         }
328 # クオリティごとに
329 if (($trconqty eq "")||($trconqty == 1)){
330 #$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";
331 $mp4file = "${mp4outdir}M4V${mp4filenamestring}.MP4";
332 $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";
333 #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
334 # 32sec
335 # 2.1MB
336 }elsif($trconqty == 2){
337 #$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";
338 $mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4";
339 $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";
340 #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
341 # 2min22sec
342 # 6.4MB
343 }elsif($trconqty == 3){
344 #$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";
345 $mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4";
346 $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";
347 #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
348 #  2m53.912s
349 # 7MB
350 }elsif($trconqty == 4){
351 #$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";
352 $mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4";
353 $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";
354 #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
355 # 11m0.294s
356 # 20MB
357 }elsif($trconqty == 5){
358 #$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";
359 $mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4";
360 $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";
361 #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
362 #  14m14.033s
363 # 18MB
364 }
365
366 $encodeoptionlog = $encodeoption;
367 Jcode::convert(\$encodeoptionlog,'euc');
368
369 &writelog("ipodtranscode START QTY=$trconqty $encodeoptionlog");
370 #print "ffmpeg $encodeoptionlog \n";
371 &changefilestatus($pid,$FILESTATUSTRANSCODEFFMPEG);
372 system ("ffmpeg  $encodeoption ");
373 &writelog("ipodtranscode FFEND $inputmpeg2");
374 &changefilestatus($pid,$FILESTATUSTRANSCODECOMPLETE);
375 #もう要らなくなった #2008/11/14
376 #&writelog("ipodtranscode mp4psp -p $mp4file $movietitleeuc");
377 #system("/usr/local/bin/mp4psp -p $mp4file '$movietitleeuc' ");
378 #&writelog("ipodtranscode mp4psp COMPLETE  $mp4file ");
379
380 &updatemp4file();
381 }#endif #デジタルかアナログか
382
383 $counttranscodefiles = &counttranscodefiles();
384 ############################
385 #一回で終らせるように
386 #exit;
387 }# end while
388 #残りファイルがゼロなら
389 &writelog("ipodtranscode ALL COMPLETE");
390 exit;
391
392 #-----------------------------------------------------------------------
393 sub mp4filenamestringbuild(){
394 #ファイル名決定
395 #1329-19-20080814-2337.m2t
396 my @mpegfilename = split(/\./,$dbparam[2]) ;
397 my $pspfilname = "-".$mpegfilename[0] ;
398 return("$pspfilname");
399 }#end sub mp4filenamestringbuild
400
401
402 sub makethumbnail(){
403 #サムネール
404 my $outputfilename = $inputmpeg2 ;#フルパス
405 my $thmfilename = "MAQ${mp4filenamestring}.THM";
406 &writelog("ipodtranscode DEBUG thmfilename $thmfilename");
407
408 #system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $outputfilename");
409 #
410 #&writelog("ipodtranscode DEBUG mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $outputfilename");
411 if($outputfilename =~ /.m2t$/){
412 #ハイビジョンTS
413 system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -vf framestep=300step,scale=160:90,expand=160:120 -frames 1 $outputfilename");
414 &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");
415 }else{
416 #アナログ
417 system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -vf framestep=300step,scale=165:126,crop=160:120 -frames 1 $outputfilename");
418 &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");
419 }
420 #if (-e "$pspdirname/$thmfilename"){
421 #       $timestamp = strftime("%Y%m%d-%H%M%S", localtime);
422 #chomp $timestamp;
423 #       system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename".$timestamp.".THM");
424 #}else{
425 #       system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename");
426 #}
427 #&writelog("ipodtranscode DEBUG convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/$thmfilename");
428
429 #system("rm -rf $pspdirname/0000000*.jpg ");
430 #&writelog("ipodtranscode DEBUG rm -rf $pspdirname/0000000*.jpg");
431 system("mv $pspdirname/00000001.jpg $pspdirname/$thmfilename");
432
433 }#endsub makethumbnail
434
435 sub updatemp4file(){
436 my $mp4filename = "MAQ${mp4filenamestring}.MP4";
437
438 if (-e "${mp4outdir}MAQ${mp4filenamestring}.MP4"){
439 # MP4ファイル名をPIDレコードに書き込み
440         $sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.1'});
441         $sth->execute($mp4filename, $pid);
442         &writelog("ipodtranscode UPDATEsubtitleDB $stmt{'ipodtranscode.updatemp4file.1'}");
443
444 # MP4ファイル名をfoltia_mp4files挿入
445         $sth = $dbh->prepare($stmt{'ipodtranscode.updatemp4file.2'});
446         $sth->execute($tid, $mp4filename);
447         &writelog("ipodtranscode UPDATEmp4DB $stmt{'ipodtranscode.updatemp4file.2'}");
448
449 &changefilestatus($pid,$FILESTATUSALLCOMPLETE);
450 }else{
451 &writelog("ipodtranscode ERR MP4 NOT EXIST $pid/$mp4filename");
452 }
453
454
455 }#updatemp4file
456
457 sub counttranscodefiles(){
458     $sth = $dbh->prepare($stmt{'ipodtranscode.counttranscodefiles.1'});
459     $sth->execute($FILESTATUSRECEND, $FILESTATUSTRANSCODECOMPLETE);
460 my @titlecount= $sth->fetchrow_array;
461
462 return ($titlecount[0]);
463
464
465 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed