OSDN Git Service

d47e9aabba11ff4864008210abf93c93c4d3bebc
[rec10/rec10-git.git] / rec10 / ts2x264.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
5 import commands
6 import configreader
7 import os
8 import os.path
9 import sys
10 import re
11 import random
12 import time
13 import traceback
14 import zip
15
16 import recdblist
17 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
18     """
19     pinで指定されたファイルをpoutにx264でエンコードして書き出す
20     """
21     dualpass = 0
22     is24fps=0
23     size="HD"
24     crf=18
25     quality=4
26     quality=int(configreader.getConfEnv("x264_preset"))
27     crf=int(configreader.getConfEnv("crf"))
28     deinterlace=1
29     bluray=0
30     sar=1
31     if re.search("H", opts):
32         size = "HD"
33     if re.search("S", opts):
34         size = "WVGA"
35     if re.search("F", opts):
36         size = "FullHD"
37     if re.search("W",opts):
38         size = "WVGA"
39     if re.search("MW1",opts):
40         size = "QVGA_BASE"
41         crf=crf+4
42         sar=0
43     if re.search("MW2", opts):
44         size = "WVGA_BASE"
45         crf=crf+2
46         sar=0
47     if re.search("v", opts):
48         is24fps=1
49         crf=int(configreader.getConfEnv("animation_crf"))
50     if re.search("a", opts):
51         is24fps=1
52         crf=int(configreader.getConfEnv("animation_crf"))
53     if re.search("I", opts):
54         deinterlace=0
55     if re.search("B", opts):
56         bluray=1
57         sar=0
58     if re.search("q",opts):
59         quality=quality-2
60     if re.search("w",opts):
61         quality=quality-1
62     if re.search("e",opts):
63         quality=quality+1
64     if re.search("r",opts):
65         quality=quality+2
66     if re.search("u",opts):
67         crf=crf+2
68     if re.search("i",opts):
69         crf=crf+1
70     if re.search("o",opts):
71         crf=crf-1
72     if re.search("p",opts):
73         crf=crf-2
74     if re.search("d",opts):#二カ国語放送の場合
75         tm2v=pin.replace(".ts",".m2v")
76         encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar)
77     elif re.search("5",opts):#5.1chの場合
78         encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar)
79     elif re.search("b",opts):#BonTsDemuxを使いたい場合
80         tm2v=pin.replace(".ts",".m2v")
81         encodeFfmpegSar(tm2v,pout,size,is24fps,quality,crf,deinterlace=deinterlace,usebluray=bluray,usesar=sar)
82     else:
83         try:
84             encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=1,usebluray=bluray,usesar=sar)
85             if os.path.exists(pout):
86                 if not os.path.getsize(pout)>1*1000:
87                     recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200)
88                     try:
89                         encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar)
90                     except Exception, inst:
91                         recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
92             else:
93                 recdblist.addCommonlogEX("Warning", "Old mencoder option used.","","",log_level=200)
94                 try:
95                     encodeMencoderSar(pin, pout,size,is24fps,quality,crf,deinterlace=deinterlace,uselavf=0,usebluray=bluray,usesar=sar)
96                 except Exception, inst:
97                     recdblist.addCommonlogEX("Error", "ts2x264_mencoder_old(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
98         except Exception, inst:
99             recdblist.addCommonlogEX("Error", "ts2x264(ts2x264.py)", str(type(inst)), str(inst)+traceback.format_exc(),log_level=200)
100 def encodeMencoderSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,uselavf=0,usebluray=0,usesar=1):
101     mencoder=configreader.getConfPath("mencoder")
102     tee=configreader.getConfPath("tee")
103     encvf=""
104     txt=""
105     encvf="-sws 9 -vf yadif=0,pp=l5"
106     harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
107     ofps="-ofps 30000/1001"
108     fps="-fps 30000/1001"
109     x264fps="30000/1001 --keyint 30"
110     x264streamsize=""
111     x264preset=""
112     x264tune=""
113     x264_bitrate="5000"
114     x264interlaced=0
115     x264sar="1:1"
116     tsar=getMoviePAR2(pin)
117     if usesar==1:
118         x264sar=str(tsar[0])+u":"+str(tsar[1])
119     lavft=""
120     if is24fps==1:
121         ofps="-ofps 24000/1001"
122         fps="-fps 30000/1001"
123         x264fps="24000/1001 --keyint 24"
124         x264tune="--tune animation"
125         encvf="-sws 9 -vf pullup,softskip"
126         harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
127     if size == "HD":
128         tsize=getParSize(pin,720)
129         if usesar==1:
130             encvf = encvf + ",scale=-3:720::0:3"+harddup
131             x264streamsize=str(tsize[0])+u"x720"
132         else:
133             encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
134             x264streamsize=u"1280x720"
135         x264_bitrate="2500"
136     elif size == "WVGA":
137         tsize=getParSize(pin,480)
138         if usesar==1:
139             encvf = encvf + ",scale=-3:480::0:3"+harddup
140             x264streamsize=str(tsize[0])+u"x480"
141         else:
142             encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup
143             x264streamsize=u"854x480"
144         x264_bitrate="1500"
145     elif size == "FullHD":
146         tsize=getParSize(pin,1080)
147         if usesar==1:
148             encvf = encvf + ",scale=-3:1080::0:3"+harddup
149             x264streamsize=str(tsize[0])+u"x1080"
150         else:
151             encvf = encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup
152             x264streamsize=u"1920x1080"
153         x264_bitrate="5000"
154     elif size == "QVGA_BASE":
155         tsize=getParSize(pin,240)
156         if usesar==1:
157             encvf = encvf + ",scale=-3:240::0:3"+harddup
158             x264streamsize=str(tsize[0])+u"x240"
159         else:
160             encvf = encvf + ",scale=320:-2::0:3,expand=320:240"+harddup
161             x264streamsize=u"320x240"
162         x264_bitrate="300"
163     elif size == "WVGA_BASE":
164         tsize=getParSize(pin,480)
165         if usesar==1:
166             encvf = encvf + ",scale=-3:480::0:3"+harddup
167             x264streamsize=str(tsize[0])+u"x480"
168         else:
169             encvf = encvf + ",scale=-2:480::0:3,expand=854:480"+harddup
170             x264streamsize=u"854x480"
171         x264_bitrate="1500"
172     else:
173         tsize=getParSize(pin,720)
174         if usesar==1:
175             encvf = encvf + ",scale=-3:720::0:3"+harddup
176             x264streamsize=str(tsize[0])+u"x720"
177         else:
178             encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
179             x264streamsize=u"1280x720"
180         x264_bitrate="2500"
181     if deinterlace==0:
182         tsize=getMovieBaseSize2(pin)
183         ofps="-ofps 30000/1001"
184         #fps="-fps 30000/1001"
185         fps=""
186         x264fps="30000/1001 --keyint 30"
187         x264interlaced=1
188         encvf="-vf hqdn3d=2:1:2"
189         harddup=",harddup"
190         encvf=encvf+harddup
191         x264streamsize=str(tsize[0])+u"x"+str(tsize[1])
192         if usebluray==1:
193             encvf = u"-sws 9 "+encvf + ",scale=-2:1080::0:3,expand=1920:1080"+harddup
194             x264streamsize=u"1920x1080"
195     if tsize[0] <= 0 or tsize[1] <= 0:
196         encvf="-sws 9 -vf yadif=0,pp=l5"
197         harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
198         ofps="-ofps 30000/1001"
199         fps="-fps 30000/1001"
200         x264fps="30000/1001 --keyint 30"
201         tsize=[1280,720]
202         encvf = encvf + ",scale=-2:720::0:3,expand=1280:720"+harddup
203         x264streamsize=u"1280x720"
204         x264_bitrate="2500"
205     if quality==1:
206         x264preset=u"ultrafast"
207     elif quality==2:
208         x264preset=u"veryfast"
209     elif quality==3:
210         x264preset=u"fast"
211     elif quality==4:
212         x264preset=u"medium"
213     elif quality==5:
214         x264preset=u"slow"
215     elif quality==6:
216         x264preset=u"slower"
217     else:
218         x264preset=u"medium"
219     if size == "WVGA_BASE" or size == "QVGA_BASE":
220         x264profile=" --level 32 --profile baseline "
221     else:
222         x264profile=" --level 41 --profile high "
223     if uselavf==1:
224         lavft="-demuxer lavf "
225     x264crf=str(crf)
226     os.environ['LANG']="ja_JP.UTF-8"
227     random.seed(pin)
228     random.jumpahead(10)
229     temptime=int(time.time())
230     temptime=temptime % 9697
231     random.jumpahead(temptime)
232     streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 99999999)))
233     unicode(commands.getoutput(u"mkfifo "+streampath),'utf-8','ignore')
234     logmencoder=recdblist.getLogTitle(pin)+".mencoder.log"
235     logx264=recdblist.getLogTitle(pin)+".x264.log"
236     encexe=mencoder+u" \""+pin+u"\" -quiet -vfm ffmpeg "+lavft+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" 2>&1 | "+tee+" \""+logmencoder+"\" & "
237     encexe=encexe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout, streampath, x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray)
238     #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
239     encexe=u"nice -n 19 " +encexe+" 2>&1 | "+tee+" \""+logx264+"\""
240     try:
241         recdblist.addCommandSelfLog(pin, encexe)
242     except Exception, inst:
243         print type(inst)
244         print str(inst)
245         print traceback.print_exc(file=sys.stdout)
246     recdblist.printutf8(encexe)
247     txt=""
248     try:
249         txt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8','ignore')
250     except:
251         ""
252     os.remove(streampath)
253     zip.addFile2FileZip(logmencoder, recdblist.getLogTitle(pin)+".log.zip")
254     zip.addFile2FileZip(logx264, recdblist.getLogTitle(pin)+".log.zip")
255     os.remove(logmencoder)
256     os.remove(logx264)
257     recdblist.addCommandLog(pin, u"Mencoder", encexe, txt)
258 #    recdblist.addCommandLogTar(pin,u"Mencoder","mencoder", encexe,txt)
259 def encodeFfmpegSar(pin,pout,size,is24fps,quality,crf,deinterlace=1,usebluray=0,usesar=1):
260     """
261
262     """
263     ffmpeg=configreader.getConfPath("ffmpeg")
264     tee=configreader.getConfPath("tee")
265     fps=u"-r 29.970030 "
266     x264fps="30000/1001 --keyint 30"
267     x264streamsize=""
268     x264preset=""
269     x264tune=""
270     x264_bitrate="2500"
271     x264_thread="auto"
272     x264interlaced=0
273     tsar=getMoviePAR2(pin)
274     filter="-deinterlace"
275     x264sar=str(tsar[0])+":"+str(tsar[1])
276     if is24fps==1:
277         fps=u"-r 23.976023 "
278         x264fps="24000/1001 --keyint 24"
279         x264tune="--tune animation"
280     if size == "HD":
281         tsize=getParSize(pin,720)
282         s = "-s "+str(tsize[0])+"x720 "
283         x264streamsize=str(tsize[0])+u"x720"
284         x264_bitrate="2500"
285     elif size == "WVGA":
286         tsize=getParSize(pin,480)
287         s = "-s "+str(tsize[0])+"x480 "
288         x264streamsize=str(tsize[0])+u"x480"
289         x264_bitrate="1500"
290     elif size == "FullHD":
291         tsize=getParSize(pin,1080)
292         s = "-s "+str(tsize[0])+"x1080 "
293         x264streamsize=str(tsize[0])+u"x1080"
294         x264_bitrate="5000"
295     elif size == "SD":
296         tsize=getParSize(pin,480)
297         s = "-s "+str(tsize[0])+"x480 "
298         x264streamsize=str(tsize[0])+u"x480"
299         x264_bitrate="1250"
300     elif size == "QVGA_BASE":
301         tsize=getParSize(pin,240)
302         s = "-s "+str(tsize[0])+"x240 "
303         x264streamsize=str(tsize[0])+u"x240"
304         x264_bitrate="300"
305     elif size == "WVGA_BASE":
306         tsize=getParSize(pin,480)
307         s = "-s "+str(tsize[0])+"x480 "
308         x264streamsize=str(tsize[0])+u"x480"
309         x264_bitrate="1500"
310     else:
311         tsize=getParSize(pin,720)
312         s = "-s "+str(tsize[0])+"x720 "
313         x264streamsize=str(tsize[0])+u"x720"
314         x264_bitrate="2500"
315     if deinterlace==0:
316         tsize=getMovieBaseSize2(pin)
317         fps=""
318         s = "-s "+str(tsize[0])+"x"+str(tsize[1])+" "
319         x264fps="30000/1001 --keyint 30"
320         x264interlaced=1
321         filter=""
322         x264streamsize=str(tsize[0])+u"x"+str(tsize[1])
323     if quality==1:
324         x264preset=u"ultrafast"
325     elif quality==2:
326         x264preset=u"veryfast"
327     elif quality==3:
328         x264preset=u"fast"
329     elif quality==4:
330         x264preset=u"medium"
331     elif quality==5:
332         x264preset=u"slow"
333     elif quality==6:
334         x264preset=u"slower"
335     else:
336         x264preset=u"medium"
337     if size == "WVGA_BASE" or size == "QVGA_BASE":
338         x264profile=" --level 32 --profile baseline "
339     else:
340         x264profile=" --level 41 --profile high "
341     x264crf=str(crf)
342     txt=""
343     os.environ['LANG']="ja_JP.UTF-8"
344     log_ffmpeg=recdblist.getLogTitle(pin)+".ffmpeg.log"
345     log_x264=recdblist.getLogTitle(pin)+".x264.log"
346     exe=ffmpeg+u" -y -i \""+pin+"\" -vcodec rawvideo -pix_fmt yuv420p "+s+fps+" "+filter+" -an -f rawvideo - 2> \""+log_ffmpeg+"\" | "
347     exe=exe+getX264Commandline(x264preset, x264sar, x264fps, x264profile, x264tune, pout,"-", x264streamsize, crf=x264crf,interlaced=x264interlaced,bluray=usebluray)
348     exe = "nice -n 19 " + exe+" 2>&1 | "+tee+" \""+log_x264+"\""
349     txt=""
350     #recdblist.addCommandSelfLog(log_ffmpeg,recdblist.getLogTitle(pin)+".log.zip")
351     #recdblist.addCommandSelfLog(log_x264,recdblist.getLogTitle(pin)+".log.zip")
352     recdblist.printutf8(exe)
353     recdblist.addCommandSelfLog(pin,exe)
354     try:
355         txt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
356     except:
357         ""
358     recdblist.addCommandLog(pin, u"FFmpeg動画エンコード", exe, txt)
359     zip.addFile2FileZip(log_ffmpeg, recdblist.getLogTitle(pin+".log.zip"))
360     zip.addFile2FileZip(log_x264, recdblist.getLogTitle(pin+".log.zip"))
361     os.remove(log_ffmpeg)
362     os.remove(log_x264)
363 def getMovieBaseSize2(pin):##動画開始後すぐに解像度が変更されたときに対処
364     ffmpeg=configreader.getConfPath("ffmpeg")
365     os.environ['LANG']="ja_JP.UTF-8"
366     exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
367     try:
368         recdblist.addCommandSelfLog(pin, exe)
369     except Exception, inst:
370         print type(inst)
371         print str(inst)
372         print traceback.print_exc(file=sys.stdout)
373     txts=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8','ignore')
374     rT=re.compile(u"Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
375     rT2=re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
376     sizeMaxX=0
377     sizeMaxY=0
378     txtls=txts.split("\n")
379     for t in txtls:
380         rM=rT.search(t)
381         rM2=rT2.search(t)
382         if rM:
383             sizetxt=rM.group(1)
384             partxt=rM.group(2)
385             tX=int(sizetxt.split("x")[0])
386             tY=int(sizetxt.split("x")[1])
387             tEX=int(partxt.split(":")[0])
388             tEY=int(partxt.split(":")[1])
389             if sizeMaxX<tX:
390                 sizeMaxX=tX
391                 sizeMaxY=tY
392         if rM2:
393             sizetxt=rM2.group(1)
394             tX=int(sizetxt.split("x")[0])
395             tY=int(sizetxt.split("x")[1])
396             if sizeMaxX<tX:
397                 sizeMaxX=tX
398                 sizeMaxY=tY
399     os.remove(pin+".size.ts")
400     return [sizeMaxX,sizeMaxY]
401 def getMoviePAR2(pin):
402     ffmpeg=configreader.getConfPath("ffmpeg")
403     os.environ['LANG']="ja_JP.UTF-8"
404     exe=ffmpeg+u" -ss 5 -fs 1 -t 10 -i \""+pin+"\" \""+pin+".size.ts\" 2>&1"
405     try:
406         recdblist.addCommandSelfLog(pin, exe)
407     except Exception, inst:
408         print type(inst)
409         print str(inst)
410         print traceback.print_exc(file=sys.stdout)
411     txts = unicode(commands.getoutput(exe.encode('utf-8')), 'utf-8', 'ignore')
412     rT = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+PAR\D+(\d+:\d+)\D+.*\Z")
413     rT2 = re.compile(u".*Stream.*#.*:.*\D+([\d]+x[\d]+)\D+SAR\D+(\d+:\d+)\D+.*DAR\D+(\d+:\d+)\D+.*\Z")
414     sizeMaxX = 0
415     parx = 0
416     pary = 0
417     txtls = txts.split("\n")
418     for t in txtls:
419         rM = rT.match(t)
420         rM2 = rT2.match(t)
421         if rM:
422             sizetxt = rM.group(1)
423             dartxt = rM.group(2)
424             tX = int(sizetxt.split("x")[0])
425             tY = int(sizetxt.split("x")[1])
426             tEX = int(dartxt.split(":")[0])
427             tEY = int(dartxt.split(":")[1])
428             if sizeMaxX < tX:
429                 sizeMaxX = tX
430                 if tX == 1920 and tY == 1080:
431                     parx = 1
432                     pary = 1
433                 else:
434                     parx = tEX
435                     pary = tEY
436         rM = rT.match(t)
437         if rM2:
438             sizetxt = rM2.group(1)
439             sartxt = rM2.group(2)
440             dartxt = rM2.group(3)
441             tX = int(sizetxt.split("x")[0])
442             tY = int(sizetxt.split("x")[1])
443             tEX = int(dartxt.split(":")[0])
444             tEY = int(dartxt.split(":")[1])##dar=sarxpar
445             tSX = int(sartxt.split(":")[0])
446             tSY = int(sartxt.split(":")[1])##par=dar/sar= darx*pary*sary=dary*parx*sarx
447             if sizeMaxX < tX:
448                 sizeMaxX = tX
449                 if tX == 1920 and tY == 1080:
450                     parx = 1
451                     pary = 1
452                 else:
453                     if tEX * tSY == tEY * tSX:
454                         parx = 1
455                         pary = 1
456                     elif tEX * tSY * 3 == tEY * tSX * 4:
457                         parx = 4
458                         pary = 3
459                     elif tEX * tSY * 4 == tEY * tSX * 3:
460                         parx = 3
461                         pary = 4
462                     elif tEX * tSY * 9 == tEY * tSX * 16:
463                         parx = 16
464                         pary = 9
465                     elif tEX * tSY * 16 == tEY * tSX * 9:
466                         parx = 9
467                         pary = 16
468     os.remove(pin+".size.ts")
469     return [parx,pary]
470 def getParSize(pin,y):
471     tSize=getMovieBaseSize2(pin)
472     if tSize[1] != 0 :
473         tX=tSize[0]*10*y/tSize[1]
474         tY=y
475         if tX>int(tX/10)*10:
476             tX=tX/10+1
477         else:
478             tX=tX/10
479     else:
480         tX=-1
481         tY=-1
482     return [tX,tY]
483 def getX264CoreVersion():
484     x264=configreader.getConfPath("x264")
485     #print x264
486     t1=commands.getoutput(x264+" --help|grep core")
487     #print t1
488     rT=re.compile(u"x264 core:(\d*)[\d]*.*\Z")
489     rM=rT.match(t1)
490     v=-1
491     if rM:
492         v=int(rM.group(1))
493     return v
494 def getX264Commandline(preset,sar,fps,x264profile,x264tune,pout,pin,x264streamsize,crf=-1,bitrate=0,interlaced=0,bluray=0):
495     x264=configreader.getConfPath("x264")
496     os.environ['LANG']="ja_JP.UTF-8"
497     x264_sar="--sar "+sar
498     x264preset=u"--preset "+preset
499     x264fps="--fps "+fps
500     x264interlaced=""
501     x264bluray=""
502     x264_addline=configreader.getConfEnv("x264_addline")
503     if crf==-1:
504         x264bitrate=u"--bitrate "+str(bitrate)
505     else:
506         x264crf=u"--crf "+str(crf)
507     if interlaced==1:
508         x264interlaced="--tff --nal-hrd vbr"
509     if bluray==1:
510         if getX264CoreVersion()<115:
511             x264bluray=" --weightp 1 --nal-hrd vbr --bframes 3 --b-pyramid none --open-gop bluray --slices 4 --aud --colorprim bt709 --transfer bt709 "
512             x264_addline=""
513             if fps=="24000/1001 --keyint 24" or fps =="24000/1001":
514                 if x264streamsize=="1280x720":
515                     x264bluray=u"--ref 6 "+x264bluray
516                 if x264streamsize=="1920x1080":
517                     x264bluray=u"--ref 4 "+x264bluray
518             elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":
519                 if x264streamsize=="1280x720":
520                     x264bluray=u"--ref 6 --pulldown double "+x264bluray
521                 if x264streamsize=="1920x1080":
522                     if interlaced==0:
523                         x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray
524                     else:
525                         x264bluray=u"--ref 4 "+x264bluray
526         elif getX264CoreVersion()>=115:
527             x264bluray=" --slices 4 --bluray-compat --nal-hrd vbr --bframes 3 --b-pyramid strict --aud --colorprim bt709 --transfer bt709 "
528             x264_addline=""
529             if fps=="24000/1001 --keyint 24" or fps =="24000/1001":
530                 if x264streamsize=="1280x720":
531                     x264bluray=u"--ref 6 "+x264bluray
532                 if x264streamsize=="1920x1080":
533                     x264bluray=u"--ref 4 "+x264bluray
534             elif fps=="30000/1001 --keyint 30" or fps =="30000/1001":
535                 if x264streamsize=="1280x720":
536                     x264bluray=u"--ref 6 --pulldown double "+x264bluray
537                 if x264streamsize=="1920x1080":
538                     if interlaced==0:
539                         x264bluray=u"--ref 4 --fake-interlaced --pic-struct "+x264bluray
540                     else:
541                         x264bluray=u"--ref 4 "+x264bluray
542     x264_thread="auto"
543     try:
544         xtt=configreader.getConfEnv("x264_thread")
545         xtt=int(xtt)
546         if xtt>0:
547             x264_thread=str(xtt)
548     except:
549         x264_thread="auto"
550     x264_addline=configreader.getConfEnv("x264_addline")
551     if getX264CoreVersion()>103:
552         x264res=u"--input-res "+x264streamsize
553         exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" "+x264res+" -o \""+pout+"\" "+pin
554     else:
555         exe=u"nice -n 19 "+x264+" --demuxer raw --vbv-maxrate 30000 --vbv-bufsize 25000 "+x264_sar+" "+x264crf+u" "+x264bluray+u" "+x264interlaced+u" "+x264_addline+u" --colormatrix bt709 --threads "+x264_thread+" "+x264profile+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+pin+" "+x264streamsize
556     return exe