root/trunk/install/perl/ipodtranscode.pl

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

SQLite採用

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