OSDN Git Service

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