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):
66 mencoder=configreader.getpath("mencoder")
67 x264=configreader.getpath("x264")
70 encvf="-vf yadif=0,pp=l5"
71 harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
72 ofps="-ofps 30000/1001"
74 x264fps="--fps 30000/1001"
79 x264_addline=configreader.getenv("x264_addline")
81 ofps="-ofps 24000/1001"
83 x264fps="--fps 24000/1001"
84 x264tune="--tune animation"
85 encvf="-vf pullup,softskip"
86 harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
88 encvf = encvf + ",scale=1280:720::0:3"+harddup
89 x264streamsize=u"1280x720"
92 encvf = encvf + ",scale=854:480::0:3"+harddup
93 x264streamsize=u"854x480"
95 elif size == "FullHD":
96 encvf = encvf + ",scale=1920:1080::0:3"+harddup
97 x264streamsize=u"1920x1080"
100 encvf = encvf + ",scale=720:480::0:3"+harddup
101 x264streamsize=u"720x480"
104 encvf = encvf + ",scale=1280:720::0:3"+harddup
105 x264streamsize=u"1280x720"
108 x264preset=u"--preset ultrafast"
110 x264preset=u"--preset veryfast"
112 x264preset=u"--preset fast"
114 x264preset=u"--preset medium"
116 x264preset=u"--preset slow"
118 x264preset=u"--preset slower"
119 x264crf=u"--crf "+str(crf)
120 os.environ['LANG']="ja_JP.UTF-8"
123 streampath=os.path.join(os.path.dirname(pin),str(random.randint(10000, 999999)))
124 os.system(u"mkfifo "+streampath)
125 encexe=mencoder+u" \""+pin+u"\" -vfm ffmpeg -quiet -sws 9 "+encvf+u",format=i420 "+fps+" "+ofps+" -oac mp3lame -ovc raw -of rawvideo -o \""+streampath+"\" &"
126 encexe=encexe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u" "+u" --vbv-bufsize "+str(int(x264_maxrate)*2)+u" --vbv-maxrate "+x264_maxrate+u" --level 41 --profile high "+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" "+streampath+" "+x264streamsize
127 encexe=u"nice -n 19 " +encexe
128 recdblist.printutf8(encexe)
129 txt=txt+"Cmd : "+encexe+"\n"
132 txtt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8')
135 os.system("rm "+streampath)
137 recdblist.addlog( pin, txt, "mencoder-log")
139 def encode_ffmpeg(pin,pout,size,is24fps,quality,crf):
143 ffmpeg=configreader.getpath("ffmpeg")
144 x264=configreader.getpath("x264")
146 x264fps="--fps 30000/1001"
151 x264_addline=configreader.getenv("x264_addline")
154 x264streamsize=u"1280x720"
158 x264streamsize=u"854x480"
160 elif size == "FullHD":
162 x264streamsize=u"1920x1080"
166 x264streamsize=u"720x480"
170 x264streamsize=u"1280x720"
173 x264preset=u"--preset ultrafast"
175 x264preset=u"--preset veryfast"
177 x264preset=u"--preset fast"
179 x264preset=u"--preset medium"
181 x264preset=u"--preset slow"
183 x264preset=u"--preset slower"
184 x264crf=u"--crf "+str(crf)
186 os.environ['LANG']="ja_JP.UTF-8"
187 exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+fps+"-deinterlace -an -f rawvideo - |"
188 exe=exe+u" nice -n 19 "+x264+" "+x264crf+u" "+x264_addline+u" --vbv-bufsize "+str(int(x264_maxrate)*2)+u" --vbv-maxrate "+x264_maxrate+u" --level 41 --profile high "+x264preset+" "+x264tune+" "+x264fps+" -o \""+pout+"\" - "+x264streamsize
189 txt=txt+"Cmd : "+exe+"\n"
190 exe = "nice -n 19 " + exe
191 txt=txt+"Cmd : "+exe+"\n"
193 recdblist.printutf8(exe)
195 txtt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
199 recdblist.addlog( pin, txt, "dual audio ffmpeg-log")