OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / branches / 0.5 / src / tv2avi.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import shutil
6 import time
7 import chdb
8 import configreader
9 import datetime
10 import os
11 import re
12 import ts2x264
13 import ts2xvid
14 import tv2ts
15 import recdb
16
17 global Bitrate_HD
18 global Bitrate_FHD
19 global Bitrate_SD
20 global Bitrate_WQVGA
21 Bitrate_HD="2000"
22 Bitrate_FHD="2500"
23 Bitrate_SD="1250"
24 Bitrate_WQVGA="200"
25
26 def timetv2avi(pout, chtxt, btime, etime,opt):
27     bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
28     et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
29     extt = os.path.splitext(pout)
30     tsout = extt[0]
31     #tsout=pout####
32     #print "4"+tsout
33     tnow = datetime.datetime.now()
34     wt = bt-tnow
35     waitt = wt.seconds-5
36     time.sleep(waitt)
37     tnow = datetime.datetime.now()
38     dt = et-tnow
39     rectime = dt.seconds-10
40     rectime = str(rectime)
41     #print tsout+".ts,"+chdb.chtxtsearch(chtxt)['ch']+","+chdb.chtxtsearch(chtxt)['csch']+","+rectime
42     tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], rectime)
43     aviin = tsout + ".ts"
44     dualaudio = 0
45     pentaaudio = 0
46     if re.search("5",opt):
47         pentaaudio = 1
48     if re.search("d",opt):
49         dualaudio = 1
50     if re.search("\[二\]", pout):
51         dualaudio = 1
52     elif re.search('(二)', pout):
53         dualaudio = 1
54     elif re.search('\(二\)', pout):
55         dualaudio = 1
56     if opt=="":
57         opts=""
58         if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
59             opts=opts+"S2"
60             if chtxt == "disch":
61                 ""
62             elif chtxt == "hisch":
63                 ""
64             else:
65                 opts=opts+"a"
66         else:
67             opts=opts+"Ha2"
68     else:
69         opts=opt
70     if re.search("x",opt):
71         makexvid = 0
72     else:
73         makexvid = 1
74     if dualaudio == 1:
75         dualaudiots2avi(aviin, tsout + "sa.avi")
76         aviin = tsout + "sa.avi"
77     if pentaaudio ==1:
78         dualaudiots2avi(aviin, tsout + "sa.avi")
79         aviin = tsout + "sa.avi"
80     bt=datetime.datetime.now()+datetime.timedelta(seconds=600)
81     btime=bt.strftime("%Y-%m-%d %H:%M:%S")
82     et=datetime.datetime.now()+datetime.timedelta(seconds=600)
83     etime=et.strftime("%Y-%m-%d %H:%M:%S")
84     title=os.path.split(tsout)[1]
85     #try:
86     #    os.remove(aviin)
87     #except:
88     #    ""
89 def tv2avi(pout, chtxt, btime, etime,opt):
90     bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
91     et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
92     dt = et-bt
93     time = dt.seconds-10
94     time = str(time)
95     extt = os.path.splitext(pout)
96     tsout = extt[0]
97     tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], time)
98     aviin = tsout + ".ts"
99     dualaudio = 0
100     pentaaudio = 0 
101     if re.search("5",opt):
102         pentaaudio = 1
103     if re.search("d",opt):
104         dualaudio = 1
105     if re.search('\[二\]', pout):
106         dualaudio = 1
107     elif re.search('(二)', pout):
108         dualaudio = 1
109     elif re.search('\(二\)', pout):
110         dualaudio = 1
111     opts=""
112     if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
113         opts=opts+"S2"
114         if chtxt == "disch":
115             ""
116         elif chtxt == "hisch":
117             ""
118         else:
119             opts=opts+"a"
120     else:
121         opts=opts+"Ha2"
122     if dualaudio == 1:
123         dualaudiots2avi(aviin, tsout + "sa.avi")
124         aviin = tsout + "sa.avi"
125     if pentaaudio ==1:
126         dualaudiots2avi(aviin, tsout + "sa.avi")
127         aviin = tsout + "sa.avi"
128     ts2x264.ts2x264(aviin, pout,opts)
129     #os.remove(aviin)
130 def b252avi(pout, chtxt,opt):
131     extt = os.path.splitext(pout)
132     tsout = extt[0]
133     tv2ts.b252ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'])
134     aviin = tsout + ".ts"
135     dualaudio = 0
136     pentaaudio = 0
137     if re.search("5",opt):
138         pentaaudio = 1
139     if re.search("d",opt):
140         dualaudio = 1
141     if re.search('\[二\]', pout):
142         dualaudio = 1
143     elif re.search('(二)', pout):
144         dualaudio = 1
145     elif re.search('\(二\)', pout):
146         dualaudio = 1
147     if opt=="":
148         opts=""
149         if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
150             opts=opts+"S2"
151             if chtxt == "disch":
152                 ""
153             elif chtxt == "hisch":
154                 ""
155             else:
156                 opts=opts+"a"
157         else:
158             opts=opts+"Ha2"
159     else:
160         opts=opt
161     if re.search("x",opt):
162         makexvid = 0
163     else:
164         makexvid = 1
165     if dualaudio == 1:
166         dualaudiots2avi(aviin, tsout + "sa.avi")
167         aviin = tsout + "sa.avi"
168     if pentaaudio ==1:
169         dualaudiots2avi(aviin, tsout + "sa.avi")
170         aviin = tsout + "sa.avi"
171     if makexvid==1:
172         ts2xvid.ts2xvid(aviin, pout,opts)
173     else:
174         ts2x264.ts2x264(aviin, pout,opts)
175     #try:
176     #    os.remove(aviin)
177     #except:
178     #    ""
179
180 def dualaudiots2avi(pin, pout):
181     bontsdemux = configreader.getpath('bontsdemux')
182     wine = configreader.getpath('wine')
183     bonpin = "Z:\\" + pin[1:]
184     outf = os.path.splitext(pin)[0]
185     bonpout = "Z:\\" + outf[1:]
186     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit"
187     #print exe
188     exe = 'xvfb-run -a ' + exe
189     #exe='export Display=:2&&'+exe
190     print exe
191     os.system(exe)
192     ffpin1 = pin.replace("ts", "wav")
193     ffpin2 = pin.replace("ts", "m2v")
194     exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
195     #print exe
196     os.system(exe)
197     os.remove(ffpin1)
198     os.remove(ffpin2)
199 def dualaudio2sep(pin,pout,delay):
200     bontsdemux = configreader.getpath('bontsdemux')
201     wine = configreader.getpath('wine')
202     bonpin = "Z:\\" + pin[1:]
203     outf = os.path.splitext(pin)[0]
204     bonpout = "Z:\\" + outf[1:]
205     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 1 -o \"" + bonpout + "\" -start -quit"
206     #print exe
207     exe = 'xvfb-run -a ' + exe
208     #exe='export Display=:2&&'+exe
209     print exe
210     os.system(exe)
211     ffpin=pin.replace(".ts","")
212     ffpin1 = pin.replace("ts", "wav")
213     ffpin2 = pin.replace("ts", "m2v")
214     ffpout1=ffpin+"1_delay"+delay+".wav"
215     ffpout2=ffpin+"2_delay"+delay+".wav"
216     shutil.move(ffpin1, ffpout1)
217     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\" -start -quit"
218     exe = 'xvfb-run -a ' + exe
219     os.system(exe)
220     shutil.move(ffpin1, ffpout2)
221     ffpout21=ffpout1.replace(".wav",".ogg")
222     ffpout22=ffpout2.replace(".wav",".ogg")
223     aexe1="ffmpeg -i "+ffpout1+" -vn -acodec vorbis -ar 48000 -ab 128k "+ffpout21
224     aexe2="ffmpeg -i "+ffpout2+" -vn -acodec vorbis -ar 48000 -ab 128k "+ffpout22
225     os.system(aexe1)
226     os.system(aexe2)
227
228     #exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
229     #print exe
230     
231     #os.remove(ffpin1)
232     #os.remove(ffpin2)
233
234 def pentaaudiots2avi(pin, pout):
235     bontsdemux = configreader.getpath('bontsdemux')
236     wine = configreader.getpath('wine')
237     bonpin = "Z:\\" + pin[1:]
238     outf = os.path.splitext(pin)[0]
239     bonpout = "Z:\\" + outf[1:]
240     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 3 -o \"" + bonpout + "\" -start -quit"
241     #print exe
242     exe = 'xvfb-run -a ' + exe
243     #exe='export Display=:2&&'+exe
244     print exe
245     os.system(exe)
246     ffpin1 = pin.replace("ts", "wav")
247     ffpin2 = pin.replace("ts", "m2v")
248     exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
249     #print exe
250     os.system(exe)
251     os.remove(ffpin1)
252     os.remove(ffpin2)
253