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 pintimecode=os.path.join(dir,etitle+u".timecode.txt")
49 pinaac=os.path.join(dir,etitle+u".aac")
51 evfr.append("ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'")
52 evfr.append(wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2")
53 evfr.append(exe+u" -aviraw video \'"+pin120+u"\'")
54 videotpath=os.path.join(dir,etitle+u".120_video.264")
55 evfr.append(exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'")
56 evfr.append(wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'")
59 recdblist.printutf8(e)
62 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
65 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
66 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
67 ptmp=pin.replace(".avi",".noodml.avi")
68 e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
70 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
72 e3=exe+u" -aviraw video \'"+pin120+u"\'"
74 e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
76 e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
78 recdblist.printutf8(e)
81 cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
85 cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
89 cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
93 cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
97 cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
107 shutil.move(pin,os.path.join(dir,etitle+".avi"))
110 e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"
111 e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"
114 if not os.path.exists(audiopath):
115 if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):
116 audiopath=os.path.join(dir,etitle+u"_audio.mp3")
117 elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):
118 audiopath=os.path.join(dir,etitle+u"_audio.aac")
120 shutil.move(audiopath,os.path.join(dir,etitle+u"_audio.aac"))
121 audiopath=os.path.join(dir,etitle+u"_audio.aac")
122 ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))
123 e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"
125 shutil.move(ptmp,pout)
126 logo=pin.replace(u".avi",u".log")
127 txt = "\n####MP4Box-log####\n"+txt
129 f.write(txt.encode('utf-8'))
133 delpath.append(pin.replace(u".avi",u".120.avi"))
134 delpath.append(pin.replace(u".avi",u".sa.avi"))
135 delpath.append(pin.replace(u".avi",u".ts"))
136 delpath.append(pin.replace(u".avi",u".aac"))
137 delpath.append(pin.replace(u".avi",u".m2v"))
138 delpath.append(pin.replace(u".avi",u".120_video.264"))
139 delpath.append(pin.replace(u".avi",u".ts.b25"))
140 if os.path.exists(pout):
141 if os.path.exists(audiopath):
143 if os.path.exists(videopath):
152 def mkv2mp4(pin,pout):
153 exeb = configreader.getpath(u"mkvextract")
154 exe = configreader.getpath(u"MP4Box")
155 dtsedit=configreader.getpath("DtsEdit")
156 wineexe=configreader.getpath("wine")
157 dir=os.path.split(pin)[0]
158 title=os.path.split(pin)[1]
159 title=os.path.splitext(title)[0]
160 etitle=base64.b16encode(title.encode('utf-8'))
161 audiopath=os.path.join(dir,etitle+u"_audio.aac")
162 videopath=os.path.join(dir,etitle+u"_video.264")
163 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
164 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
165 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
166 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
167 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
168 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
169 logo=pin.replace(".avi",".log")
170 os.environ['LANG']="ja_JP.UTF-8"
171 txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
173 txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
177 txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
181 txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
185 os.system(exe3.encode('utf-8'))
188 txt = "\n####MKV2MP4-log####\n"+txt
190 f.write(txt.encode('utf-8'))
193 if os.path.exists(pout):
194 if os.path.exists(audiopath):
196 if os.path.exists(videopath):
198 if os.path.exists(timecodepath):
199 os.remove(timecodepath)
200 if os.path.exists(tmpmp4):