OSDN Git Service

fix many bug.
[rec10/rec10-git.git] / rec10 / trunk / src / ts2x264.py
index 5908d27..5356fc2 100644 (file)
 # coding: UTF-8
 # Rec10 TS Recording Tools
 # Copyright (C) 2009 Yukikaze
-import tv2avi
-import status
+import commands
 import os
-import time
 import re
-
-def ts2x264(pin,pout,opts):#sizeは"HD"か"SD"
-    pout = pout.encode('utf-8')
-    pin = pin.encode('utf-8')
+import time
+import tv2avi
+import recdblist
+def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
     """
     pinで指定されたファイルをpoutにx264でエンコードして書き出す
     """
-    
-    status.setEncoding(status.getEncoding()+1)
-    isAnime=0
-    size="SD"
-
-    makemini=0
-    if re.search("a",opts):
-        isAnime=1
-        #print "isAnime"
-    dualpass=0
-    if re.search("2",opts):
-        dualpass=1
-    if re.search("Q",opts):
-        size="WQVGA"
-    if re.search("F",opts):
-        size="FHD"
-    if re.search("H",opts):
-        size="HD"
-    if re.search("S",opts):
-        size="SD"
-    if isAnime==1:
-        encvf="-vf pullup,softskip,pp=l5,"
-    else:
-        encvf="-vf pp=l5,"
-    if size=="SD":
-        encvf=encvf+"scale=720:480,harddup"
-        bitrate="bitrate="+tv2avi.Bitrate_SD
-    elif size=="HD":
-        encvf=encvf+"scale=1280:720,harddup"
-        bitrate="bitrate="+tv2avi.Bitrate_HD
-    elif size=="FHD":
-        encvf=encvf+"scale=1920:1080,harddup"
-        bitrate="bitrate="+tv2avi.Bitrate_FHD
-    elif size=="WQVGA":
-        encvf=encvf+"scale=400:240,harddup"
-        bitrate="bitrate="+tv2avi.Bitrate_WQVGA
+    isAnime = 0
+    if re.search("a", opts):
+        isAnime = 1
+    dualpass = 0
+    resize=0
+    isvfr=0
+    size="Tall"
+    if re.search("2", opts):
+        dualpass = 1
+    if re.search("H", opts):
+        size = "HD"
+    if re.search("S", opts):
+        size = "SD"
+    if re.search("F", opts):
+        size = "FHD"
+    if re.search("L", opts):
+        size = "Short"
+    if re.search("G", opts):
+        size = "LowHD"
+    if re.search("v", opts):
+        isvfr=1
+    encode(pin, pout,size,isvfr,dualpass)
+def encode(pin,pout,size,isvfr,is2pass):
+    encvf=""
+    txt=""
+    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::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
+        crf="crf=20"
+    elif size == "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::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_FHD*bm)
+        crf="crf=22"
+    elif size == "Short":
+        encvf = encvf +harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_Short*bm)
+        crf="crf=20"
+    elif size == "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
-
-    if dualpass==1:
-        pas1exe="mencoder \'"+pin+"\' -ovc x264 "+encvf+" -x264encopts "+bitrate+":threads=auto:pass=1:turbo=2 -passlogfile "+pin+".log "+"-oac mp3lame -lameopts cbr:br=128 -o /dev/null"
-        pas2exe="mencoder \'"+pin+"\' -ovc x264 "+encvf+" -x264encopts "+bitrate+":threads=auto:pass=2 -passlogfile "+pin+".log "+"-oac mp3lame -lameopts cbr:br=128 -o \'"+pout+"\'"
-        pas1exe="/usr/bin/nice -n 19 "+pas1exe
-        pas2exe="/usr/bin/nice -n 19 "+pas2exe
-        print pas2exe
-        os.system(pas1exe)
-        print "1pass終了"
+        encvf = encvf + ",scale=1280:720::0:4"+harddup
+        bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
+        crf="crf=22"
+    if is2pass == 1:
+        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
+        recdblist.printutf8(pas1exe)
+        txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
+        recdblist.printutf8(pas2exe)
         time.sleep(5)
-        os.system(pas2exe)
+        txt=txt+unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
+    else:
+        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
+        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:
-        pas1exe="mencoder \'"+pin+"\' -ovc x264 "+encvf+" -x264encopts "+bitrate+":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'"+pout+"\'"
-        os.system(pas1exe)
-    status.setEncoding(status.getEncoding()-1)
\ No newline at end of file
+        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()
\ No newline at end of file