OSDN Git Service

ready to enable multi-pc encoding 2
[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 status
6 import os
7 import time
8 import re
9
10 def ts2x264(pin,pout,opts):#sizeは"HD"か"SD"
11     pout = pout.encode('utf-8')
12     pin = pin.encode('utf-8')
13     """
14     pinで指定されたファイルをpoutにx264でエンコードして書き出す
15     """
16     
17     status.setEncoding(status.getEncoding()+1)
18     isAnime=0
19     size="SD"
20
21     makemini=0
22     if re.search("a",opts):
23         isAnime=1
24         #print "isAnime"
25     dualpass=0
26     if re.search("2",opts):
27         dualpass=1
28     if re.search("Q",opts):
29         size="WQVGA"
30     if re.search("F",opts):
31         size="FHD"
32     if re.search("H",opts):
33         size="HD"
34     if re.search("S",opts):
35         size="SD"
36     if isAnime==1:
37         encvf="-vf pullup,softskip,pp=l5,"
38     else:
39         encvf="-vf pp=l5,"
40     if size=="SD":
41         encvf=encvf+"scale=720:480,harddup"
42         bitrate="bitrate=1250"
43     elif size=="HD":
44         encvf=encvf+"scale=1280:720,harddup"
45         bitrate="bitrate=2000"
46     elif size=="FHD":
47         encvf=encvf+"scale=1920:1080,harddup"
48         bitrate="bitrate=2500"
49     elif size=="WQVGA":
50         encvf=encvf+"scale=400:240,harddup"
51         bitrate="bitrate=200"
52     else:
53         encvf=encvf+"scale=1280:720,harddup"
54         bitrate="bitrate=2000"
55
56     if dualpass==1:
57         pas1exe="mencoder \'"+pin+"\' -ovc x264 "+encvf+" -x264encopts "+bitrate+":threads=auto:pass=1:turbo=2 -passlogfile "+pin+".log "+"-oac mp3lame -lameopts cbr:br=128 -o /dev/null"
58         pas2exe="mencoder \'"+pin+"\' -ovc x264 "+encvf+" -x264encopts "+bitrate+":threads=auto:pass=2 -passlogfile "+pin+".log "+"-oac mp3lame -lameopts cbr:br=128 -o \'"+pout+"\'"
59         pas1exe="/usr/bin/nice -n 19 "+pas1exe
60         pas2exe="/usr/bin/nice -n 19 "+pas2exe
61         print pas2exe
62         os.system(pas1exe)
63         print "1pass終了"
64         time.sleep(5)
65         os.system(pas2exe)
66     else:
67         pas1exe="mencoder \'"+pin+"\' -ovc x264 "+encvf+" -x264encopts "+bitrate+":threads=auto -oac mp3lame -lameopts cbr:br=128  -o \'"+pout+"\'"
68         os.system(pas1exe)
69     status.setEncoding(status.getEncoding()-1)