3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
11 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
13 pinで指定されたファイルをpoutにx264でエンコードして書き出す
21 if re.search("2", opts):
23 if re.search("H", opts):
25 if re.search("S", opts):
28 if re.search("F", opts):
30 if re.search("L", opts):
33 if re.search("G", opts):
35 if re.search("v", opts):
37 if re.search("a", opts):
40 if re.search("l",opts):
42 if re.search("h",opts):
44 if re.search("d",opts):
45 encode_ffmpeg(pin, pout, size, dualpass ,is24fps , quality)
46 elif re.search("5",opts):
47 encode_ffmpeg(pin, pout, size, dualpass ,is24fps , quality)
49 encode(pin, pout,size,dualpass,is24fps,quality)
50 def encode(pin,pout,size,is2pass,is24fps,quality):
53 encvf="-vf yadif=0,pp=l5"
54 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
55 ofps="-ofps 30000/1001"
61 encvf = encvf + ",scale=1280:720::0:3"+harddup
62 bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
63 bnum=tv2avi.Bitrate_HD*bm
66 encvf = encvf + ",scale=720:480::0:3"+harddup
67 bitrate = "bitrate=" + str(tv2avi.Bitrate_SD*bm)
68 bnum=tv2avi.Bitrate_SD*bm
71 encvf = encvf + ",scale=1920:1080::0:3"+harddup
72 bitrate = "bitrate=" + str(tv2avi.Bitrate_FHD*bm)
73 bnum=tv2avi.Bitrate_FHD*bm
76 encvf = encvf +harddup
77 bitrate = "bitrate=" + str(tv2avi.Bitrate_Short*bm)
78 bnum=tv2avi.Bitrate_Short*bm
81 encvf = encvf + ",scale=1280:720::0:3"+harddup
82 bitrate = "bitrate=" + str(tv2avi.Bitrate_LowHD*bm)
83 bnum=tv2avi.Bitrate_LowHD*bm
86 encvf = encvf + ",scale=1280:720::0:3"+harddup
87 bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
88 bnum=tv2avi.Bitrate_HD*bm
95 x264enc=":me=dia:partitions=none:frameref=1:subq=2:scenecut=0:trellis=0"
99 x264enc=":me=dia:partitions=i8x8,i4x4:frameref=1:subq=4:trellis=0"
103 x264enc=":8x8dct:bframes=1"
107 x264enc=":direct_pred=auto:frameref=5:subq=6:8x8dct:bframes=3:trellis=1"
111 x264enc=":frameref=5:subq=7:trellis=2:partitions=all:8x8dct:direct_pred=auto:me=umh:bframes=3"
116 ofps="-ofps 24000/1001"
117 fps="-fps 30000/1001"
118 encvf="-vf pullup,softskip"
119 harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
122 vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
123 x264enc=":me=dia:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=none:frameref=1:subq=2:scenecut=0:trellis=0"
127 vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
128 x264enc=":me=dia:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=i8x8,i4x4:frameref=1:subq=4:trellis=0"
132 vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
133 x264enc=":aq-strength=0.6:8x8dct:deblock=1,1:psy-rd=0.4:bframes=1"
137 vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
138 x264enc=":direct_pred=auto:aq-strength=0.6:deblock=1,1:psy-rd=0.4:8x8dct:frameref=5:subq=6:bframes=3:trellis=1"
142 vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
143 x264enc=":frameref=5:subme=8:subq=7:trellis=2:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=all:8x8dct:direct_pred=auto:me=umh:bframes=3"
147 pas1exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -nosound -sws 9 -ovc x264 " + encvf +" "+fps+" "+ofps+" -x264encopts " + bitrate +x264enc1+ ":threads=auto:level_idc=42:pass=1:turbo=2 -passlogfile \'" + pin + ".log\' " + " -o /dev/null"
148 pas2exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -sws 9 -ovc x264 " + encvf +" "+fps+ " "+ofps+" -x264encopts " + bitrate +x264enc2+ ":level_idc=42:threads=auto:pass=2 -passlogfile \'" + pin + ".log\' -oac mp3lame -lameopts cbr:br=256 -o \'" + pout + "\'"
149 pas1exe = "nice -n 19 " + pas1exe
150 pas2exe = "nice -n 19 " + pas2exe
151 recdblist.printutf8(pas1exe)
152 txt=txt+"Cmd : "+pas1exe+"\n"
155 txtt=unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
159 recdblist.printutf8(pas2exe)
163 txtt=unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
168 pas1exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -sws 9 -ovc x264 " + encvf+" "+fps + " "+ofps+" -x264encopts " + bitrate +x264enc+":level_idc=42:threads=auto -oac mp3lame -lameopts cbr:br=256 -o \'" + pout + "\'"
169 pas1exe = "nice -n 19 " + pas1exe
170 recdblist.printutf8(pas1exe)
171 txt=txt+"Cmd : "+pas1exe+"\n"
174 txtt=unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
178 recdblist.addlog( pin, txt, "mencoder-log")
180 def encode_ffmpeg(pin,pout,size,is2pass,is24fps,quality):
186 x264enc="-level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 "
190 x264enc="-level 42 -me_method dia -partitions parti8x8+parti4x4 -refs 1 -trellis 0 "
191 x264enc1="-level 42 -me_method dia -partitions none -refs 1 -trellis 0 "
196 x264enc1="-level 42 -me_method dia -partitions none "
200 x264enc="-level 42 -directpred auto -refs 5 -subq 6 -bf 1 -trellis 1 "
201 x264enc1="-level 42 -me_method dia -partitions none -refs 1 -subq 6 -bf 1 -trellis 1 "
205 x264enc="-level 42 -refs 5 -subq 7 -trellis 2 -partitions all -directpred auto -me_method umh -bf 3 "
206 x264enc1="-level 42 -me_method dia -partitions none -refs 1 -subq 7 -trellis 2 -directpred auto -bf 3 "
211 x264enc="-level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
212 x264enc1="-level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
216 x264enc="-level 42 -me_method dia -partitions parti8x8+parti4x4 -refs 1 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
217 x264enc1="-level 42 -me_method dia -partitions none -refs 1 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
221 x264enc="-level 42 -deblockalpha 1 -deblockbeta 1 "
222 x264enc1="-me_method dia -partitions none -vpre hq -level 42 -deblockalpha 1 -deblockbeta 1 "
226 x264enc="-level 42 -directpred auto -refs 5 -subq 6 -bf 1 -trellis 1 -deblockalpha 1 -deblockbeta 1 "
227 x264enc1="-level 42 -directpred auto -me_method dia -partitions none -refs 1 -subq 6 -bf 1 -trellis 1 -deblockalpha 1 -deblockbeta 1 "
231 x264enc="-level 42 -refs 5 -subq 7 -trellis 2 -partitions all -directpred auto -me_method umh -bf 3 -deblockalpha 1 -deblockbeta 1 "
232 x264enc1="-level 42 -refs 1 -subq 7 -trellis 2 -partitions none -directpred auto -me_method dia -bf 3 -deblockalpha 1 -deblockbeta 1 "
237 bitrate = str(tv2avi.Bitrate_HD)
241 bitrate = str(tv2avi.Bitrate_SD)
245 bitrate = str(tv2avi.Bitrate_FHD)
247 elif size == "Short":
249 bitrate = str(tv2avi.Bitrate_Short)
251 elif size == "LowHD":
253 bitrate = str(tv2avi.Bitrate_LowHD)
257 bitrate = str(tv2avi.Bitrate_LowHD)
261 os.environ['LANG']="ja_JP.UTF-8"
262 exe1=ffmpeg+" -y -i \""+pin+"\" -pass 1 -vsync 400 -vcodec libx264 -vpre fastfirstpass -b "+bitrate+"k "+x264enc1+s+"-deinterlace -an -f avi /dev/null"
263 exe2=ffmpeg+" -y -i \""+pin+"\" -pass 2 -vsync 400 -vcodec libx264 -vpre hq -b "+bitrate+"k "+x264enc2+s+"-deinterlace -an -f avi \"" +pout+"\"" #aviにすべきかどうか
264 recdblist.printutf8(exe1)
265 exe1 = "nice -n 19 " + exe1
266 exe2 = "nice -n 19 " + exe2
267 txt=txt+u"Cmd : "+exe1+"\n"
270 txtt=unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
274 recdblist.addlog( pin, txt, "dual audio ffmpeg-log - 1pass")
276 txt=txt+u"Cmd : "+exe2+"\n"
279 txtt=unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
283 recdblist.addlog( pin, txt, "dual audio ffmpeg-log - 2pass")
285 os.environ['LANG']="ja_JP.UTF-8"
286 exe=ffmpeg+" -y -i \""+pin+"\" -vsync 400 -vcodec libx264 -vpre hq -b "+bitrate+"k "+x264enc+s+"-deinterlace -an \"" +pout+"\""
287 txt=txt+"Cmd : "+exe+"\n"
288 exe = "nice -n 19 " + exe
289 txt=txt+"Cmd : "+exe+"\n"
292 txtt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
296 recdblist.addlog( pin, txt, "dual audio ffmpeg-log")