3 # Rec10 TS Recording Tools
\r
4 # Copyright (C) 2009-2010 Yukikaze
\r
18 def ts2mp4(pin, pout, opt):
\r
19 dir=os.path.split(pout)[0]
\r
20 title=os.path.split(pout)[1]
\r
21 title=os.path.splitext(title)[0]
\r
22 """tpavi=os.path.join(dir, title+".avi")
\r
23 tv2avi.ts2avi(pin, tpavi, opt)
\r
25 if not os.path.exists(tpavi):
\r
26 if os.path.exists(pin):
\r
28 avi2mp4(tpavi,pout,opt)"""
\r
29 tpraw=os.path.join(dir, title+".264")
\r
30 tpmp4=os.path.join(dir, title+".mp4")
\r
31 tv2avi.ts2raw(pin, tpraw, opt)
\r
33 raw2mp4(tpraw, tpmp4, opt)
\r
34 def raw2mp4(pin,pout,opt):
\r
35 dir=os.path.split(pout)[0]
\r
36 title=os.path.split(pout)[1]
\r
37 title=os.path.splitext(title)[0]
\r
38 duration="-fps 29.970030 "
\r
41 if re.search("a",opt):
\r
42 duration="-fps 23.976023 "
\r
43 elif re.search("v",opt):
\r
44 duration="-fps 23.976023 "
\r
45 if re.search("d",opt):
\r
47 duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置
\r
48 elif re.search("5",opt):
\r
50 duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置
\r
51 exe = configreader.getpath("mp4box")
\r
53 os.environ['LANG']="ja_JP.UTF-8"
\r
55 wineexe=configreader.getpath("wine")
\r
56 pincap=pin.replace(".264",".srt")
\r
57 cap2ass=configreader.getpath("Caption2Ass")
\r
58 pints=pin.replace(".264",".ts")
\r
59 paac1=pin.replace(".264","_1.aac")
\r
60 paac2=pin.replace(".264","_2.aac")
\r
61 recdblist.printutf8(paac1)
\r
62 if not os.path.exists(paac1):
\r
63 paac1=pin.replace(".264","_1.mp3")
\r
64 if not os.path.exists(paac2):
\r
65 paac2=pin.replace(".264","_2.mp3")
\r
66 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
\r
67 e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""
\r
68 e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\""
\r
69 e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\""
\r
70 e1s=exe +u" -add \""+pincap+"\" \""+pout+"\""
\r
71 if os.path.isfile(cap2ass):
\r
72 txt=txt+execcomd(e0)
\r
73 execmp4box(pin, pout, e1)
\r
74 addmp4(paac1, pout, e1a1)
\r
75 addmp4(paac2, pout, e1a2)
\r
76 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
\r
77 addmp4(pincap, pout, e1s)
\r
78 elif ispentaaudio==1:
\r
79 wineexe=configreader.getpath("wine")
\r
80 pincap=pin.replace(".264",".srt")
\r
81 cap2ass=configreader.getpath("Caption2Ass")
\r
82 pints=pin.replace(".264",".ts")
\r
83 paac1=pin.replace(".264","_1.aac")
\r
84 paac2=pin.replace(".264","_2.aac")
\r
85 recdblist.printutf8(paac1)
\r
86 if not os.path.exists(paac1):
\r
87 paac1=pin.replace(".264","_1.mp3")
\r
88 if not os.path.exists(paac2):
\r
89 paac2=pin.replace(".264","_2.mp3")
\r
90 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
\r
91 e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""
\r
92 e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\""
\r
93 e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\""
\r
94 e1s=exe +u" -add \""+pincap+"\" \""+pout+"\""
\r
95 if os.path.isfile(cap2ass):
\r
96 txt=txt+execcomd(e0)
\r
97 execmp4box(pin, pout, e1)
\r
98 addmp4(paac1, pout, e1a1)
\r
99 addmp4(paac2, pout, e1a2)
\r
100 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
\r
101 addmp4(pincap, pout, e1s)
\r
103 wineexe=configreader.getpath("wine")
\r
104 pincap=pin.replace(".264",".srt")
\r
105 cap2ass=configreader.getpath("Caption2Ass")
\r
106 pints=pin.replace(".264",".ts")
\r
107 pinaac=pin.replace(".264",".aac")
\r
108 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
\r
109 e1="ffmpeg -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\""
\r
110 e2=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""
\r
111 e2a=exe +u" -add \""+pinaac+"\" \""+pout+"\""
\r
112 e2s=exe +u" -add \""+pincap+"\" \""+pout+"\""
\r
113 if os.path.isfile(cap2ass):
\r
114 txt=txt+execcomd(e0)
\r
115 txt=txt+execcomd(e1)
\r
116 execmp4box(pin, pout, e2)
\r
117 addmp4(pinaac, pout, e2a)
\r
118 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
\r
119 addmp4(pincap, pout, e2s)
\r
120 recdblist.addlog(pout, txt, "mp4box-log")
\r
121 if status.getSettings_auto_del_tmp()==1:
\r
122 if os.path.exists(pout):
\r
123 if os.path.getsize(pout)>100*1000*1000:
\r
124 deltitle(dir,title)
\r
125 def avi2mp4(pin,pout,opt):
\r
127 if re.search(u"v", opt):
\r
129 exe = configreader.getpath(u"MP4Box")
\r
130 dir=os.path.split(pin)[0]
\r
131 title=os.path.split(pin)[1]
\r
132 title=os.path.splitext(title)[0]
\r
133 etitle=base64.b16encode(title.encode('utf-8'))
\r
134 audiopath=os.path.join(dir,etitle+u"_audio.raw")
\r
135 videopath=os.path.join(dir,etitle+u"_video.264")
\r
137 os.environ['LANG']="ja_JP.UTF-8"
\r
140 wineexe=configreader.getpath("wine")
\r
141 cfr2tc=configreader.getpath("cfr2tc")
\r
142 dtsedit=configreader.getpath("DtsEdit")
\r
143 caption2ass=configreader.getpath("Caption2Ass")
\r
144 pin120=os.path.join(dir,etitle+u".120.avi")
\r
145 pints=os.path.join(dir,title+u".ts")
\r
146 pmp4=os.path.join(dir,etitle+u".tmp.mp4")
\r
147 pintimecode=os.path.join(dir,etitle+u".timecode.txt")
\r
148 pinaac=os.path.join(dir,etitle+u".aac")
\r
149 pincat=os.path.join(dir,etitle+u".srt")
\r
150 evfr0="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"
\r
151 evfr1=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2"
\r
152 evfr2=exe+u" -aviraw video \'"+pin120+u"\'"
\r
153 videotpath=os.path.join(dir,etitle+u".120_video.h264")
\r
154 evfr3=exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
\r
155 evfr4=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
\r
157 recdblist.printutf8(evfr0)
\r
159 txt=txt+unicode(commands.getoutput(evfr0.encode('utf-8')),'utf-8')
\r
163 recdblist.printutf8(evfr1)
\r
165 txt=txt+unicode(commands.getoutput(evfr1.encode('utf-8')),'utf-8')
\r
169 if not os.path.exists(pin120):
\r
170 evfr2=exe+u" -aviraw video \'"+pin+u"\'"
\r
171 videotpath=os.path.join(dir,etitle+u"_video.h264")
\r
172 evfr3=exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
\r
173 recdblist.printutf8(evfr2)
\r
175 txt=txt+unicode(commands.getoutput(evfr2.encode('utf-8')),'utf-8')
\r
179 recdblist.printutf8(evfr3)
\r
181 txt=txt+unicode(commands.getoutput(evfr3.encode('utf-8')),'utf-8')
\r
185 recdblist.printutf8(evfr4)
\r
187 txt=txt+unicode(commands.getoutput(evfr4.encode('utf-8')),'utf-8')
\r
190 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
\r
191 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happened.)"
\r
192 ptmp=pin.replace(".avi",".noodml.avi")
\r
193 e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
\r
195 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
\r
196 ex2="nice -n 17 "+e2
\r
197 e3=exe+u" -aviraw video \'"+pin120+u"\'"
\r
198 ex3="nice -n 17 "+e3
\r
199 e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
\r
200 ex4="nice -n 17 "+e4
\r
201 e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
\r
202 ex5="nice -n 17 "+e5
\r
203 recdblist.printutf8(e)
\r
206 cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
\r
210 cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
\r
214 if os.path.exists(pin120):
\r
215 cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
\r
219 cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
\r
223 cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
\r
233 shutil.move(pin,os.path.join(dir,etitle+".avi"))
\r
236 if os.path.exists(os.path.join(dir,etitle+".avi")):
\r
237 e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"
\r
238 e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"
\r
241 if not os.path.exists(audiopath):
\r
242 if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):
\r
243 audiopath=os.path.join(dir,etitle+u"_audio.mp3")
\r
244 elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):
\r
245 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
247 shutil.move(audiopath,os.path.join(dir,etitle+u"_audio.aac"))
\r
248 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
249 ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))
\r
250 e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"
\r
252 shutil.move(ptmp,pout)
\r
253 recdblist.addlog(pin,txt,"MP4Box-log")
\r
256 delpath.append(pin.replace(u".avi",u".120.avi"))
\r
257 delpath.append(pin.replace(u".avi",u".sa.avi"))
\r
258 delpath.append(pin.replace(u".avi",u".m2v"))
\r
259 delpath.append(pin.replace(u".avi",u"_1.aac"))
\r
260 delpath.append(pin.replace(u".avi",u"_2.aac"))
\r
261 delpath.append(pin.replace(u".avi",u"_1.mp3"))
\r
262 delpath.append(pin.replace(u".avi",u"_2.mp3"))
\r
263 delpath.append(pin.replace(u".avi",u".ts"))
\r
264 delpath.append(pin.replace(u".avi",u".aac"))
\r
265 delpath.append(pin.replace(u".avi",u".m2v"))
\r
266 delpath.append(pin.replace(u".avi",u".120_video.264"))
\r
267 delpath.append(pin.replace(u".avi",u".ts.b25"))
\r
268 if os.path.exists(pout):
\r
269 if os.path.exists(audiopath):
\r
270 os.remove(audiopath)
\r
271 if os.path.exists(videopath):
\r
272 os.remove(videopath)
\r
280 def mkv2mp4(pin,pout):
\r
281 exeb = configreader.getpath(u"mkvextract")
\r
282 exe = configreader.getpath(u"MP4Box")
\r
283 dtsedit=configreader.getpath("DtsEdit")
\r
284 wineexe=configreader.getpath("wine")
\r
285 dir=os.path.split(pin)[0]
\r
286 title=os.path.split(pin)[1]
\r
287 title=os.path.splitext(title)[0]
\r
288 etitle=base64.b16encode(title.encode('utf-8'))
\r
289 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
290 videopath=os.path.join(dir,etitle+u"_video.264")
\r
291 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
\r
292 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
\r
293 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
\r
294 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
\r
295 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
\r
296 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
\r
297 os.environ['LANG']="ja_JP.UTF-8"
\r
300 txt=txt+execcomd(exe0)+"\n"
\r
301 txt=txt+execcomd(exe1)+"\n"
\r
302 txt=txt+execcomd(exe2)+"\n"
\r
303 txt=txt+execcomd(exe3)+"\n"
\r
306 recdblist.addlog(pin, txt, "MKV2MP4-log")
\r
307 txt = "\n####MKV2MP4-log####\n"+txt
\r
309 if os.path.exists(pout):
\r
310 if os.path.exists(audiopath):
\r
311 os.remove(audiopath)
\r
312 if os.path.exists(videopath):
\r
313 os.remove(videopath)
\r
314 if os.path.exists(timecodepath):
\r
315 os.remove(timecodepath)
\r
316 if os.path.exists(tmpmp4):
\r
318 def execmp4box(pin,pout,cmd):
\r
319 title=os.path.splitext(os.path.split(pin)[1])[0]
\r
320 ptin=os.path.join(os.path.dirname(pin),base64.b16encode(title.encode('utf-8'))+".264")
\r
321 recdblist.printutf8(ptin)
\r
322 shutil.move(pin,ptin)
\r
324 ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")
\r
325 cmdn=string.replace(cmd,pin,ptin)
\r
326 cmdn=string.replace(cmdn,pout,ptout)
\r
327 recdblist.printutf8(cmdn)
\r
331 except Exception, inst:
\r
332 txt= "error occures in execmp4box\n"
\r
333 txt=txt+ str(type(inst))+"\n"
\r
335 recdblist.addlog(pin, txt, "MP4Box-log")
\r
337 shutil.move(ptin,pin)
\r
338 shutil.move(ptout,pout)
\r
340 def addmp4(padd,pout,cmd):#without video
\r
341 title=os.path.splitext(os.path.split(padd)[1])[0]
\r
342 ext=os.path.splitext(os.path.split(padd)[1])[1]
\r
343 ptadd=os.path.join(os.path.dirname(padd),base64.b16encode(title.encode('utf-8'))+ext)
\r
344 ptoutb=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+"_b.mp4")
\r
345 ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")
\r
346 shutil.move(padd,ptadd)
\r
347 if os.path.isfile(pout):
\r
348 shutil.move(pout,ptoutb)
\r
350 cmdn=string.replace(cmd,padd,ptadd)
\r
351 cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)
\r
352 cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)
\r
353 cmdn=string.replace(cmdn,pout,ptout)
\r
354 recdblist.printutf8(cmdn)
\r
358 except Exception, inst:
\r
359 txt= "error occures in addmp4\n"
\r
360 txt=txt+ str(type(inst))+"\n"
\r
362 recdblist.addlog(pout, txt, "MP4Box-log-add")
\r
365 shutil.move(ptadd,padd)
\r
366 shutil.move(ptout,pout)
\r
371 txt=u"Cmd : "+cmd+"\n"
\r
372 txt2=commands.getoutput(cmd.encode('utf-8'))
\r
373 txt=txt+unicode(txt2,"utf-8")+"\n"
\r