OSDN Git Service

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