3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
16 def ts2mp4(pin, pout, opt):
17 dir=os.path.split(pout)[0]
18 title=os.path.split(pout)[1]
19 title=os.path.splitext(title)[0]
20 tpavi=os.path.join(dir, title+".avi")
21 tv2avi.ts2avi(pin, tpavi, opt)
23 if not os.path.exists(tpavi):
24 if os.path.exists(pin):
26 avi2mp4(tpavi,pout,opt)
27 def avi2mp4(pin,pout,opt):
29 if re.search(u"v", opt):
31 exe = configreader.getpath(u"MP4Box")
32 dir=os.path.split(pin)[0]
33 title=os.path.split(pin)[1]
34 title=os.path.splitext(title)[0]
35 etitle=base64.b16encode(title)
36 audiopath=os.path.join(dir,etitle+u"_audio.raw")
37 videopath=os.path.join(dir,etitle+u"_video.264")
39 os.environ['LANG']="ja_JP.UTF-8"
42 wineexe=configreader.getpath("wine")
43 cfr2tc=configreader.getpath("cfr2tc")
44 dtsedit=configreader.getpath("DtsEdit")
45 pin120=os.path.join(dir,etitle+u".120.avi")
46 pints=os.path.join(dir,title+u".ts")
47 pmp4=os.path.join(dir,etitle+u".tmp.mp4")
48 pmp42=os.path.join(dir,etitle+u".tmp2.mp4")
49 pintimecode=os.path.join(dir,etitle+u".timecode.txt")
50 pinaac=os.path.join(dir,etitle+u".aac")
52 evfr.append("ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'")
53 evfr.append(wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2")
54 evfr.append(exe+u" -aviraw video \'"+pin120+u"\'")
55 videotpath=os.path.join(dir,etitle+u".120_video.264")
56 evfr.append(exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'")
57 evfr.append(wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pmp42+"\'")
58 evfr.append(exe+u" -add \'"+pinaac+"\' \'"+pmp42+"\'")
61 recdblist.printutf8(e)
64 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
68 shutil.move(pmp42,pout)
71 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
72 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
73 ptmp=pin.replace(".avi",".noodml.avi")
74 e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
76 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
78 e3=exe+u" -aviraw video \'"+pin120+u"\'"
80 e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -new \'"+pmp4+"\'"
82 e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pmp42+"\'"
84 e6=exe+u" -add \'"+pinaac+"\' \'"+pmp42+"\'"
86 recdblist.printutf8(e)
89 cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
93 cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
97 cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
101 cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
105 cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
109 cmdt=unicode(commands.getoutput(ex6.encode('utf-8')),'utf-8')
117 shutil.move(pmp42,pout)
123 shutil.move(pin,os.path.join(dir,etitle+".avi"))
126 e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"
127 e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"
130 if os.path.exists(audiopath):
131 if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):
132 audiopath=os.path.join(dir,etitle+u"_audio.mp3")
133 elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):
134 audiopath=os.path.join(dir,etitle+u"_audio.aac")
135 ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))
136 e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"
138 shutil.move(ptmp,pout)
139 logo=pin.replace(u".avi",u".log")
140 txt = "\n####MP4Box-log####\n"+txt
142 f.write(txt.encode('utf-8'))
146 delpath.append(pin.replace(u".avi",u".120.avi"))
147 delpath.append(pin.replace(u".avi",u".sa.avi"))
148 delpath.append(pin.replace(u".avi",u".ts"))
149 delpath.append(pin.replace(u".avi",u".aac"))
150 delpath.append(pin.replace(u".avi",u".m2v"))
151 delpath.append(pin.replace(u".avi",u".120_video.264"))
152 delpath.append(pin.replace(u".avi",u".ts.b25"))
153 if os.path.exists(pout):
154 if os.path.exists(audiopath):
156 if os.path.exists(videopath):
165 def mkv2mp4(pin,pout):
166 exeb = configreader.getpath(u"mkvextract")
167 exe = configreader.getpath(u"MP4Box")
168 dtsedit=configreader.getpath("DtsEdit")
169 wineexe=configreader.getpath("wine")
170 dir=os.path.split(pin)[0]
171 title=os.path.split(pin)[1]
172 title=os.path.splitext(title)[0]
173 etitle=base64.b16encode(title.encode('utf-8'))
174 audiopath=os.path.join(dir,etitle+u"_audio.raw")
175 videopath=os.path.join(dir,etitle+u"_video.264")
176 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
177 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
178 tmpmp42=os.path.join(dir,etitle+u".mp4")
179 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
180 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
181 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -new \'"+tmpmp4+u"\'"
182 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+tmpmp42+u"\'"
183 exe4=exe+u" -add \'"+audiopath+u"\' \'"+tmpmp42+u"\'"
184 logo=pin.replace(".avi",".log")
185 os.environ['LANG']="ja_JP.UTF-8"
186 txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
188 txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
192 txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
196 txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
200 commands.getoutput(exe3.encode('utf-8'))
204 txt = txt+unicode(commands.getoutput(exe4.encode('utf-8')),'utf-8')
207 shutil.move(tmpmp42,pout)
208 txt = "\n####MKV2MP4-log####\n"+txt
210 f.write(txt.encode('utf-8'))
213 if os.path.exists(pout):
214 if os.path.exists(audiopath):
216 if os.path.exists(videopath):
218 if os.path.exists(timecodepath):
219 os.remove(timecodepath)
220 if os.path.exists(tmpmp4):
222 if os.path.exists(tmpmp42):