OSDN Git Service

fix many bug.
[rec10/rec10-git.git] / rec10 / trunk / src / ts2x264.py
index 1e67b17..5356fc2 100644 (file)
@@ -7,9 +7,8 @@ import os
 import re
 import time
 import tv2avi
+import recdblist
 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
-    pout = pout.encode('utf-8')
-    pin = pin.encode('utf-8')
     """
     pinで指定されたファイルをpoutにx264でエンコードして書き出す
     """
@@ -18,6 +17,7 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
         isAnime = 1
     dualpass = 0
     resize=0
+    isvfr=0
     size="Tall"
     if re.search("2", opts):
         dualpass = 1
@@ -31,47 +31,66 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
         size = "Short"
     if re.search("G", opts):
         size = "LowHD"
-    encode(pin, pout,size,isAnime,dualpass)
-def encode(pin,pout,size,isAnime,is2pass):
+    if re.search("v", opts):
+        isvfr=1
+    encode(pin, pout,size,isvfr,dualpass)
+def encode(pin,pout,size,isvfr,is2pass):
     encvf=""
     txt=""
-    if isAnime == 1:
-        encvf = "-vf yadif=3,pp=l5,framestep=2,"
-    else:
-        encvf = "-vf yadif=3,pp=l5,framestep=2,"
+    encvf="-vf yadif=0,pp=mb"
+    harddup=",harddup"
+    ofps="-ofps 30000/1001"
+    bm=1
+    scale=""
+    x264enc1=""
+    x264enc2=""
+    crf=""
+    if isvfr==1:
+        ofps="-ofps 120000/1001"
+        encvf="-vf pullup,softskip,pp=mb"
+        bm=4
+        x264enc1=":me=hex:bframes=3"
+        x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b"
+        harddup=""
     if size == "HD":
-        encvf = encvf + "scale=1280:720,harddup"
-        bitrate = "bitrate=" + tv2avi.Bitrate_HD
+        encvf = encvf + ",scale=1280:720::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
+        crf="crf=20"
     elif size == "SD":
-        encvf = encvf + "scale=720:480,harddup"
-        bitrate = "bitrate=" + tv2avi.Bitrate_SD
+        encvf = encvf + ",scale=720:480::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_SD*bm)
+        crf="crf=20"
     elif size == "FHD":
-        encvf = encvf + "scale=1920:1080,harddup"
-        bitrate = "bitrate=" + tv2avi.Bitrate_FHD
+        encvf = encvf + ",scale=1920:1080::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_FHD*bm)
+        crf="crf=22"
     elif size == "Short":
-        encvf = encvf + "harddup"
-        bitrate = "bitrate=" + tv2avi.Bitrate_Short
+        encvf = encvf +harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_Short*bm)
+        crf="crf=20"
     elif size == "LowHD":
-        encvf = encvf + "scale=1280:720,harddup"
-        bitrate = "bitrate=" + tv2avi.Bitrate_LowHD
+        encvf = encvf + ",scale=1280:720::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_LowHD*bm)
+        crf="crf=22"
     else:
-        encvf = encvf + "scale=1280:720,harddup"
-        bitrate = "bitrate=" + tv2avi.Bitrate_HD
+        encvf = encvf + ",scale=1280:720::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
+        crf="crf=22"
     if is2pass == 1:
-        pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -ofps 30000/1001 -x264encopts " + bitrate + ":threads=auto:pass=1:turbo=2 -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o /dev/null"
-        pas2exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -ofps 30000/1001 -x264encopts " + bitrate + ":threads=auto:pass=2 -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o \'" + pout + "\'"
+        pas1exe = "mencoder \'" + pin + "\' -noskip -quiet -nosound -sws 9 -ovc x264 " + encvf + " "+ofps+" -x264encopts " + bitrate +x264enc1+ ":threads=auto:pass=1:turbo=2 -passlogfile \'" + pin + ".log\' " + " -o /dev/null"
+        pas2exe = "mencoder \'" + pin + "\' -noskip -noodml -quiet -nosound -sws 9 -ovc x264 " + encvf + " "+ofps+" -x264encopts " + bitrate +x264enc2+ ":threads=auto:pass=2 -passlogfile \'" + pin + ".log\' " + " -o \'" + pout + "\'"
         pas1exe = "nice -n 19 " + pas1exe
         pas2exe = "nice -n 19 " + pas2exe
-        print pas1exe
-        txt=txt+commands.getoutput(pas1exe.encode('utf-8'))
-        print pas2exe
+        recdblist.printutf8(pas1exe)
+        txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
+        recdblist.printutf8(pas2exe)
         time.sleep(5)
-        txt=txt+commands.getoutput(pas2exe.encode('utf-8'))
+        txt=txt+unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
     else:
-        pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -ofps 30000/1001 -x264encopts " + bitrate + ":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'" + pout + "\'"
+        pas1exe = "mencoder \'" + pin + "\' -noskip -noodml -nosound -quiet -sws 9 -ovc x264 " + encvf + " "+ofps+" -x264encopts " + bitrate +x264enc2+":threads=auto -o \'" + pout + "\'"
         pas1exe = "nice -n 19 " + pas1exe
-        print pas1exe
-        txt=txt+commands.getoutput(pas1exe.encode('utf-8'))
+        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")
@@ -87,5 +106,5 @@ def encode(pin,pout,size,isAnime,is2pass):
         s=s+len("\n")
         stxt=stxt[s:]
     txt="\n####mencoder-log_"+size+"####\n"+stxt
-    f.write(txt)
+    f.write(txt.encode('utf-8'))
     f.close()
\ No newline at end of file