root/trunk/install/perl/singletranscode.pl

リビジョン 1, 9.6 kB (コミッタ: jplcom, コミット時期: 18 年 前)

initial import

  • svn:executable 属性の設定値:
Line 
1 #!/usr/bin/perl
2 #
3 # Anime recording system foltia
4 # http://www.dcc-jpl.com/soft/foltia/
5 #
6 #usage singletranscode.pl [563-1-20051022-1830.m2p] (PATHなしで)
7 #
8 #トラコンラッパ
9 #おもにメンテナンス用
10 # ファイル名が古いまま
11 #
12 #faacで刺さる場合はffmpegつかった別のトラコンを試してみてもよいでしょう
13 #
14 #./ffmpeg -i ~/php/tv/962-2-20061014-0209.m2p -vcodec xvid -croptop 8 -cropbottom 8 -cropleft 8 -cropright 14 -s 320x240 -b 300 -bt 128 -r 14.985 -bufsize 192 -maxrate 512 -minrate 0 -deinterlace -acodec aac -ab 128 -ar 24000 -ac 2 ~/php/tv/962.localized/mp4/M4V-962-2-20061014-0209.MP4
15 #
16 #古い
17 # ffmpeg -i  ../../563-1-20051022-1830.m2p  -f psp -r 14.985 -s 320x240 -b  300 -ar 24000 -ab 32 M4V00001.MP4
18 #
19 # 現行トラコンの前段階コマンド
20 # /usr/local/bin/ffmpeg -y -i $1 -vcodec xvid -croptop 8 -cropbottom 8 -cropleft  8 -cropright 14 -s 320x240 -b 300 -bt 128 -r 14.985  -hq -nr -qns -bufsize 192 -maxrate 512 -minrate 0 -deinterlace  -acodec pcm_s16le -ar 24000 -ac 2 -f m4v $TMP_M4V -f s16le $TMP_S16
21 #
22 #
23 # DCC-JPL Japan/foltia project
24 #
25 #
26
27
28 use DBI;
29 use DBD::Pg;
30 use Schedule::At;
31 use Time::Local;
32 use Jcode;
33
34 $path = $0;
35 $path =~ s/singletranscode.pl$//i;
36 if ($pwd  ne "./"){
37 push( @INC, "$path");
38 }
39
40 require "foltialib.pl";
41 #引き数がアルか?
42 $outputfile =  $ARGV[0] ;
43 if ($outputfile eq "" ){
44         #引き数なし出実行されたら、終了
45         print "usage singletranscode.pl  srcMPEG2file [PID] [pspdir] [aspect 3|16] [title]\n";
46         print "Ex. singletranscode.pl  514-2-20050701-2400.m2p 32961 [pspdir] [aspect 3|16] [title]\n";
47         exit;
48 }
49 $outputfilename = $outputfile;
50 @fullarg = split(/\//,$outputfile );
51 $outputfile = pop( @fullarg );
52 @tid = split(/-/,$outputfile );
53 $tid = $tid[0];
54 $countno = $tid[1];
55
56 chomp($outputfile);
57 $outputfile =~ s/\.m2p//;
58
59                 $mp4newstylefilename = "-".$outputfile ;
60
61
62 # -- recwrapからほとんどコピー
63
64 #PSPトラコン必要かどうか
65         my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",
66
67                 $DBDriv,$DBName,$DBHost,$DBPort);
68          $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;
69
70 if ($ARGV[1] != ""){
71         $pid = $ARGV[1] ;
72 }else{
73 $DBQuery =  "SELECT pid FROM  foltia_subtitle WHERE m2pfilename = '$ARGV[0]' ";
74          $sth = $dbh->prepare($DBQuery);
75         $sth->execute();
76  @pidarray = $sth->fetchrow_array;
77         unless ($pidarray[0]  == "" ){
78                 $pid = $pidarray[0]
79         }else{
80                 &writelog("singletranscode undefined ; PID (Not found m2p file $ARGV[0])");
81         }
82
83 }#endif pid
84
85
86 # 追加部分
87
88 $query =  "SELECT count(*)  FROM  foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' ";
89          $sth = $dbh->prepare($query);
90         $sth->execute();
91  @subticount= $sth->fetchrow_array;
92  unless ($subticount[0]  >= 1){
93
94 $query =  "SELECT count(*)  FROM  foltia_subtitle WHERE tid = '$tid'  ";
95          $sth = $dbh->prepare($query);
96         $sth->execute();
97  @subticount= $sth->fetchrow_array;
98
99  unless ($subticount[0]  >= 1){
100
101         print "This file not included in DB.\n";
102         print "Fill parameter ;usage  singletranscode.pl  srcMPEG2file [pspdir] [aspect 3|16] [title]\n";
103         exit;
104
105 }
106 }
107 sleep(10);
108 # 追加部分ここまで
109
110
111
112 # Starlight breaker向けキャプチャ画像作成
113 if (-e "$toolpath/perl/captureimagemaker.pl"){
114         &writelog("singletranscode Call captureimagemaker $outputfilename");
115         system ("$toolpath/perl/captureimagemaker.pl $outputfilename");
116 }
117
118
119
120 # PSP ------------------------------------------------------
121 #PSPトラコン必要かどうか
122 $DBQuery =  "SELECT psp,aspect,title FROM  foltia_program WHERE tid = '$tid' ";
123          $sth = $dbh->prepare($DBQuery);
124         $sth->execute();
125  @psptrcn= $sth->fetchrow_array;
126  if ($psptrcn[0]  == 1 ){#トラコン番組
127
128
129 #PSPムービーディレクトリがアルかどうか
130  
131 #TIDが100以上の3桁の場合はそのまま
132 my $pspfilnamehd = "";
133
134         $pspfilnamehd = $tid;
135 $pspdirname = "$tid.localized/";
136 $pspdirname = $recfolderpath."/".$pspdirname;
137
138 #なければ作る
139 unless (-e $pspdirname ){
140         system("$toolpath/perl/mklocalizeddir.pl $tid");
141         #&writelog("singletranscode mkdir $pspdirname");
142 }
143 $pspdirname = "$tid.localized/mp4/";
144 $pspdirname = $recfolderpath."/".$pspdirname;
145 #なければ作る
146 unless (-e $pspdirname ){
147         mkdir $pspdirname ,0777;
148         #&writelog("singletranscode mkdir $pspdirname");
149 }
150
151 #ファイル名決定
152 if ($mp4filenamestyle == 1){# 1;よりわかりやすいファイル名
153  $pspfilname = $mp4newstylefilename ;
154  
155 }else{##0:PSP ファームウェアver.2.80より前と互換性を持つファイル名
156 #・フォルダ名[100MNV01]の100の部分は変更可(100〜999)。
157 # MP_ROOT ━ 100MNV01 ┳ M4V00001.MP4(動画)
158 #┃                  ┗ M4V00001.THM(サムネイル)※必須ではない
159
160 #ファイル名決定
161 #ファイル名決定 #新アルゴリズム
162 #TID 0000-3599まで[3桁]
163 #話数 00-999まで[2桁]
164
165 my $pspfilnameft = "";
166 my $pspfilnameyearhd = "";
167 my $pspfilnameyearft = "";
168
169 $btid = $tid % 3600;
170 # print "$btid\n";
171
172 if($btid >= 0 && $btid < 1000){
173
174         $pspfilnamehd = sprintf("%03d",$btid);
175
176 }elsif ($btid >= 1000 && $btid < 3600){
177         $pspfilnameyearhd = substr($btid, 0, 2);
178         $pspfilnameyearhd =~ s/10/A/;
179         $pspfilnameyearhd =~ s/11/B/;
180         $pspfilnameyearhd =~ s/12/C/;
181         $pspfilnameyearhd =~ s/13/D/;
182         $pspfilnameyearhd =~ s/14/E/;
183         $pspfilnameyearhd =~ s/15/F/;
184         $pspfilnameyearhd =~ s/16/G/;
185         $pspfilnameyearhd =~ s/17/H/;
186         $pspfilnameyearhd =~ s/18/I/;
187         $pspfilnameyearhd =~ s/19/J/;
188         $pspfilnameyearhd =~ s/20/K/;
189         $pspfilnameyearhd =~ s/21/L/;
190         $pspfilnameyearhd =~ s/22/M/;
191         $pspfilnameyearhd =~ s/23/N/;
192         $pspfilnameyearhd =~ s/24/O/;
193         $pspfilnameyearhd =~ s/25/P/;
194         $pspfilnameyearhd =~ s/26/Q/;
195         $pspfilnameyearhd =~ s/27/R/;
196         $pspfilnameyearhd =~ s/28/S/;
197         $pspfilnameyearhd =~ s/29/T/;
198         $pspfilnameyearhd =~ s/30/U/;
199         $pspfilnameyearhd =~ s/31/V/;
200         $pspfilnameyearhd =~ s/32/W/;
201         $pspfilnameyearhd =~ s/33/X/;
202         $pspfilnameyearhd =~ s/34/Y/;
203         $pspfilnameyearhd =~ s/35/Z/;
204        
205 $pspfilnameyearft = substr($btid, 2, 2);
206 $pspfilnameyearft = sprintf("%02d",$pspfilnameyearft);
207 $pspfilnamehd = $pspfilnameyearhd . $pspfilnameyearft;
208
209 }
210
211 # 話数
212 if (0 < $countno && $countno < 100 ){
213 # 2桁
214         $pspfilnameft = sprintf("%02d",$countno);
215 }elsif(100 <= $countno && $countno < 1000 ){
216 # 3桁
217         $pspfilnameft = sprintf("%03d",$countno); # 話数3桁
218         $pspfilnamehd = substr($pspfilnamehd, 0, 2); # TID 二桁 後ろ1バイト落とし
219 }elsif(1000 <= $countno && $countno < 10000 ){
220 # 4桁
221         $pspfilnameft = sprintf("%04d",$countno); # 話数4桁
222         $pspfilnamehd = substr($pspfilnamehd, 0, 1); # TID 1桁 後ろ2バイト落とし
223
224
225 }elsif($countno == 0){
226 #タイムスタンプが最新のMP4ファイル名取得
227 my $newestmp4filename = `cd $pspdirname ; ls -t *.MP4 | head -1`;
228  if ($newestmp4filename =~ /M4V$tid/){
229         $nowcountno = $' ;
230                 $nowcountno++;
231                 $pspfilnameft = sprintf("%02d",$nowcountno);
232         while (-e "$pspdirname/M4V".$pspfilnamehd.$pspfilnameft.".MP4"){
233                 $nowcountno++;
234                 $pspfilnameft = sprintf("%02d",$nowcountno);   
235         print "File exist:$nowcountno\n";
236         }
237 #print "NeXT\n";
238 }else{
239 # 0の場合 週番号を100から引いたもの
240 # week number of year with Monday as first day of week (01..53)
241 #だったけど常に0に
242 #       my $weeno = `date "+%V"`;
243 #       $weeno = 100 - $weeno ;
244 #       $pspfilnameft = sprintf("%02d",$weeno);
245         $pspfilnameft = sprintf("%02d",0);
246 #print "WEEKNO\n";
247 }
248
249 }
250
251 my $pspfilname = $pspfilnamehd.$pspfilnameft  ;
252 # print "$pspfilname($pspfilnamehd/$pspfilnameft)\n";
253 }# endif MP4ファイル名が新styleなら
254
255 &writelog("singletranscode TRCNSTART vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]");
256 #トラコン開始
257 system("$toolpath/perl/transcode/vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]");
258
259 &writelog("singletranscode TRCNEND  vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]");
260
261 #最適化
262
263 $DBQuery =  "SELECT subtitle  FROM  foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' ";
264          $sth = $dbh->prepare($DBQuery);
265         $sth->execute();
266  @programtitle = $sth->fetchrow_array;
267
268 if ( $countno == "0" ){
269         $pspcountno = "";
270 }else{
271         $pspcountno = $countno ;
272 }
273 &writelog("singletranscode OPTIMIZE  mp4psp -p $pspdirname/M4V$pspfilname.MP4   -t  '$psptrcn[2] $pspcountno $programtitle[0]' ");
274 Jcode::convert(\$programtitle[0],'euc');
275 system ("/usr/local/bin/mp4psp -p $pspdirname/M4V$pspfilname.MP4   -t  '$psptrcn[2] $pspcountno $programtitle[0]'") ;
276
277
278 #サムネール
279
280 # mplayer -ss 00:01:20 -vo jpeg:outdir=/home/foltia/php/tv/443MNV01 -ao null -sstep 1 -frames 3  -v 3 /home/foltia/php/tv/443-07-20050218-0030.m2p
281 #2005/02/22_18:30:05 singletranscode TRCNSTART vfr4psp.sh /home/foltia/php/tv/447-21-20050222-1800.m2p 44721 /home/foltia/php/tv/447MNV01 3
282 &writelog("singletranscode THAMJ  mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $recfolderpath/$outputfilename ");
283 system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3  -v 3 $recfolderpath/$outputfilename");
284 &writelog("singletranscode THAMI  convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V$pspdirname.THM ");
285
286 if (-e "$pspdirname/M4V".$pspfilname.".THM"){
287 $timestamp =`date "+%Y%m%d-%H%M%S"`;
288 chomp $timestamp;
289         system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V".$pspfilname.".THM.".$timestamp.".THM");
290
291 }else{
292         system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V".$pspfilname.".THM");
293 }
294 # rm -rf 00000001.jpg     
295 # convert -resize 160x120\! 00000002.jpg M4V44307.THM
296 # rm -rf 00000002.jpg 
297 system("rm -rf $pspdirname/0000000*.jpg ");
298
299
300
301
302 # MP4ファイル名をPIDレコードに書き込み
303 unless ($pid eq ""){
304         $DBQuery =  "
305         UPDATE  foltia_subtitle 
306         SET PSPfilename = 'M4V$pspfilname.MP4'
307         WHERE pid =  '$pid' ";
308          $sth = $dbh->prepare($DBQuery);
309         $sth->execute();
310 &writelog("singletranscode UPDATEsubtitleDB  $DBQuery");
311 }else{
312 &writelog("singletranscode PID not found");
313 }
314 # MP4ファイル名をfoltia_mp4files挿入
315         $DBQuery =  "insert into  foltia_mp4files values ('$tid','M4V$pspfilname.MP4') ";
316          $sth = $dbh->prepare($DBQuery);
317         $sth->execute();
318 &writelog("singletranscode UPDATEmp4DB  $DBQuery");
319
320 }#PSPトラコンあり
321
322
323
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed