OSDN Git Service

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