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 audiopath=os.path.join(dir,title+u"_audio.raw")
36 videopath=os.path.join(dir,title+u"_video.264")
38 os.environ['LANG']="ja_JP.UTF-8"
41 wineexe=configreader.getpath("wine")
42 cfr2tc=configreader.getpath("cfr2tc")
43 dtsedit=configreader.getpath("DtsEdit")
44 pin120=pin.replace(".avi",".120.avi")
45 pints=pin.replace(".avi",".ts")
46 pmp4=pin.replace(".avi",".tmp.mp4")
47 pintimecode=pin.replace(".avi",".timecode.txt")
48 pinaac=pin.replace(".avi",".aac")
50 evfr.append("ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'")
51 evfr.append(wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2")
52 evfr.append(exe+u" -aviraw video \'"+pin120+u"\'")
53 videotpath=os.path.join(dir,title+u".120_video.264")
54 evfr.append(exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'")
55 #evfr.append(exe+u" -add \'"+pinaac+"\' \'"+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')
82 cmdt=cmdt+unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
83 cmdt=cmdt+unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
84 cmdt=cmdt+unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
85 cmdt=cmdt+unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
91 exes.append(exe+u" -aviraw audio \'"+pin+u"\'")
92 exes.append(exe+u" -aviraw video \'"+pin+u"\'")
93 if os.path.exists(audiopath):
94 if os.path.exists(os.path.join(dir,title+u"_audio.mp3")):
95 audiopath=os.path.join(dir,title+u"_audio.mp3")
96 elif os.path.exists(os.path.join(dir,title+u"_audio.aac")):
97 audiopath=os.path.join(dir,title+u"_audio.aac")
98 exes.append(exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+pout+u"\'")
100 recdblist.printutf8(e)
103 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
106 logo=pin.replace(u".avi",u".log")
107 txt = "\n####MP4Box-log####\n"+txt
109 f.write(txt.encode('utf-8'))
113 delpath.append(pin.replace(u".avi",u".120.avi"))
114 delpath.append(pin.replace(u".avi",u".sa.avi"))
115 delpath.append(pin.replace(u".avi",u".ts"))
116 delpath.append(pin.replace(u".avi",u".aac"))
117 delpath.append(pin.replace(u".avi",u".m2v"))
118 delpath.append(pin.replace(u".avi",u".120_video.264"))
119 delpath.append(pin.replace(u".avi",u".ts.b25"))
120 if os.path.exists(pout):
121 if os.path.exists(audiopath):
123 if os.path.exists(videopath):
132 def mkv2mp4(pin,pout):
133 exeb = configreader.getpath(u"mkvextract")
134 exe = configreader.getpath(u"MP4Box")
135 dtsedit=configreader.getpath("DtsEdit")
136 wineexe=configreader.getpath("wine")
137 dir=os.path.split(pin)[0]
138 title=os.path.split(pin)[1]
139 title=os.path.splitext(title)[0]
140 etitle=base64.b16encode(title.encode('utf-8'))
141 audiopath=os.path.join(dir,etitle+u"_audio.raw")
142 videopath=os.path.join(dir,etitle+u"_video.264")
143 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
144 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
145 tmpmp42=os.path.join(dir,etitle+u".mp4")
146 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
147 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
148 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -new \'"+tmpmp4+u"\'"
149 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+tmpmp42+u"\'"
150 exe4=exe+u" -add \'"+audiopath+u"\' \'"+tmpmp42+u"\'"
151 logo=pin.replace(".avi",".log")
152 os.environ['LANG']="ja_JP.UTF-8"
153 txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
155 txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
159 txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
163 txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
167 commands.getoutput(exe3.encode('utf-8'))
171 txt = txt+unicode(commands.getoutput(exe4.encode('utf-8')),'utf-8')
174 shutil.move(tmpmp42,pout)
175 txt = "\n####MKV2MP4-log####\n"+txt
177 f.write(txt.encode('utf-8'))
180 if os.path.exists(pout):
181 if os.path.exists(audiopath):
183 if os.path.exists(videopath):
185 if os.path.exists(timecodepath):
186 os.remove(timecodepath)
187 if os.path.exists(tmpmp4):
189 if os.path.exists(tmpmp42):