OSDN Git Service

sys.setdefaultencoding('UTF-8') required version.
[rec10/rec10-git.git] / rec10 / branches / 0.9.0 / src / ts2xvid.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import commands
6 import re
7 import time
8
9 import tv2avi
10 def ts2xvid(pin, pout, opts):#sizeは"HD"か"SD"
11     """
12     pinで指定されたファイルをpoutにx264でエンコードして書き出す
13     """
14     pout = pout.encode('utf-8')
15     pin = pin.encode('utf-8')
16     isAnime = 0
17     size = "SD"
18     if re.search("a", opts):
19         isAnime = 1
20         #print "isAnime"
21     dualpass = 0
22     if re.search("2", opts):
23         dualpass = 1
24     if re.search("Q", opts):
25         size = "WQVGA"
26     if re.search("F", opts):
27         size = "FHD"
28     if re.search("T", opts):
29         size = "THD"
30     if re.search("H", opts):
31         size = "HD"
32     if re.search("S", opts):
33         size = "SD"
34     if isAnime == 1:
35         encvf = "-vf pullup,softskip,pp=l5,"
36     else:
37         encvf = "-vf pp=l5,"
38     if size == "SD":
39         encvf = encvf + "scale=720:480,harddup"
40         bitrate = "bitrate=" + tv2avi.Bitrate_SD
41     elif size == "HD":
42         encvf = encvf + "scale=1280:720,harddup"
43         bitrate = "bitrate=" + tv2avi.Bitrate_HD
44     elif size == "FHD":
45         encvf = encvf + "scale=1920:1080,harddup"
46         bitrate = "bitrate=" + tv2avi.Bitrate_FHD
47     elif size == "THD":
48         encvf = encvf + "scale=1440:1080,harddup"
49         bitrate = "bitrate=" + tv2avi.Bitrate_THD
50     elif size == "WQVGA":
51         encvf = encvf + "scale=400:240,harddup"
52         bitrate = "bitrate=" + tv2avi.Bitrate_WQVGA
53     else:
54         encvf = encvf + "scale=1280:720,harddup"
55         bitrate = "bitrate=" + tv2avi.Bitrate_HD
56     if dualpass == 1:
57         pas1exe = "mencoder \'" + pin + "\' -ovc xvid " + encvf + " -xvidencopts " + bitrate + ":threads=2:pass=1:turbo -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o /dev/null"
58         pas2exe = "mencoder \'" + pin + "\' -ovc xvid " + encvf + " -xvidencopts " + bitrate + ":threads=2:pass=2 -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o \'" + pout + "\'"
59         pas1exe = "nice -n 19 " + pas1exe
60         pas2exe = "nice -n 19 " + pas2exe
61         print pas1exe
62         commands.getoutput(pas1exe)
63         #os.system(pas1exe)
64         print pas2exe
65         time.sleep(5)
66         commands.getoutput(pas2exe)
67         #os.system(pas2exe)
68     else:
69         pas1exe = "mencoder \'" + pin + "\' -ovc xvid " + encvf + " -xvidencopts " + bitrate + ":threads=2 -oac mp3lame -lameopts cbr:br=128  -o \'" + pout + "\'"
70         pas1exe = "nice -n 19 " + pas1exe
71         print pas1exe
72         commands.getoutput(pas1exe)
73         #os.system(pas1exe)
74         
75