1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
use DBI; |
---|
16 |
use DBD::Pg; |
---|
17 |
use Schedule::At; |
---|
18 |
use Time::Local; |
---|
19 |
use Jcode; |
---|
20 |
|
---|
21 |
$path = $0; |
---|
22 |
$path =~ s/recwrap.pl$//i; |
---|
23 |
if ($pwd ne "./"){ |
---|
24 |
push( @INC, "$path"); |
---|
25 |
} |
---|
26 |
|
---|
27 |
require "foltialib.pl"; |
---|
28 |
|
---|
29 |
$recch = $ARGV[0] ; |
---|
30 |
if ($recch eq "" ){ |
---|
31 |
|
---|
32 |
print "usage recwrap.pl ch length(sec) [bitrate(5)] [TID] [NO] [PID]\n"; |
---|
33 |
exit; |
---|
34 |
} |
---|
35 |
|
---|
36 |
$recch = $ARGV[0] ; |
---|
37 |
$reclength = $ARGV[1] ; |
---|
38 |
$bitrate = $ARGV[2] ; |
---|
39 |
$tid = $ARGV[3] ; |
---|
40 |
$countno = $ARGV[4] ; |
---|
41 |
$pid = $ARGV[5] ; |
---|
42 |
|
---|
43 |
$outputfile = `date +%Y%m%d-%H%M --date "1 min "`; |
---|
44 |
chomp($outputfile); |
---|
45 |
if ($tid == 0){ |
---|
46 |
$outputfilename = "0--".$outputfile."-".$recch.".m2p"; |
---|
47 |
$mp4newstylefilename = "-0--".$outputfile."-".$recch; |
---|
48 |
}else{ |
---|
49 |
if ($countno == 0){ |
---|
50 |
$outputfilename = $tid ."--".$outputfile.".m2p"; |
---|
51 |
$mp4newstylefilename = "-" . $tid ."--".$outputfile; |
---|
52 |
}else{ |
---|
53 |
$outputfilename = $tid ."-".$countno."-".$outputfile.".m2p"; |
---|
54 |
$mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile; |
---|
55 |
} |
---|
56 |
} |
---|
57 |
|
---|
58 |
|
---|
59 |
if ($haveirdaunit == 1){ |
---|
60 |
|
---|
61 |
if ($recch == 0){ |
---|
62 |
|
---|
63 |
&writelog("recwrap Call Change STB CH :$pid"); |
---|
64 |
system ("$toolpath/perl/changestbch.pl $pid &"); |
---|
65 |
} |
---|
66 |
} |
---|
67 |
|
---|
68 |
if($recch == -10){ |
---|
69 |
|
---|
70 |
&writelog("recwrap Not recordable channel;exit:PID $pid"); |
---|
71 |
exit; |
---|
72 |
} |
---|
73 |
|
---|
74 |
&writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid"); |
---|
75 |
|
---|
76 |
|
---|
77 |
$oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno"); |
---|
78 |
$oserr = $oserr / 256; |
---|
79 |
if ($oserr == 1){ |
---|
80 |
&writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
81 |
}else{ |
---|
82 |
&writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
83 |
} |
---|
84 |
|
---|
85 |
my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", |
---|
86 |
$DBDriv,$DBName,$DBHost,$DBPort); |
---|
87 |
$dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; |
---|
88 |
|
---|
89 |
|
---|
90 |
$DBQuery = "UPDATE foltia_subtitle SET |
---|
91 |
m2pfilename = '$outputfilename' |
---|
92 |
WHERE pid = '$pid' "; |
---|
93 |
$sth = $dbh->prepare($DBQuery); |
---|
94 |
$sth->execute(); |
---|
95 |
&writelog("recwrap UPDATEDB $DBQuery"); |
---|
96 |
|
---|
97 |
|
---|
98 |
$DBQuery = "insert into foltia_m2pfiles values ('$outputfilename')"; |
---|
99 |
$sth = $dbh->prepare($DBQuery); |
---|
100 |
$sth->execute(); |
---|
101 |
&writelog("recwrap UPDATEDB $DBQuery"); |
---|
102 |
|
---|
103 |
|
---|
104 |
if (-e "$toolpath/perl/captureimagemaker.pl"){ |
---|
105 |
&writelog("recwrap Call captureimagemaker $outputfilename"); |
---|
106 |
system ("$toolpath/perl/captureimagemaker.pl $outputfilename"); |
---|
107 |
} |
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 |
$DBQuery = "SELECT psp,aspect,title FROM foltia_program WHERE tid = '$tid' "; |
---|
114 |
$sth = $dbh->prepare($DBQuery); |
---|
115 |
$sth->execute(); |
---|
116 |
@psptrcn= $sth->fetchrow_array; |
---|
117 |
if ($psptrcn[0] == 1 ){ |
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 |
my $pspfilnamehd = ""; |
---|
124 |
|
---|
125 |
$pspfilnamehd = $tid; |
---|
126 |
$pspdirname = "$tid.localized/"; |
---|
127 |
$pspdirname = $recfolderpath."/".$pspdirname; |
---|
128 |
|
---|
129 |
|
---|
130 |
unless (-e $pspdirname ){ |
---|
131 |
system("$toolpath/perl/mklocalizeddir.pl $tid"); |
---|
132 |
|
---|
133 |
} |
---|
134 |
$pspdirname = "$tid.localized/mp4/"; |
---|
135 |
$pspdirname = $recfolderpath."/".$pspdirname; |
---|
136 |
|
---|
137 |
unless (-e $pspdirname ){ |
---|
138 |
mkdir $pspdirname ,0777; |
---|
139 |
|
---|
140 |
} |
---|
141 |
|
---|
142 |
|
---|
143 |
if ($mp4filenamestyle == 1){ |
---|
144 |
$pspfilname = $mp4newstylefilename ; |
---|
145 |
|
---|
146 |
}else{ |
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 |
my $pspfilnameft = ""; |
---|
157 |
my $pspfilnameyearhd = ""; |
---|
158 |
my $pspfilnameyearft = ""; |
---|
159 |
|
---|
160 |
$btid = $tid % 3600; |
---|
161 |
|
---|
162 |
|
---|
163 |
if($btid >= 0 && $btid < 1000){ |
---|
164 |
|
---|
165 |
$pspfilnamehd = sprintf("%03d",$btid); |
---|
166 |
|
---|
167 |
}elsif ($btid >= 1000 && $btid < 3600){ |
---|
168 |
$pspfilnameyearhd = substr($btid, 0, 2); |
---|
169 |
$pspfilnameyearhd =~ s/10/A/; |
---|
170 |
$pspfilnameyearhd =~ s/11/B/; |
---|
171 |
$pspfilnameyearhd =~ s/12/C/; |
---|
172 |
$pspfilnameyearhd =~ s/13/D/; |
---|
173 |
$pspfilnameyearhd =~ s/14/E/; |
---|
174 |
$pspfilnameyearhd =~ s/15/F/; |
---|
175 |
$pspfilnameyearhd =~ s/16/G/; |
---|
176 |
$pspfilnameyearhd =~ s/17/H/; |
---|
177 |
$pspfilnameyearhd =~ s/18/I/; |
---|
178 |
$pspfilnameyearhd =~ s/19/J/; |
---|
179 |
$pspfilnameyearhd =~ s/20/K/; |
---|
180 |
$pspfilnameyearhd =~ s/21/L/; |
---|
181 |
$pspfilnameyearhd =~ s/22/M/; |
---|
182 |
$pspfilnameyearhd =~ s/23/N/; |
---|
183 |
$pspfilnameyearhd =~ s/24/O/; |
---|
184 |
$pspfilnameyearhd =~ s/25/P/; |
---|
185 |
$pspfilnameyearhd =~ s/26/Q/; |
---|
186 |
$pspfilnameyearhd =~ s/27/R/; |
---|
187 |
$pspfilnameyearhd =~ s/28/S/; |
---|
188 |
$pspfilnameyearhd =~ s/29/T/; |
---|
189 |
$pspfilnameyearhd =~ s/30/U/; |
---|
190 |
$pspfilnameyearhd =~ s/31/V/; |
---|
191 |
$pspfilnameyearhd =~ s/32/W/; |
---|
192 |
$pspfilnameyearhd =~ s/33/X/; |
---|
193 |
$pspfilnameyearhd =~ s/34/Y/; |
---|
194 |
$pspfilnameyearhd =~ s/35/Z/; |
---|
195 |
|
---|
196 |
$pspfilnameyearft = substr($btid, 2, 2); |
---|
197 |
$pspfilnameyearft = sprintf("%02d",$pspfilnameyearft); |
---|
198 |
$pspfilnamehd = $pspfilnameyearhd . $pspfilnameyearft; |
---|
199 |
|
---|
200 |
} |
---|
201 |
|
---|
202 |
|
---|
203 |
if (0 < $countno && $countno < 100 ){ |
---|
204 |
|
---|
205 |
$pspfilnameft = sprintf("%02d",$countno); |
---|
206 |
}elsif(100 <= $countno && $countno < 1000 ){ |
---|
207 |
|
---|
208 |
$pspfilnameft = sprintf("%03d",$countno); |
---|
209 |
$pspfilnamehd = substr($pspfilnamehd, 0, 2); |
---|
210 |
}elsif(1000 <= $countno && $countno < 10000 ){ |
---|
211 |
|
---|
212 |
$pspfilnameft = sprintf("%04d",$countno); |
---|
213 |
$pspfilnamehd = substr($pspfilnamehd, 0, 1); |
---|
214 |
|
---|
215 |
|
---|
216 |
}elsif($countno == 0){ |
---|
217 |
|
---|
218 |
my $newestmp4filename = `cd $pspdirname ; ls -t *.MP4 | head -1`; |
---|
219 |
if ($newestmp4filename =~ /M4V$tid/){ |
---|
220 |
$nowcountno = $' ; |
---|
221 |
$nowcountno++; |
---|
222 |
$pspfilnameft = sprintf("%02d",$nowcountno); |
---|
223 |
while (-e "$pspdirname/M4V".$pspfilnamehd.$pspfilnameft.".MP4"){ |
---|
224 |
$nowcountno++; |
---|
225 |
$pspfilnameft = sprintf("%02d",$nowcountno); |
---|
226 |
print "File exist:$nowcountno\n"; |
---|
227 |
} |
---|
228 |
#print "NeXT\n"; |
---|
229 |
}else{ |
---|
230 |
# 0の場合 週番号を100から引いたもの |
---|
231 |
# week number of year with Monday as first day of week (01..53) |
---|
232 |
#だったけど常に0に |
---|
233 |
# my $weeno = `date "+%V"`; |
---|
234 |
# $weeno = 100 - $weeno ; |
---|
235 |
# $pspfilnameft = sprintf("%02d",$weeno); |
---|
236 |
$pspfilnameft = sprintf("%02d",0); |
---|
237 |
#print "WEEKNO\n"; |
---|
238 |
} |
---|
239 |
|
---|
240 |
} |
---|
241 |
|
---|
242 |
my $pspfilname = $pspfilnamehd.$pspfilnameft ; |
---|
243 |
# print "$pspfilname($pspfilnamehd/$pspfilnameft)\n"; |
---|
244 |
}# endif MP4ファイル名が新styleなら |
---|
245 |
|
---|
246 |
&writelog("recwrap TRCNSTART vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
247 |
#トラコン開始 |
---|
248 |
system("$toolpath/perl/transcode/vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
249 |
|
---|
250 |
&writelog("recwrap TRCNEND vfr4psp.sh $recfolderpath/$outputfilename $pspfilname $pspdirname $psptrcn[1]"); |
---|
251 |
|
---|
252 |
#最適化 |
---|
253 |
|
---|
254 |
$DBQuery = "SELECT subtitle FROM foltia_subtitle WHERE tid = '$tid' AND countno = '$countno' "; |
---|
255 |
$sth = $dbh->prepare($DBQuery); |
---|
256 |
$sth->execute(); |
---|
257 |
@programtitle = $sth->fetchrow_array; |
---|
258 |
|
---|
259 |
if ( $countno == "0" ){ |
---|
260 |
$pspcountno = ""; |
---|
261 |
}else{ |
---|
262 |
$pspcountno = $countno ; |
---|
263 |
} |
---|
264 |
&writelog("recwrap OPTIMIZE mp4psp -p $pspdirname/M4V$pspfilname.MP4 -t '$psptrcn[2] $pspcountno $programtitle[0]' "); |
---|
265 |
Jcode::convert(\$programtitle[0],'euc'); |
---|
266 |
system ("/usr/local/bin/mp4psp -p $pspdirname/M4V$pspfilname.MP4 -t '$psptrcn[2] $pspcountno $programtitle[0]'") ; |
---|
267 |
|
---|
268 |
|
---|
269 |
#サムネール |
---|
270 |
|
---|
271 |
# 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 |
---|
272 |
#2005/02/22_18:30:05 recwrap TRCNSTART vfr4psp.sh /home/foltia/php/tv/447-21-20050222-1800.m2p 44721 /home/foltia/php/tv/447MNV01 3 |
---|
273 |
&writelog("recwrap THAMJ mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3 -v 3 $recfolderpath/$outputfilename "); |
---|
274 |
system ("mplayer -ss 00:01:20 -vo jpeg:outdir=$pspdirname -ao null -sstep 1 -frames 3 -v 3 $recfolderpath/$outputfilename"); |
---|
275 |
&writelog("recwrap THAMI convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V$pspdirname.THM "); |
---|
276 |
|
---|
277 |
if (-e "$pspdirname/M4V".$pspfilname.".THM"){ |
---|
278 |
$timestamp =`date "+%Y%m%d-%H%M%S"`; |
---|
279 |
chomp $timestamp; |
---|
280 |
system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V".$pspfilname.".THM.".$timestamp.".THM"); |
---|
281 |
|
---|
282 |
}else{ |
---|
283 |
system("convert -crop 160x120+1+3 -resize 165x126\! $pspdirname/00000002.jpg $pspdirname/M4V".$pspfilname.".THM"); |
---|
284 |
} |
---|
285 |
# rm -rf 00000001.jpg |
---|
286 |
# convert -resize 160x120\! 00000002.jpg M4V44307.THM |
---|
287 |
# rm -rf 00000002.jpg |
---|
288 |
system("rm -rf $pspdirname/0000000*.jpg "); |
---|
289 |
|
---|
290 |
|
---|
291 |
|
---|
292 |
|
---|
293 |
# MP4ファイル名をPIDレコードに書き込み |
---|
294 |
$DBQuery = "UPDATE foltia_subtitle SET |
---|
295 |
PSPfilename = 'M4V$pspfilname.MP4' |
---|
296 |
WHERE pid = '$pid' "; |
---|
297 |
$sth = $dbh->prepare($DBQuery); |
---|
298 |
$sth->execute(); |
---|
299 |
&writelog("recwrap UPDATEsubtitleDB $DBQuery"); |
---|
300 |
|
---|
301 |
# MP4ファイル名をfoltia_mp4files挿入 |
---|
302 |
$DBQuery = "insert into foltia_mp4files values ('$tid','M4V$pspfilname.MP4') "; |
---|
303 |
$sth = $dbh->prepare($DBQuery); |
---|
304 |
$sth->execute(); |
---|
305 |
&writelog("recwrap UPDATEmp4DB $DBQuery"); |
---|
306 |
|
---|
307 |
}#PSPトラコンあり |
---|
308 |
|
---|
309 |
|
---|
310 |
|
---|
311 |
|
---|
312 |
|
---|