OSDN Git Service

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