OSDN Git Service

fix oikake bug.
[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     size="Tall"
21     if re.search("2", opts):
22         dualpass = 1
23     if re.search("H", opts):
24         size = "HD"
25     if re.search("S", opts):
26         size = "SD"
27     if re.search("F", opts):
28         size = "FHD"
29     if re.search("L", opts):
30         size = "Short"
31     if re.search("G", opts):
32         size = "LowHD"
33     encode(pin, pout,size,isAnime,dualpass)
34 def encode(pin,pout,size,isAnime,is2pass):
35     encvf=""
36     txt=""
37     if isAnime == 1:
38         encvf = "-vf yadif=0,"
39     else:
40         encvf = "-vf yadif=0,"
41     if size == "HD":
42         encvf = encvf + "scale=1280:720,harddup"
43         bitrate = "bitrate=" + tv2avi.Bitrate_HD
44     elif size == "SD":
45         encvf = encvf + "scale=720:480,harddup"
46         bitrate = "bitrate=" + tv2avi.Bitrate_SD
47     elif size == "FHD":
48         encvf = encvf + "scale=1920:1080,harddup"
49         bitrate = "bitrate=" + tv2avi.Bitrate_FHD
50     elif size == "Short":
51         encvf = encvf + "harddup"
52         bitrate = "bitrate=" + tv2avi.Bitrate_Short
53     elif size == "LowHD":
54         encvf = encvf + "scale=1280:720,harddup"
55         bitrate = "bitrate=" + tv2avi.Bitrate_LowHD
56     else:
57         encvf = encvf + "scale=1280:720,harddup"
58         bitrate = "bitrate=" + tv2avi.Bitrate_HD
59     if is2pass == 1:
60         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"
61         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 + "\'"
62         pas1exe = "nice -n 19 " + pas1exe
63         pas2exe = "nice -n 19 " + pas2exe
64         recdblist.printutf8(pas1exe)
65         txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
66         recdblist.printutf8(pas2exe)
67         time.sleep(5)
68         txt=txt+unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
69     else:
70         pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -ofps 30000/1001 -x264encopts " + bitrate + ":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'" + pout + "\'"
71         pas1exe = "nice -n 19 " + pas1exe
72         recdblist.printutf8(pas1exe)
73         txt=txt+unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
74     logo=pin
75     logo=logo.replace(".sa.avi",".ts")
76     logo=logo.replace(".ts",".log")
77     f=open(logo,'a')
78     s=len(txt)
79     stxt=""
80     if s>100:
81         stxt=txt[s-300:]
82     else:
83         stxt=txt
84     s=stxt.find("\n")
85     if s>0:
86         s=s+len("\n")
87         stxt=stxt[s:]
88     txt="\n####mencoder-log_"+size+"####\n"+stxt
89     f.write(txt.encode('utf-8'))
90     f.close()