3 # Rec10 TS Recording Tools
\r
4 # Copyright (C) 2009-2011 Yukikaze
\r
16 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
\r
18 pinで指定されたファイルをpoutにx264でエンコードして書き出す
\r
25 quality=int(configreader.getConfEnv("x264_preset"))
\r
26 crf=int(configreader.getConfEnv("crf"))
\r
28 if re.search("H", opts):
\r
30 if re.search("S", opts):
\r
32 if re.search("F", opts):
\r
34 if re.search("W",opts):
\r
36 if re.search("MW1",opts):
\r
39 if re.search("MW2", opts):
\r
42 if re.search("v", opts):
\r
44 crf=int(configreader.getConfEnv("animation_crf"))
\r
45 if re.search("a", opts):
\r
47 crf=int(configreader.getConfEnv("animation_crf"))
\r
48 if re.search("I", opts):
\r
50 if re.search("q",opts):
\r
52 if re.search("w",opts):
\r
54 if re.search("e",opts):
\r
56 if re.search("r",opts):
\r
58 if re.search("u",opts):
\r
60 if re.search("i",opts):
\r
62 if re.search("o",opts):
\r
64 if re.search("p",opts):
\r
66 if re.search("d",opts):#二カ国語放送の場合
\r
67 tm2v=pin.replace(".ts",".m2v")
\r
68 encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace)
\r
69 elif re.search("5",opts):#5.1chの場合
\r
70 encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace)
\r
71 elif re.search("0",opts):#BonTsDemuxを使いたい場合
\r
73 elif re.search("X",opts):
\r
75 encodeMencoderSar_lavf(pin, pout,size,is24fps,quality,crf,deinterlace)
\r
76 except Exception, inst:
\r
77 recdblist.addCommonlogEX("Error in X", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
\r
78 elif re.search("Y",opts):
\r
80 encodeMencoderSar_lavf(pin, pout,size,is24fps,quality,crf,deinterlace)
\r
81 if os.path.exists(pout):
\r
82 if not os.path.getsize(pout)>1*1000:
\r
83 recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200)
\r
85 encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace)
\r
86 except Exception, inst:
\r
87 recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
\r
89 recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200)
\r
91 encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace)
\r
92 except Exception, inst:
\r
93 recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
\r
94 except Exception, inst:
\r
95 recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
\r
98 encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace)
\r
99 except Exception, inst:
\r
100 recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
\r
102 def encodeMencoderSar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
\r
103 mencoder=configreader.getConfPath("mencoder")
\r
104 tee=configreader.getConfPath("tee")
\r
107 encvf="-sws 9 -vf yadif=0,pp=l5"
\r
108 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
\r
109 ofps="-ofps 30000/1001"
\r
110 fps="-fps 30000/1001"
\r
111 x264fps="30000/1001"
\r
115 x264_bitrate="5000"
\r
116 tsar=getMoviePAR2(pin)
\r
117 x264sar=str(tsar[0])+":"+str(tsar[1])
\r
119 ofps="-ofps 24000/1001"
\r
120 fps="-fps 30000/1001"
\r
121 x264fps="24000/1001"
\r
122 x264tune="--tune animation"
\r
123 encvf="-sws 9 -vf pullup,softskip"
\r
124 harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
\r
126 tsize=getParSize(pin,720)
\r
127 encvf = encvf + ",scale=-3:720::0:3"+harddup
\r
128 x264streamsize=str(tsize[0])+u"x720"
\r
129 x264_bitrate="2500"
\r
130 elif size == "WVGA":
\r
131 tsize=getParSize(pin,480)
\r
132 encvf = encvf + ",scale=-3:480::0:3"+harddup
\r
133 x264streamsize=str(tsize[0])+u"x480"
\r
134 x264_bitrate="1500"
\r
135 elif size == "FullHD":
\r
136 tsize=getParSize(pin,1080)
\r
137 encvf = encvf + ",scale=-3:1080::0:3"+harddup
\r
138 x264streamsize=str(tsize[0])+u"x1080"
\r
139 x264_bitrate="5000"
\r
140 elif size == "QVGA_BASE":
\r
141 tsize=getParSize(pin,240)
\r
142 encvf = encvf + ",scale=-3:240::0:3"+harddup
\r
143 x264streamsize=str(tsize[0])+u"x240"
\r
145 elif size == "WVGA_BASE":
\r
146 tsize=getParSize(pin,480)
\r
147 encvf = encvf + ",scale=-3:480::0:3"+harddup
\r
148 x264streamsize=str(tsize[0])+u"x480"
\r
149 x264_bitrate="1500"
\r
151 tsize=getParSize(pin,720)
\r
152 encvf = encvf + ",scale=-3:720::0:3"+harddup
\r
153 x264streamsize=str(tsize[0])+u"x720"
\r
154 x264_bitrate="2500"
\r
156 tsize=getMovieBaseSize2(pin)
\r
157 ofps="-ofps 30000/1001"
\r
158 #fps="-fps 30000/1001"
\r
160 x264fps="30000/1001"
\r
161 x264tune=x264tune+" --tff --nal-hrd vbr"
\r
162 encvf="-vf hqdn3d=2:1:2"
\r
164 encvf=encvf+harddup
\r
165 x264streamsize=str(tsize[0])+u"x"+str(tsize[1])
\r
166 if tsize[0] <= 0 or tsize[1] <= 0:
\r
167 encvf="-sws 9 -vf yadif=0,pp=l5"
\r
168 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
\r
169 ofps="-ofps 30000/1001"
\r
170 fps="-fps 30000/1001"
\r
171 x264fps="30000/1001"
\r
173 encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
\r
174 x264streamsize=u"1280x720"
\r
175 x264_bitrate="2500"
\r
177 x264preset=u"ultrafast"
\r
179 x264preset=u"veryfast"
\r
183 x264preset=u"medium"
\r
187 x264preset=u"slower"
\r
189 x264preset=u"medium"
\r
190 if size == "WVGA_BASE" or size == "QVGA_BASE":
\r
191 x264profile=" --level 32 --profile baseline "
\r
193 x264profile=" --level 41 --profile high "
\r
195 os.environ['LANG']="ja_JP.UTF-8"
\r
197 random.jumpahead(10)
\r
198 temptime=int(time.time())
\r
199 temptime=temptime % 9697
\r
200 random.jumpahead(temptime)
\r
201 streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999)))
\r
202 unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore')
\r
203 logmencoder=recdblist.getLogTitle(pin)+".mencoder.log"
\r
204 logx264=recdblist.getLogTitle(pin)+".x264.log"
\r
205 encexe=mencoder+u" \""+pin+u"\" -quiet -vfm ffmpeg "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" 2>&1 | "+tee+" \""+logmencoder+"\" & "
\r
206 encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf)
\r
207 #encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
\r
208 encexe=u"nice -n 19 " +encexe+" 2>&1 | "+tee+" \""+logx264+"\""
\r
210 recdblist.addCommandSelfLog(pin, encexe)
\r
211 except Exception, inst:
\r
214 print traceback.print_exc(file=sys.stdout)
\r
215 recdblist.printutf8(encexe)
\r
218 txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore')
\r
221 os.remove(streampath)
\r
222 zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip")
\r
223 zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip")
\r
224 os.remove(logmencoder)
\r
226 recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)
\r
227 # recdblist.addCommandLogTar(pin,u"Mencoder","mencoder", encexe,txt)
\r
228 def encodeMencoderSar_lavf(pin,pout,size,is24fps,quality,crf,deinterlace=1):
\r
229 mencoder=configreader.getConfPath("mencoder")
\r
230 tee=configreader.getConfPath("tee")
\r
233 encvf="-sws 9 -vf yadif=0,pp=l5"
\r
234 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
\r
235 ofps="-ofps 30000/1001"
\r
236 fps="-fps 30000/1001"
\r
237 x264fps="30000/1001"
\r
241 x264_bitrate="5000"
\r
242 tsar=getMoviePAR2(pin)
\r
243 x264sar=str(tsar[0])+":"+str(tsar[1])
\r
245 ofps="-ofps 24000/1001"
\r
246 fps="-fps 30000/1001"
\r
247 x264fps="24000/1001"
\r
248 x264tune="--tune animation"
\r
249 encvf="-sws 9 -vf pullup,softskip"
\r
250 harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
\r
252 tsize=getParSize(pin,720)
\r
253 encvf = encvf + ",scale=-3:720::0:3"+harddup
\r
254 x264streamsize=str(tsize[0])+u"x720"
\r
255 x264_bitrate="2500"
\r
256 elif size == "WVGA":
\r
257 tsize=getParSize(pin,480)
\r
258 encvf = encvf + ",scale=-3:480::0:3"+harddup
\r
259 x264streamsize=str(tsize[0])+u"x480"
\r
260 x264_bitrate="1500"
\r
261 elif size == "FullHD":
\r
262 tsize=getParSize(pin,1080)
\r
263 encvf = encvf + ",scale=-3:1080::0:3"+harddup
\r
264 x264streamsize=str(tsize[0])+u"x1080"
\r
265 x264_bitrate="5000"
\r
266 elif size == "QVGA_BASE":
\r
267 tsize=getParSize(pin,240)
\r
268 encvf = encvf + ",scale=-3:240::0:3"+harddup
\r
269 x264streamsize=str(tsize[0])+u"x240"
\r
271 elif size == "WVGA_BASE":
\r
272 tsize=getParSize(pin,480)
\r
273 encvf = encvf + ",scale=-3:480::0:3"+harddup
\r
274 x264streamsize=str(tsize[0])+u"x480"
\r
275 x264_bitrate="1500"
\r
277 tsize=getParSize(pin,720)
\r
278 encvf = encvf + ",scale=-3:720::0:3"+harddup
\r
279 x264streamsize=str(tsize[0])+u"x720"
\r
280 x264_bitrate="2500"
\r
282 tsize=getMovieBaseSize2(pin)
\r
283 ofps="-ofps 30000/1001"
\r
284 #fps="-fps 30000/1001"
\r
286 x264fps="30000/1001"
\r
287 x264tune=x264tune+" --tff --nal-hrd vbr"
\r
288 encvf="-vf hqdn3d=2:1:2"
\r
290 encvf=encvf+harddup
\r
291 x264streamsize=str(tsize[0])+u"x"+str(tsize[1])
\r
292 if tsize[0] <= 0 or tsize[1] <= 0:
\r
293 encvf="-sws 9 -vf yadif=0,pp=l5"
\r
294 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
\r
295 ofps="-ofps 30000/1001"
\r
296 fps="-fps 30000/1001"
\r
297 x264fps="30000/1001"
\r
299 encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
\r
300 x264streamsize=u"1280x720"
\r
301 x264_bitrate="2500"
\r
303 x264preset=u"ultrafast"
\r
305 x264preset=u"veryfast"
\r
309 x264preset=u"medium"
\r
313 x264preset=u"slower"
\r
315 x264preset=u"medium"
\r
316 if size == "WVGA_BASE" or size == "QVGA_BASE":
\r
317 x264profile=" --level 32 --profile baseline "
\r
319 x264profile=" --level 41 --profile high "
\r
321 os.environ['LANG']="ja_JP.UTF-8"
\r
323 random.jumpahead(10)
\r
324 temptime=int(time.time())
\r
325 temptime=temptime % 9697
\r
326 random.jumpahead(temptime)
\r
327 streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999)))
\r
328 unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore')
\r
329 logmencoder=recdblist.getLogTitle(pin)+".mencoder.log"
\r
330 logx264=recdblist.getLogTitle(pin)+".x264.log"
\r
331 encexe=mencoder+u" \""+pin+u"\" -quiet -vfm ffmpeg -demuxer lavf "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" 2>&1 | "+tee+" \""+logmencoder+"\" & "
\r
332 encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf)
\r
333 #encexe=encexe+u" nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
\r
334 encexe=u"nice -n 19 " +encexe+" 2>&1 | "+tee+" \""+logx264+"\""
\r
336 recdblist.addCommandSelfLog(pin, encexe)
\r
337 except Exception, inst:
\r
340 print traceback.print_exc(file=sys.stdout)
\r
341 recdblist.printutf8(encexe)
\r
344 txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore')
\r
347 os.remove(streampath)
\r
348 zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip")
\r
349 zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip")
\r
350 os.remove(logmencoder)
\r
352 recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)
\r
353 def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1):
\r
357 ffmpeg=configreader.getConfPath("ffmpeg")
\r
358 tee=configreader.getConfPath("tee")
\r
359 fps=u"-r 29.970030 "
\r
360 x264fps="30000/1001"
\r
364 x264_bitrate="2500"
\r
366 tsar=getMoviePAR2(pin)
\r
367 filter="-deinterlace"
\r
368 x264sar=str(tsar[0])+":"+str(tsar[1])
\r
370 tsize=getParSize(pin,720)
\r
371 s = "-s "+str(tsize[0])+"x720 "
\r
372 x264streamsize=str(tsize[0])+u"x720"
\r
373 x264_bitrate="2500"
\r
374 elif size == "WVGA":
\r
375 tsize=getParSize(pin,480)
\r
376 s = "-s "+str(tsize[0])+"x480 "
\r
377 x264streamsize=str(tsize[0])+u"x480"
\r
378 x264_bitrate="1500"
\r
379 elif size == "FullHD":
\r
380 tsize=getParSize(pin,1080)
\r
381 s = "-s "+str(tsize[0])+"x1080 "
\r
382 x264streamsize=str(tsize[0])+u"x1080"
\r
383 x264_bitrate="5000"
\r
385 tsize=getParSize(pin,480)
\r
386 s = "-s "+str(tsize[0])+"x480 "
\r
387 x264streamsize=str(tsize[0])+u"x480"
\r
388 x264_bitrate="1250"
\r
389 elif size == "QVGA_BASE":
\r
390 tsize=getParSize(pin,240)
\r
391 s = "-s "+str(tsize[0])+"x240 "
\r
392 x264streamsize=str(tsize[0])+u"x240"
\r
394 elif size == "WVGA_BASE":
\r
395 tsize=getParSize(pin,480)
\r
396 s = "-s "+str(tsize[0])+"x480 "
\r
397 x264streamsize=str(tsize[0])+u"x480"
\r
398 x264_bitrate="1500"
\r
400 tsize=getParSize(pin,720)
\r
401 s = "-s "+str(tsize[0])+"x720 "
\r
402 x264streamsize=str(tsize[0])+u"x720"
\r
403 x264_bitrate="2500"
\r
405 tsize=getMovieBaseSize2(pin)
\r
407 s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" "
\r
408 x264fps="30000/1001"
\r
409 x264tune=x264tune+" --tff --nal-hrd vbr"
\r
411 x264streamsize=str(tsize[0])+u"x"+str(tsize[1])
\r
413 x264preset=u"ultrafast"
\r
415 x264preset=u"veryfast"
\r
419 x264preset=u"medium"
\r
423 x264preset=u"slower"
\r
425 x264preset=u"medium"
\r
426 if size == "WVGA_BASE" or size == "QVGA_BASE":
\r
427 x264profile=" --level 32 --profile baseline "
\r
429 x264profile=" --level 41 --profile high "
\r
432 os.environ['LANG']="ja_JP.UTF-8"
\r
433 log_ffmpeg=recdblist.getLogTitle(pin)+".ffmpeg.log"
\r
434 log_x264=recdblist.getLogTitle(pin)+".x264.log"
\r
435 exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - 2> \""+log_ffmpeg+"\" | "
\r
436 exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf)
\r
437 exe = "nice -n 19 " + exe+" 2>&1 | "+tee+" \""+log_x264+"\""
\r
439 #recdblist.addCommandSelfLog(log_ffmpeg,recdblist.getLogTitle(pin)+".log.zip")
\r
440 #recdblist.addCommandSelfLog(log_x264,recdblist.getLogTitle(pin)+".log.zip")
\r
441 recdblist.printutf8(exe)
\r
442 recdblist.addCommandSelfLog(pin,exe)
\r
444 txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
447 recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
\r
448 zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip"))
\r
449 zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip"))
\r
450 os.remove(log_ffmpeg)
\r
451 os.remove(log_x264)
\r
452 def getMovieBaseSize(pin):
\r
453 ffmpeg=configreader.getConfPath("ffmpeg")
\r
454 os.environ['LANG']="ja_JP.UTF-8"
\r
455 exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
\r
456 txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
457 rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
\r
460 txtls=txts.split("\n")
\r
464 sizetxt=rM.group(1)
\r
466 tX=int(sizetxt.split("x")[0])
\r
467 tY=int(sizetxt.split("x")[1])
\r
468 tEX=int(partxt.split(":")[0])
\r
469 tEY=int(partxt.split(":")[1])
\r
473 return [sizeMaxX,sizeMaxY]
\r
474 def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処
\r
475 ffmpeg=configreader.getConfPath("ffmpeg")
\r
476 os.environ['LANG']="ja_JP.UTF-8"
\r
477 exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
\r
478 txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
479 rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
\r
482 txtls=txts.split("\n")
\r
486 sizetxt=rM.group(1)
\r
488 tX=int(sizetxt.split("x")[0])
\r
489 tY=int(sizetxt.split("x")[1])
\r
490 tEX=int(partxt.split(":")[0])
\r
491 tEY=int(partxt.split(":")[1])
\r
495 os.remove(pin+".size.ts")
\r
496 return [sizeMaxX,sizeMaxY]
\r
497 def getMoviePAR(pin):
\r
498 ffmpeg=configreader.getConfPath("ffmpeg")
\r
499 os.environ['LANG']="ja_JP.UTF-8"
\r
500 exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
\r
501 txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
502 rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
\r
506 txtls=txts.split("\n")
\r
510 sizetxt=rM.group(1)
\r
512 tX=int(sizetxt.split("x")[0])
\r
513 tY=int(sizetxt.split("x")[1])
\r
514 tEX=int(dartxt.split(":")[0])
\r
515 tEY=int(dartxt.split(":")[1])
\r
518 if tX==1920 and tY==1080:
\r
525 def getMoviePAR2(pin):
\r
526 ffmpeg=configreader.getConfPath("ffmpeg")
\r
527 os.environ['LANG']="ja_JP.UTF-8"
\r
528 exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
\r
529 txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
530 rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
\r
534 txtls=txts.split("\n")
\r
538 sizetxt=rM.group(1)
\r
540 tX=int(sizetxt.split("x")[0])
\r
541 tY=int(sizetxt.split("x")[1])
\r
542 tEX=int(dartxt.split(":")[0])
\r
543 tEY=int(dartxt.split(":")[1])
\r
546 if tX==1920 and tY==1080:
\r
552 os.remove(pin+".size.ts")
\r
554 def getMovieDAR(pin):
\r
555 ffmpeg=configreader.getConfPath("ffmpeg")
\r
556 os.environ['LANG']="ja_JP.UTF-8"
\r
557 exe=ffmpeg+u" -i \""+pin+"\" 2>&1"
\r
558 txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
559 rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
\r
563 txtls=txts.split("\n")
\r
567 sizetxt=rM.group(1)
\r
569 tX=int(sizetxt.split("x")[0])
\r
570 tY=int(sizetxt.split("x")[1])
\r
571 tEX=int(dartxt.split(":")[0])
\r
572 tEY=int(dartxt.split(":")[1])
\r
575 if tX==1920 and tY==1080:
\r
582 def getMovieDAR2(pin):
\r
583 ffmpeg=configreader.getConfPath("ffmpeg")
\r
584 os.environ['LANG']="ja_JP.UTF-8"
\r
585 exe=ffmpeg+u" -ss 5 -fs 1 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
\r
586 txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
\r
587 rT=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
\r
591 txtls=txts.split("\n")
\r
595 sizetxt=rM.group(1)
\r
597 tX=int(sizetxt.split("x")[0])
\r
598 tY=int(sizetxt.split("x")[1])
\r
599 tEX=int(dartxt.split(":")[0])
\r
600 tEY=int(dartxt.split(":")[1])
\r
603 if tX==1920 and tY==1080:
\r
609 os.remove(pin+".size.ts")
\r
611 def getParSize(pin,y):
\r
612 tSize=getMovieBaseSize2(pin)
\r
614 tX=tSize[0]*10*y/tSize[1]
\r
616 if tX>int(tX/10)*10:
\r
624 def getX264CoreVersion():
\r
625 x264=configreader.getConfPath("x264")
\r
626 t1=commands.getoutput(x264+" --help|grep core")
\r
627 rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z")
\r
633 def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0):
\r
634 x264=configreader.getConfPath("x264")
\r
635 os.environ['LANG']="ja_JP.UTF-8"
\r
636 x264_sar="--sar "+sar
\r
637 x264preset=u"--preset "+preset
\r
638 x264fps="--fps "+fps
\r
640 x264bitrate=u"--bitrate "+str(bitrate)
\r
642 x264crf=u"--crf "+str(crf)
\r
643 x264_addline=configreader.getConfEnv("x264_addline")
\r
646 xtt=configreader.getConfEnv("x264_thread")
\r
649 x264_thread=str(xtt)
\r
652 x264_addline=configreader.getConfEnv("x264_addline")
\r
653 if getX264CoreVersion()>103:
\r
654 x264res=u"--input-res "+x264streamsize
\r
655 exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin
\r
657 exe=u"nice -n 19 "+x264+" "+x264_sar+" "+x264crf+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize
\r