OSDN Git Service

fix installer(epgdump bug is still there)
[rec10/rec10-git.git] / rec10 / trunk / src / ts2x264.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import commands
6 import os
7 import re
8 import time
9 import tv2avi
10 import recdblist
11 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
12     """
13     pinで指定されたファイルをpoutにx264でエンコードして書き出す
14     """
15     isAnime = 0
16     if re.search("a", opts):
17         isAnime = 1
18     dualpass = 0
19     resize=0
20     isvfr=0
21     size="Tall"
22     if re.search("2", opts):
23         dualpass = 1
24     if re.search("H", opts):
25         size = "HD"
26     if re.search("S", opts):
27         size = "SD"
28     if re.search("F", opts):
29         size = "FHD"
30     if re.search("L", opts):
31         size = "Short"
32     if re.search("G", opts):
33         size = "LowHD"
34     if re.search("v", opts):
35         isvfr=1
36     encode(pin, pout,size,isvfr,dualpass)
37 def encode(pin,pout,size,isvfr,is2pass):
38     encvf=""
39     txt=""
40     encvf="-vf yadif=0"
41     harddup=",harddup"
42     ofps="-ofps 30000/1001"
43     bm=1
44     scale=""
45     x264enc1=""
46     x264enc2=""
47     if isvfr==1:
48         ofps="-ofps 120000/1001"
49         encvf="-vf pullup,softskip,yadif=0"
50         bm=4
51         x264enc1=":frameref=3:me=hex"
52         x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:me=umh:bframes=3:b_pyramid:weight_b"
53         harddup=""
54     if size == "HD":
55         encvf = encvf + ",scale=1280:720"+harddup
56         bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
57     elif size == "SD":
58         encvf = encvf + ",scale=720:480"+harddup
59         bitrate = "bitrate=" + str(tv2avi.Bitrate_SD*bm)
60     elif size == "FHD":
61         encvf = encvf + ",scale=1920:1080"+harddup
62         bitrate = "bitrate=" + str(tv2avi.Bitrate_FHD*bm)
63     elif size == "Short":
64         encvf = encvf +harddup
65         bitrate = "bitrate=" + str(tv2avi.Bitrate_Short*bm)
66     elif size == "LowHD":
67         encvf = encvf + ",scale=1280:720"+harddup
68         bitrate = "bitrate=" + str(tv2avi.Bitrate_LowHD*bm)
69     else:
70         encvf = encvf + ",scale=1280:720"+harddup
71         bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
72     if is2pass == 1:
73         pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " "+ofps+" -x264encopts " + bitrate +x264enc1+ ":threads=auto:pass=1:turbo=2 -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o /dev/null"
74         pas2exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " "+ofps+" -x264encopts " + bitrate +x264enc2+ ":threads=auto:pass=2 -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o \'" + pout + "\'"
75         pas1exe = "nice -n 19 " + pas1exe
76         pas2exe = "nice -n 19 " + pas2exe
77         recdblist.printutf8(pas1exe)
78         txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
79         recdblist.printutf8(pas2exe)
80         time.sleep(5)
81         txt=txt+unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
82     else:
83         pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " "+ofps+" -x264encopts " + bitrate +x264enc2+":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'" + pout + "\'"
84         pas1exe = "nice -n 19 " + pas1exe
85         recdblist.printutf8(pas1exe)
86         txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
87     logo=pin
88     logo=logo.replace(".sa.avi",".ts")
89     logo=logo.replace(".ts",".log")
90     f=open(logo,'a')
91     s=len(txt)
92     stxt=""
93     if s>100:
94         stxt=txt[s-300:]
95     else:
96         stxt=txt
97     s=stxt.find("\n")
98     if s>0:
99         s=s+len("\n")
100         stxt=stxt[s:]
101     txt="\n####mencoder-log_"+size+"####\n"+stxt
102     f.write(txt.encode('utf-8'))
103     f.close()