root/trunk/install/perl/singletranscode.pl

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

SQLite採用

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