3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
13 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
15 pinで指定されたファイルをpoutにx264でエンコードして書き出す
22 quality=int(configreader.getenv("x264_preset"))
23 crf=int(configreader.getenv("crf"))
24 if re.search("H", opts):
26 if re.search("S", opts):
28 if re.search("F", opts):
30 if re.search("W",opts):
32 if re.search("v", opts):
34 crf=int(configreader.getenv("animation_crf"))
35 if re.search("a", opts):
37 crf=int(configreader.getenv("animation_crf"))
38 if re.search("q",opts):
40 if re.search("w",opts):
42 if re.search("e",opts):
44 if re.search("r",opts):
46 if re.search("u",opts):
48 if re.search("i",opts):
50 if re.search("o",opts):
52 if re.search("p",opts):
54 if re.search("d",opts):
55 encode_ffmpeg(pin,pout,size,is24fps,quality,crf)
56 elif re.search("5",opts):
57 encode_ffmpeg(pin,pout,size,is24fps,quality,crf)
60 encode(pin, pout,size,is24fps,quality,crf)
61 except Exception, inst:
62 print "error occures in ts2x264.py encode"
65 def encode(pin,pout,size,is24fps,quality,crf):
68 encvf="-vf yadif=0,pp=l5"
69 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
70 ofps="-ofps 30000/1001"
72 x264fps="--fps 30000/1001"
78 ofps="-ofps 24000/1001"
80 x264fps="--fps 24000/1001"
81 x264tune="--tune animation"
82 encvf="-vf pullup,softskip"
83 harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
85 encvf = encvf + ",scale=1280:720::0:3"+harddup
86 x264streamsize=u"1280x720"
89 encvf = encvf + ",scale=854:480::0:3"+harddup
90 x264streamsize=u"854x480"
92 elif size == "FullHD":
93 encvf = encvf + ",scale=1920:1080::0:3"+harddup
94 x264streamsize=u"1920x1080"
97 encvf = encvf + ",scale=720:480::0:3"+harddup
98 x264streamsize=u"720x480"
101 encvf = encvf + ",scale=1280:720::0:3"+harddup
102 x264streamsize=u"1280x720"
105 x264preset=u"--preset ultrafast"
107 x264preset=u"--preset veryfast"
109 x264preset=u"--preset fast"
111 x264preset=u"--preset medium"
113 x264preset=u"--preset slow"
115 x264preset=u"--preset slower"
116 x264crf=u"--crf "+str(crf)
117 os.environ['LANG']="ja_JP.UTF-8"
120 streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 999999)))
121 os.system(u"mkfifo "+streampath)
122 encexe=u"mencoder \""+pin+u"\" -vfm ffmpeg -quiet -sws 9 "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" &"
123 encexe=encexe+u" nice -n 19 x264 "+x264crf+" --vbv-bufsize "+str(int(x264_maxrate)*2)+u" --vbv-maxrate "+x264_maxrate+u" --level 41 --profile high "+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
124 encexe=u"nice -n 19 " +encexe
125 recdblist.printutf8(encexe)
126 txt=txt+"Cmd : "+encexe+"\n"
129 txtt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8')
132 os.system("rm "+streampath)
134 recdblist.addlog( pin, txt, "mencoder-log")
136 def encode_ffmpeg(pin,pout,size,is24fps,quality,crf):
142 x264fps="--fps 30000/1001"
149 x264streamsize=u"1280x720"
153 x264streamsize=u"854x480"
155 elif size == "FullHD":
157 x264streamsize=u"1920x1080"
161 x264streamsize=u"720x480"
165 x264streamsize=u"1280x720"
168 x264preset=u"--preset ultrafast"
170 x264preset=u"--preset veryfast"
172 x264preset=u"--preset fast"
174 x264preset=u"--preset medium"
176 x264preset=u"--preset slow"
178 x264preset=u"--preset slower"
179 x264crf=u"--crf "+str(crf)
181 os.environ['LANG']="ja_JP.UTF-8"
182 exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
183 exe=exe+u" nice -n 19 x264 "+x264crf+" --vbv-bufsize "+str(int(x264_maxrate)*2)+u" --vbv-maxrate "+x264_maxrate+u" --level 41 --profile high "+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" - "+x264streamsize
184 txt=txt+"Cmd : "+exe+"\n"
185 exe = "nice -n 19 " + exe
186 txt=txt+"Cmd : "+exe+"\n"
188 recdblist.printutf8(exe)
190 txtt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
194 recdblist.addlog( pin, txt, "dual audio ffmpeg-log")