dualpass = 0
isvfr=0
is24fps=0
+ islight=0
size="Tall"
+ quality=5
if re.search("2", opts):
dualpass = 1
if re.search("H", opts):
size = "HD"
+ quality=7
if re.search("S", opts):
size = "SD"
+ quality=3
if re.search("F", opts):
size = "FHD"
+ quality=5
if re.search("L", opts):
size = "Short"
+ quality=3
if re.search("G", opts):
size = "LowHD"
+ quality=5
if re.search("v", opts):
- isvfr=1
+ is24fps=1
if re.search("a", opts):
is24fps=1
+ quality=quality+2
+ if re.search("l",opts):
+ quality=quality-2
+ if re.search("h",opts):
+ quality=quality+2
if re.search("d",opts):
- encode_ffmpeg(pin, pout, size, dualpass)
+ encode_ffmpeg(pin, pout, size, dualpass ,is24fps , quality)
+ elif re.search("5",opts):
+ encode_ffmpeg(pin, pout, size, dualpass ,is24fps , quality)
else:
- encode(pin, pout,size,isvfr,dualpass,is24fps)
-def encode(pin,pout,size,isvfr,is2pass,is24fps):
+ encode(pin, pout,size,dualpass,is24fps,quality)
+def encode(pin,pout,size,is2pass,is24fps,quality):
encvf=""
txt=""
- encvf="-vf yadif=0,pp=ac,pp=mb"
- harddup=",pp=ac,hqdn3d=2:1:2,harddup"
+ encvf="-vf yadif=0,pp=l5"
+ harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
ofps="-ofps 30000/1001"
fps="-fps 30000/1001"
bm=1
scale=""
- x264enc1=":me=hex:bframes=3"
- x264enc2=":direct=auto:me=umh:bframes=3"
- crf=""
- if is24fps==1:
- ofps="-ofps 24000/1001"
- fps="-fps 30000/1001"
- encvf="-vf pullup,softskip"
- harddup=",pp=ac,pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
- bm=1
- x264enc1=":me=hex:bframes=3"
- x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b"
- if isvfr==1:
- ofps="-ofps 60000/1001"
- fps="-fps 60000/1001"
- encvf="-vf tfields=1,hqdn3d=2:1:2"
- #encvf="-vf yadif=1,pp=ac,pp=mb"
- harddup=",pp=ac,pp=l5,unsharp=l3x3:0.75:c3x3:0.75,harddup"
- #encvf="-vf pullup,softskip,pp=ac"
- #encvf="-vf filmdint=io=2997:119880,pp=md"
- bm=1
- x264enc1=":me=hex:bframes=3"
- x264enc2=":frameref=3:subq=7:8x8dct:direct=auto:me=umh:bframes=3:weight_b"
+ bnum=2000
if size == "HD":
- encvf = encvf + ",scale=1280:720::0:4"+harddup
+ encvf = encvf + ",scale=1280:720::0:3"+harddup
bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
+ bnum=tv2avi.Bitrate_HD*bm
crf="crf=20"
elif size == "SD":
- encvf = encvf + ",scale=720:480::0:4"+harddup
+ encvf = encvf + ",scale=720:480::0:3"+harddup
bitrate = "bitrate=" + str(tv2avi.Bitrate_SD*bm)
+ bnum=tv2avi.Bitrate_SD*bm
crf="crf=20"
elif size == "FHD":
- encvf = encvf + ",scale=1920:1080::0:4"+harddup
+ encvf = encvf + ",scale=1920:1080::0:3"+harddup
bitrate = "bitrate=" + str(tv2avi.Bitrate_FHD*bm)
+ bnum=tv2avi.Bitrate_FHD*bm
crf="crf=22"
elif size == "Short":
encvf = encvf +harddup
bitrate = "bitrate=" + str(tv2avi.Bitrate_Short*bm)
+ bnum=tv2avi.Bitrate_Short*bm
crf="crf=20"
elif size == "LowHD":
- encvf = encvf + ",scale=1280:720::0:4"+harddup
+ encvf = encvf + ",scale=1280:720::0:3"+harddup
bitrate = "bitrate=" + str(tv2avi.Bitrate_LowHD*bm)
+ bnum=tv2avi.Bitrate_LowHD*bm
crf="crf=22"
else:
- encvf = encvf + ",scale=1280:720::0:4"+harddup
+ encvf = encvf + ",scale=1280:720::0:3"+harddup
bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
+ bnum=tv2avi.Bitrate_HD*bm
crf="crf=22"
+ x264enc=""
+ x264enc1=""
+ x264enc2=""
+
+ if quality<3:
+ x264enc=":me=dia:partitions=none:frameref=1:subme=0:scenecut=0:trellis=0"
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<5:
+ x264enc=":me=dia:partitions=i8x8,i4x4:frameref=1:subme=1:trellis=0"
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<7:
+ x264enc=""
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<9:
+ x264enc=":direct_pred=auto:frameref=5:subme=8:bframes=1:trellis=1"
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<11:
+ x264enc=":frameref=5:subme=8:subq=7:trellis=2:partitions=all:8x8dct:direct_pred=auto:me=umh:bframes=3"
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ crf=""
+ if is24fps==1:
+ ofps="-ofps 24000/1001"
+ fps="-fps 30000/1001"
+ encvf="-vf pullup,softskip"
+ harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
+ bm=1
+ if quality<3:
+ vbv=":vbv_maxrate="+str(bnum*2)
+ x264enc=":me=dia:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=none:frameref=1:subme=0:scenecut=0:trellis=0"
+ x264enc1=x264enc+vbv
+ x264enc2=x264enc1
+ elif quality<5:
+ vbv=":vbv_maxrate="+str(bnum*2)
+ x264enc=":me=dia:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=i8x8,i4x4:frameref=1:subme=1:trellis=0"
+ x264enc1=x264enc+vbv
+ x264enc2=x264enc1
+ elif quality<7:
+ vbv=":vbv_maxrate="+str(bnum*2)
+ x264enc=":aq-strength=0.6:deblock=1,1:psy-rd=0.4"
+ x264enc1=x264enc+vbv
+ x264enc2=x264enc1
+ elif quality<9:
+ vbv=":vbv_maxrate="+str(bnum*2)
+ x264enc=":direct_pred=auto:aq-strength=0.6:deblock=1,1:psy-rd=0.4:frameref=5:subme=8:bframes=1:trellis=1"
+ x264enc1=x264enc+vbv
+ x264enc2=x264enc1
+ elif quality<11:
+ vbv=":vbv_maxrate="+str(bnum*2)
+ 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"
+ x264enc1=x264enc+vbv
+ x264enc2=x264enc1
if is2pass == 1:
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"
- 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 faac -o \'" + pout + "\'"
+ 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 + "\'"
pas1exe = "nice -n 19 " + pas1exe
pas2exe = "nice -n 19 " + pas2exe
recdblist.printutf8(pas1exe)
- txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
+ txt=txt+"Cmd : "+pas1exe+"\n"
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
recdblist.printutf8(pas2exe)
time.sleep(5)
- txt=txt+unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
else:
- pas1exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -sws 9 -ovc x264 " + encvf+" "+fps + " "+ofps+" -x264encopts " + bitrate +x264enc2+":level_idc=42:threads=auto -oac faac -o \'" + pout + "\'"
+ 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 + "\'"
pas1exe = "nice -n 19 " + pas1exe
recdblist.printutf8(pas1exe)
- txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
- logo=pin
- logo=logo.replace(".sa.avi",".ts")
- logo=logo.replace(".ts",".log")
- f=open(logo,'a')
- s=len(txt)
- stxt=""
- if s>100:
- stxt=txt[s-300:]
- else:
- stxt=txt
- s=stxt.find("\n")
- if s>0:
- s=s+len("\n")
- stxt=stxt[s:]
- txt="\n####mencoder-log_"+size+"####\n"+stxt
- f.write(txt.encode('utf-8'))
- f.close()
+ txt=txt+"Cmd : "+pas1exe+"\n"
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
+ recdblist.addlog( pin, txt, "mencoder-log")
-def encode_ffmpeg(pin,pout,size,is2pass):
- #ffmpeg -i input.m2v -vsync 400 -vcodec h264 -b bitrate k -s sizexsize -deinterlace -
- #x264enc1=":me=hex:bframes=3"
- #:frameref=3:subq=7:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b
- #directpred 3
+def encode_ffmpeg(pin,pout,size,is2pass,is24fps,quality):
+ """
+
+ """
ffmpeg="ffmpeg"
- vf1="-me hex -bframes 3 "
- vf1="-ref 1 -subme 1 -me dia "
- #vf2="-ref 3 -subq 7 -partitions all -direct auto -me umh -level 42 -profile high -bframes 3 -flags2 8x8dct+bpyramid+wpred+mixed_refs+brdo "
- #vf2="-vpre hq -refs 3 -subq 7 -partitions all -level 42 -me_method umh -bf 3 -flags2 dct8x8+bpyramid+wpred+mixed_refs "
- vf2="-vpre hq -level 42 -me_method umh -bf 3 "
+ if quality<3:
+ x264enc="-vpre hq -level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<5:
+ x264enc="-vpre hq -level 42 -me_method dia -partitions parti8x8+parti4x4 -refs 1 -trellis 0 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<7:
+ x264enc="-vpre hq -level 42 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<9:
+ x264enc="-vpre hq -level 42 -directpred auto -refs 5 -subq 6 -bf 1 -trellis 1 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<11:
+ x264enc="-vpre hq -level 42 -refs 5 -subq 7 -trellis 2 -partitions all -directpred auto -me_method umh -bf 3 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ if is24fps==1:
+ if quality<3:
+ x264enc="-vpre hq -level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<5:
+ x264enc="-vpre hq -level 42 -me_method dia -partitions parti8x8+parti4x4 -refs 1 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<7:
+ x264enc="-vpre hq -level 42 -deblockalpha 1 -deblockbeta 1 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<9:
+ x264enc="-vpre hq -level 42 -directpred auto -refs 5 -subq 6 -bf 1 -trellis 1 -deblockalpha 1 -deblockbeta 1 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
+ elif quality<11:
+ x264enc="-vpre hq -level 42 -refs 5 -subq 7 -trellis 2 -partitions all -directpred auto -me_method umh -bf 3 -deblockalpha 1 -deblockbeta 1 "
+ x264enc1=x264enc
+ x264enc2=x264enc1
if size == "HD":
s = "-s 1280x720 "
bitrate = str(tv2avi.Bitrate_HD)
s = "-s 1280x720 "
bitrate = str(tv2avi.Bitrate_LowHD)
crf="crf=22"
+ txt=""
if is2pass==1:
- exe1=ffmpeg+" -y -i \""+pin+"\" -pass 1 -vsync 400 -vcodec libx264 -b "+bitrate+"k "+vf1+s+"-deinterlace -an -passlogfile \'" + pin + ".log\' " + " /dev/null"
- exe2=ffmpeg+" -y -i \""+pin+"\" -pass 2 -vsync 400 -vcodec libx264 -b "+bitrate+"k "+vf2+s+"-deinterlace -an -passlogfile \'" + pin + ".log\' \"" +pout+"\"" #aviにすべきかどうか
- os.system(exe1)
- os.system(exe2)
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe1=ffmpeg+" -y -i \""+pin+"\" -pass 1 -vsync 400 -vcodec libx264 -b "+bitrate+"k "+x264enc1+s+"-deinterlace -an -f avi -passlogfile \'" + pin + ".log\' " + " /dev/null"
+ exe2=ffmpeg+" -y -i \""+pin+"\" -pass 2 -vsync 400 -vcodec libx264 -b "+bitrate+"k "+x264enc2+s+"-deinterlace -an -passlogfile \'" + pin + ".log\' \"" +pout+"\"" #aviにすべきかどうか
+ recdblist.printutf8(exe1)
+ exe1 = "nice -n 19 " + exe1
+ exe2 = "nice -n 19 " + exe2
+ txt=txt+u"Cmd : "+exe1+"\n"+exe2+"\n"
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
else:
- exe=ffmpeg+" -y -i \""+pin+"\" -vsync 400 -vcodec libx264 -b "+bitrate+"k "+vf2+s+"-deinterlace -an \"" +pout+"\""
- os.system(exe)
\ No newline at end of file
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe=ffmpeg+" -y -i \""+pin+"\" -vsync 400 -vcodec libx264 -b "+bitrate+"k "+x264enc+s+"-deinterlace -an \"" +pout+"\""
+ txt=txt+"Cmd : "+exe+"\n"
+ exe = "nice -n 19 " + exe
+ txt=txt+"Cmd : "+exe+"\n"
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
+ recdblist.addlog( pin, txt, "dual audio ffmpeg-log")
+
\ No newline at end of file