OSDN Git Service

sys.setdefaultencoding('UTF-8') required version.
[rec10/rec10-git.git] / rec10 / branches / 0.9.0 / 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 def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
11     pout = pout.encode('utf-8')
12     pin = pin.encode('utf-8')
13     """
14     pinで指定されたファイルをpoutにx264でエンコードして書き出す
15     """
16     isAnime = 0
17     if re.search("a", opts):
18         isAnime = 1
19     dualpass = 0
20     resize=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     encode(pin, pout,size,isAnime,dualpass)
35 def encode(pin,pout,size,isAnime,is2pass):
36     encvf=""
37     txt=""
38     if isAnime == 1:
39         encvf = "-vf yadif=3,pp=l5,framestep=2,"
40     else:
41         encvf = "-vf yadif=3,pp=l5,framestep=2,"
42     if size == "HD":
43         encvf = encvf + "scale=1280:720,harddup"
44         bitrate = "bitrate=" + tv2avi.Bitrate_HD
45     elif size == "SD":
46         encvf = encvf + "scale=720:480,harddup"
47         bitrate = "bitrate=" + tv2avi.Bitrate_SD
48     elif size == "FHD":
49         encvf = encvf + "scale=1920:1080,harddup"
50         bitrate = "bitrate=" + tv2avi.Bitrate_FHD
51     elif size == "Short":
52         encvf = encvf + "harddup"
53         bitrate = "bitrate=" + tv2avi.Bitrate_Short
54     elif size == "LowHD":
55         encvf = encvf + "scale=1280:720,harddup"
56         bitrate = "bitrate=" + tv2avi.Bitrate_LowHD
57     else:
58         encvf = encvf + "scale=1280:720,harddup"
59         bitrate = "bitrate=" + tv2avi.Bitrate_HD
60     if is2pass == 1:
61         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"
62         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 + "\'"
63         pas1exe = "nice -n 19 " + pas1exe
64         pas2exe = "nice -n 19 " + pas2exe
65         print pas1exe
66         txt=txt+commands.getoutput(pas1exe)
67         print pas2exe
68         time.sleep(5)
69         txt=txt+commands.getoutput(pas2exe)
70     else:
71         pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -ofps 30000/1001 -x264encopts " + bitrate + ":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'" + pout + "\'"
72         pas1exe = "nice -n 19 " + pas1exe
73         print pas1exe
74         txt=txt+commands.getoutput(pas1exe)
75     logo=pin
76     logo=logo.replace(".sa.avi",".ts")
77     logo=logo.replace(".ts",".log")
78     f=open(logo,'a')
79     s=len(txt)
80     stxt=""
81     if s>100:
82         stxt=txt[s-300:]
83     else:
84         stxt=txt
85     s=stxt.find("\n")
86     if s>0:
87         s=s+len("\n")
88         stxt=stxt[s:]
89     txt="\n####mencoder-log_"+size+"####\n"+stxt
90     f.write(txt)
91     f.close()