3 # Rec10 TS Recording Tools
\r
4 # Copyright (C) 2009 Yukikaze
\r
16 def ts2mp4(pin, pout, opt):
\r
17 dir=os.path.split(pout)[0]
\r
18 title=os.path.split(pout)[1]
\r
19 title=os.path.splitext(title)[0]
\r
20 tpavi=os.path.join(dir, title+".avi")
\r
21 tv2avi.ts2avi(pin, tpavi, opt)
\r
23 if not os.path.exists(tpavi):
\r
24 if os.path.exists(pin):
\r
26 avi2mp4(tpavi,pout,opt)
\r
27 def avi2mp4(pin,pout,opt):
\r
29 if re.search(u"v", opt):
\r
31 exe = configreader.getpath(u"MP4Box")
\r
32 dir=os.path.split(pin)[0]
\r
33 title=os.path.split(pin)[1]
\r
34 title=os.path.splitext(title)[0]
\r
35 etitle=base64.b16encode(title.encode('utf-8'))
\r
36 audiopath=os.path.join(dir,etitle+u"_audio.raw")
\r
37 videopath=os.path.join(dir,etitle+u"_video.264")
\r
39 os.environ['LANG']="ja_JP.UTF-8"
\r
42 wineexe=configreader.getpath("wine")
\r
43 cfr2tc=configreader.getpath("cfr2tc")
\r
44 dtsedit=configreader.getpath("DtsEdit")
\r
45 caption2ass=configreader.getpath("Caption2Ass")
\r
46 pin120=os.path.join(dir,etitle+u".120.avi")
\r
47 pints=os.path.join(dir,title+u".ts")
\r
48 pmp4=os.path.join(dir,etitle+u".tmp.mp4")
\r
49 pintimecode=os.path.join(dir,etitle+u".timecode.txt")
\r
50 pinaac=os.path.join(dir,etitle+u".aac")
\r
51 pincat=os.path.join(dir,etitle+u".srt")
\r
52 evfr0="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"
\r
53 evfr1=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2"
\r
54 evfr2=exe+u" -aviraw video \'"+pin120+u"\'"
\r
55 videotpath=os.path.join(dir,etitle+u".120_video.h264")
\r
56 evfr3=exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
\r
57 evfr4=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
\r
59 recdblist.printutf8(evfr0)
\r
61 txt=txt+unicode(commands.getoutput(evfr0.encode('utf-8')),'utf-8')
\r
65 recdblist.printutf8(evfr1)
\r
67 txt=txt+unicode(commands.getoutput(evfr1.encode('utf-8')),'utf-8')
\r
71 if not os.path.exists(pin120):
\r
72 evfr2=exe+u" -aviraw video \'"+pin+u"\'"
\r
73 videotpath=os.path.join(dir,etitle+u"_video.h264")
\r
74 evfr3=exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
\r
75 recdblist.printutf8(evfr2)
\r
77 txt=txt+unicode(commands.getoutput(evfr2.encode('utf-8')),'utf-8')
\r
81 recdblist.printutf8(evfr3)
\r
83 txt=txt+unicode(commands.getoutput(evfr3.encode('utf-8')),'utf-8')
\r
87 recdblist.printutf8(evfr4)
\r
89 txt=txt+unicode(commands.getoutput(evfr4.encode('utf-8')),'utf-8')
\r
92 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
\r
93 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
\r
94 ptmp=pin.replace(".avi",".noodml.avi")
\r
95 e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
\r
97 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
\r
98 ex2="nice -n 17 "+e2
\r
99 e3=exe+u" -aviraw video \'"+pin120+u"\'"
\r
100 ex3="nice -n 17 "+e3
\r
101 e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
\r
102 ex4="nice -n 17 "+e4
\r
103 e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
\r
104 ex5="nice -n 17 "+e5
\r
105 recdblist.printutf8(e)
\r
108 cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
\r
112 cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
\r
116 if os.path.exists(pin120):
\r
117 cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
\r
121 cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
\r
125 cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
\r
135 shutil.move(pin,os.path.join(dir,etitle+".avi"))
\r
138 if os.path.exists(os.path.join(dir,etitle+".avi")):
\r
139 e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"
\r
140 e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"
\r
143 if not os.path.exists(audiopath):
\r
144 if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):
\r
145 audiopath=os.path.join(dir,etitle+u"_audio.mp3")
\r
146 elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):
\r
147 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
149 shutil.move(audiopath,os.path.join(dir,etitle+u"_audio.aac"))
\r
150 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
151 ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))
\r
152 e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"
\r
154 shutil.move(ptmp,pout)
\r
155 logo=pin.replace(u".avi",u".log")
\r
156 txt = "\n####MP4Box-log####\n"+txt
\r
158 f.write(txt.encode('utf-8'))
\r
162 delpath.append(pin.replace(u".avi",u".120.avi"))
\r
163 delpath.append(pin.replace(u".avi",u".sa.avi"))
\r
164 delpath.append(pin.replace(u".avi",u".ts"))
\r
165 delpath.append(pin.replace(u".avi",u".aac"))
\r
166 delpath.append(pin.replace(u".avi",u".m2v"))
\r
167 delpath.append(pin.replace(u".avi",u".120_video.264"))
\r
168 delpath.append(pin.replace(u".avi",u".ts.b25"))
\r
169 if os.path.exists(pout):
\r
170 if os.path.exists(audiopath):
\r
171 os.remove(audiopath)
\r
172 if os.path.exists(videopath):
\r
173 os.remove(videopath)
\r
181 def mkv2mp4(pin,pout):
\r
182 exeb = configreader.getpath(u"mkvextract")
\r
183 exe = configreader.getpath(u"MP4Box")
\r
184 dtsedit=configreader.getpath("DtsEdit")
\r
185 wineexe=configreader.getpath("wine")
\r
186 dir=os.path.split(pin)[0]
\r
187 title=os.path.split(pin)[1]
\r
188 title=os.path.splitext(title)[0]
\r
189 etitle=base64.b16encode(title.encode('utf-8'))
\r
190 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
191 videopath=os.path.join(dir,etitle+u"_video.264")
\r
192 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
\r
193 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
\r
194 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
\r
195 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
\r
196 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
\r
197 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
\r
198 logo=pin.replace(".avi",".log")
\r
199 os.environ['LANG']="ja_JP.UTF-8"
\r
205 txt = "\n####MKV2MP4-log####\n"+txt
\r
207 f.write(txt.encode('utf-8'))
\r
210 if os.path.exists(pout):
\r
211 if os.path.exists(audiopath):
\r
212 os.remove(audiopath)
\r
213 if os.path.exists(videopath):
\r
214 os.remove(videopath)
\r
215 if os.path.exists(timecodepath):
\r
216 os.remove(timecodepath)
\r
217 if os.path.exists(tmpmp4):
\r
222 txt=u"Cmd : "+cmd+"\n"
\r
223 txt2=commands.getoutput(cmd.encode('utf-8'))
\r
224 txt=txt+unicode(txt2,"utf-8")+"\n"
\r