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 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 |
|
---|
64 |
|
---|
65 |
|
---|
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 |
} |
---|
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 |
|
---|
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 |
|
---|
116 |
|
---|
117 |
$sth = $dbh->prepare($stmt{'singletranscode.4'}); |
---|
118 |
$sth->execute($tid); |
---|
119 |
@psptrcn= $sth->fetchrow_array; |
---|
120 |
if ($psptrcn[0] == 1 ){ |
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 |
|
---|
125 |
|
---|
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 |
|
---|
136 |
} |
---|
137 |
$pspdirname = "$tid.localized/mp4/"; |
---|
138 |
$pspdirname = $recfolderpath."/".$pspdirname; |
---|
139 |
|
---|
140 |
unless (-e $pspdirname ){ |
---|
141 |
mkdir $pspdirname ,0777; |
---|
142 |
|
---|
143 |
} |
---|
144 |
|
---|
145 |
|
---|
146 |
if ($mp4filenamestyle == 1){ |
---|
147 |
$pspfilname = $mp4newstylefilename ; |
---|
148 |
|
---|
149 |
}else{ |
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 |
my $pspfilnameft = ""; |
---|
160 |
my $pspfilnameyearhd = ""; |
---|
161 |
my $pspfilnameyearft = ""; |
---|
162 |
|
---|
163 |
$btid = $tid % 3600; |
---|
164 |
|
---|
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 |
|
---|
208 |
$pspfilnameft = sprintf("%02d",$countno); |
---|
209 |
}elsif(100 <= $countno && $countno < 1000 ){ |
---|
210 |
|
---|
211 |
$pspfilnameft = sprintf("%03d",$countno); |
---|
212 |
$pspfilnamehd = substr($pspfilnamehd, 0, 2); |
---|
213 |
}elsif(1000 <= $countno && $countno < 10000 ){ |
---|
214 |
|
---|
215 |
$pspfilnameft = sprintf("%04d",$countno); |
---|
216 |
$pspfilnamehd = substr($pspfilnamehd, 0, 1); |
---|
217 |
|
---|
218 |
|
---|
219 |
}elsif($countno == 0){ |
---|
220 |
|
---|
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 |
|
---|
232 |
}else{ |
---|
233 |
|
---|
234 |
|
---|
235 |
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 |
$pspfilnameft = sprintf("%02d",0); |
---|
240 |
|
---|
241 |
} |
---|
242 |
|
---|
243 |
} |
---|
244 |
|
---|
245 |
my $pspfilname = $pspfilnamehd.$pspfilnameft ; |
---|
246 |
|
---|
247 |
} |
---|
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 |
|
---|
274 |
|
---|
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 |
|
---|
288 |
|
---|
289 |
|
---|
290 |
system("rm -rf $pspdirname/0000000*.jpg "); |
---|
291 |
|
---|
292 |
|
---|
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 |
|
---|
301 |
$sth = $dbh->prepare($stmt{'singletranscode.7'}); |
---|
302 |
$sth->execute($tid, "M4V$pspfilname.MP4"); |
---|
303 |
&writelog("singletranscode UPDATEmp4DB $stmt{'singletranscode.7'}"); |
---|
304 |
|
---|
305 |
} |
---|
306 |
|
---|