1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
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 |
|
---|
63 |
|
---|
64 |
|
---|
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 |
} |
---|
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 |
|
---|
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 |
|
---|
121 |
|
---|
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 |
|
---|
130 |
|
---|
131 |
|
---|
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 |
|
---|
142 |
} |
---|
143 |
$pspdirname = "$tid.localized/mp4/"; |
---|
144 |
$pspdirname = $recfolderpath."/".$pspdirname; |
---|
145 |
|
---|
146 |
unless (-e $pspdirname ){ |
---|
147 |
mkdir $pspdirname ,0777; |
---|
148 |
|
---|
149 |
} |
---|
150 |
|
---|
151 |
|
---|
152 |
if ($mp4filenamestyle == 1){ |
---|
153 |
$pspfilname = $mp4newstylefilename ; |
---|
154 |
|
---|
155 |
}else{ |
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 |
|
---|
164 |
|
---|
165 |
my $pspfilnameft = ""; |
---|
166 |
my $pspfilnameyearhd = ""; |
---|
167 |
my $pspfilnameyearft = ""; |
---|
168 |
|
---|
169 |
$btid = $tid % 3600; |
---|
170 |
|
---|
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 |
|
---|
214 |
$pspfilnameft = sprintf("%02d",$countno); |
---|
215 |
}elsif(100 <= $countno && $countno < 1000 ){ |
---|
216 |
|
---|
217 |
$pspfilnameft = sprintf("%03d",$countno); |
---|
218 |
$pspfilnamehd = substr($pspfilnamehd, 0, 2); |
---|
219 |
}elsif(1000 <= $countno && $countno < 10000 ){ |
---|
220 |
|
---|
221 |
$pspfilnameft = sprintf("%04d",$countno); |
---|
222 |
$pspfilnamehd = substr($pspfilnamehd, 0, 1); |
---|
223 |
|
---|
224 |
|
---|
225 |
}elsif($countno == 0){ |
---|
226 |
|
---|
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 |
|
---|