OSDN Git Service

improve logging.
[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
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     size = "SD"
19     txt=""
20     if re.search("a", opts):
21         isAnime = 1
22         #print "isAnime"
23     dualpass = 0
24     if re.search("2", opts):
25         dualpass = 1
26     if re.search("Q", opts):
27         size = "WQVGA"
28     if re.search("F", opts):
29         size = "FHD"
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 == "WQVGA":
48         encvf = encvf + "scale=400:240,harddup"
49         bitrate = "bitrate=" + tv2avi.Bitrate_WQVGA
50     else:
51         encvf = encvf + "scale=1280:720,harddup"
52         bitrate = "bitrate=" + tv2avi.Bitrate_HD
53     if dualpass == 1:
54         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"
55         pas2exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -x264encopts " + bitrate + ":threads=auto:pass=2 -passlogfile \'" + pin + ".log\' " + "-oac mp3lame -lameopts cbr:br=128 -o \'" + pout + "\'"
56         pas1exe = "nice -n 19 " + pas1exe
57         pas2exe = "nice -n 19 " + pas2exe
58         print pas1exe
59         txt=txt+commands.getoutput(pas1exe)
60         #os.system(pas1exe)
61         print pas2exe
62         time.sleep(5)
63         txt=txt+commands.getoutput(pas2exe)
64         #os.system(pas2exe)
65     else:
66         pas1exe = "mencoder \'" + pin + "\' -quiet -ovc x264 " + encvf + " -x264encopts " + bitrate + ":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'" + pout + "\'"
67         pas1exe = "nice -n 19 " + pas1exe
68         print pas1exe
69         txt=txt+commands.getoutput(pas1exe)
70     f=open(pin+".enc.log",'w')
71     f.write(txt)
72     f.close()
73