3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
14 def ts2mp4(pin, pout, opt):
15 dir=os.path.split(pout)[0]
16 title=os.path.split(pout)[1]
17 title=os.path.splitext(title)[0]
18 tpavi=os.path.join(dir, title+".avi")
19 tv2avi.ts2avi(pin, tpavi, opt)
21 if not os.path.exists(tpavi):
22 if os.path.exists(pin):
24 avi2mp4(tpavi,pout,opt)
25 def avi2mp4(pin,pout,opt):
27 if re.search(u"v", opt):
29 exe = configreader.getpath(u"MP4Box")
30 dir=os.path.split(pin)[0]
31 title=os.path.split(pin)[1]
32 title=os.path.splitext(title)[0]
33 audiopath=os.path.join(dir,title+u"_audio.raw")
34 videopath=os.path.join(dir,title+u"_video.h264")
36 os.environ['LANG']="ja_JP.UTF-8"
39 wineexe=configreader.getpath("wine")
40 cfr2tc=configreader.getpath("cfr2tc")
41 dtsedit=configreader.getpath("DtsEdit")
42 pin120=pin.replace(".avi",".120.avi")
43 pints=pin.replace(".avi",".ts")
44 pmp4=pin.replace(".avi",".tmp.mp4")
45 pintimecode=pin.replace(".avi",".timecode.txt")
46 pinaac=pin.replace(".avi",".aac")
48 evfr.append("ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'")
49 evfr.append(wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2")
50 evfr.append(exe+u" -aviraw video \'"+pin120+u"\'")
51 videotpath=os.path.join(dir,title+u".120_video.h264")
52 evfr.append(exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'")
53 #evfr.append(exe+u" -add \'"+pinaac+"\' \'"+pmp4+"\'")
54 evfr.append(wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'")
57 recdblist.printutf8(e)
60 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
63 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
64 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
65 ptmp=pin.replace(".avi",".noodml.avi")
66 e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
68 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
70 e3=exe+u" -aviraw video \'"+pin120+u"\'"
72 e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
74 e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
76 recdblist.printutf8(e)
79 cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
80 cmdt=cmdt+unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
81 cmdt=cmdt+unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
82 cmdt=cmdt+unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
83 cmdt=cmdt+unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
89 exes.append(exe+u" -aviraw audio \'"+pin+u"\'")
90 exes.append(exe+u" -aviraw video \'"+pin+u"\'")
91 if os.path.exists(audiopath):
92 if os.path.exists(os.path.join(dir,title+u"_audio.mp3")):
93 audiopath=os.path.join(dir,title+u"_audio.mp3")
94 elif os.path.exists(os.path.join(dir,title+u"_audio.aac")):
95 audiopath=os.path.join(dir,title+u"_audio.aac")
96 exes.append(exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+pout+u"\'")
98 recdblist.printutf8(e)
101 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
104 logo=pin.replace(u".avi",u".log")
105 txt = "\n####MP4Box-log####\n"+txt
107 f.write(txt.encode('utf-8'))
111 delpath.append(pin.replace(u".avi",u".120.avi"))
112 delpath.append(pin.replace(u".avi",u".sa.avi"))
113 delpath.append(pin.replace(u".avi",u".ts"))
114 delpath.append(pin.replace(u".avi",u".aac"))
115 delpath.append(pin.replace(u".avi",u".m2v"))
116 delpath.append(pin.replace(u".avi",u".120_video.h264"))
117 delpath.append(pin.replace(u".avi",u".ts.b25"))
118 if os.path.exists(pout):
119 if os.path.exists(audiopath):
121 if os.path.exists(videopath):
130 def mkv2mp4(pin,pout):
131 exeb = configreader.getpath(u"mkvextract")
132 exe = configreader.getpath(u"MP4Box")
133 dtsedit=configreader.getpath("DtsEdit")
134 wineexe=configreader.getpath("wine")
135 dir=os.path.split(pin)[0]
136 title=os.path.split(pin)[1]
137 title=os.path.splitext(title)[0]
138 audiopath=os.path.join(dir,title+u"_audio.raw")
139 videopath=os.path.join(dir,title+u"_video.h264")
140 timecodepath=os.path.join(dir,title+u"_1_timecode.txt")
141 tmpmp4=os.path.join(dir,title+u".tmp.mp4")
142 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
143 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
144 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
145 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
146 logo=pin.replace(".avi",".log")
147 os.environ['LANG']="ja_JP.UTF-8"
148 txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
150 txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
151 txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
152 txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
153 txt = txt+unicode(commands.getoutput(exe3.encode('utf-8')),'utf-8')
158 txt = "\n####MKV2MP4-log####\n"+txt
160 f.write(txt.encode('utf-8'))
163 if os.path.exists(pout):
164 if os.path.exists(audiopath):
166 if os.path.exists(videopath):