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:\\"+pout+"\'")
60 recdblist.printutf8(e)
63 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
66 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
67 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
68 ptmp=pin.replace(".avi",".noodml.avi")
69 e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
71 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
73 e3=exe+u" -aviraw video \'"+pin120+u"\'"
75 e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
77 e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
79 recdblist.printutf8(e)
82 cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
86 cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
90 cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
94 cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
98 cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
108 shutil.move(pin,os.path.join(dir,etitle+".avi"))
111 e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"
112 e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"
115 if not os.path.exists(audiopath):
116 if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):
117 audiopath=os.path.join(dir,etitle+u"_audio.mp3")
118 elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):
119 audiopath=os.path.join(dir,etitle+u"_audio.aac")
121 shutil.move(audiopath,os.path.join(dir,etitle+u"_audio.aac"))
122 audiopath=os.path.join(dir,etitle+u"_audio.aac")
123 ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))
124 e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"
126 shutil.move(ptmp,pout)
127 logo=pin.replace(u".avi",u".log")
128 txt = "\n####MP4Box-log####\n"+txt
130 f.write(txt.encode('utf-8'))
134 delpath.append(pin.replace(u".avi",u".120.avi"))
135 delpath.append(pin.replace(u".avi",u".sa.avi"))
136 delpath.append(pin.replace(u".avi",u".ts"))
137 delpath.append(pin.replace(u".avi",u".aac"))
138 delpath.append(pin.replace(u".avi",u".m2v"))
139 delpath.append(pin.replace(u".avi",u".120_video.264"))
140 delpath.append(pin.replace(u".avi",u".ts.b25"))
141 if os.path.exists(pout):
142 if os.path.exists(audiopath):
144 if os.path.exists(videopath):
153 def mkv2mp4(pin,pout):
154 exeb = configreader.getpath(u"mkvextract")
155 exe = configreader.getpath(u"MP4Box")
156 dtsedit=configreader.getpath("DtsEdit")
157 wineexe=configreader.getpath("wine")
158 dir=os.path.split(pin)[0]
159 title=os.path.split(pin)[1]
160 title=os.path.splitext(title)[0]
161 etitle=base64.b16encode(title.encode('utf-8'))
162 audiopath=os.path.join(dir,etitle+u"_audio.aac")
163 videopath=os.path.join(dir,etitle+u"_video.264")
164 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
165 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
166 tmpmp42=os.path.join(dir,etitle+u".mp4")
167 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
168 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
169 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
170 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
171 logo=pin.replace(".avi",".log")
172 os.environ['LANG']="ja_JP.UTF-8"
173 txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
175 txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
179 txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
183 txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
187 os.system(exe3.encode('utf-8'))
190 txt = "\n####MKV2MP4-log####\n"+txt
192 f.write(txt.encode('utf-8'))
195 if os.path.exists(pout):
196 if os.path.exists(audiopath):
198 if os.path.exists(videopath):
200 if os.path.exists(timecodepath):
201 os.remove(timecodepath)
202 if os.path.exists(tmpmp4):
204 if os.path.exists(tmpmp42):