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 exes.append(exe+u" -new -fps 29.970030 -add \'"+videopath+u"\'#video -add \'"+audiopath+u"\'#audio \'"+pout+u"\'")
93 recdblist.printutf8(e)
96 txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
99 logo=pin.replace(u".avi",u".log")
100 txt = "\n####MP4Box-log####\n"+txt
102 f.write(txt.encode('utf-8'))
106 delpath.append(pin.replace(u".avi",u".120.avi"))
107 delpath.append(pin.replace(u".avi",u".sa.avi"))
108 delpath.append(pin.replace(u".avi",u".ts"))
109 delpath.append(pin.replace(u".avi",u".aac"))
110 delpath.append(pin.replace(u".avi",u".m2v"))
111 delpath.append(pin.replace(u".avi",u".120_video.h264"))
112 delpath.append(pin.replace(u".avi",u".ts.b25"))
113 if os.path.exists(pout):
114 if os.path.exists(audiopath):
116 if os.path.exists(videopath):
125 def mkv2mp4(pin,pout):
126 exeb = configreader.getpath(u"mkvextract")
127 exe = configreader.getpath(u"MP4Box")
128 dtsedit=configreader.getpath("DtsEdit")
129 wineexe=configreader.getpath("wine")
130 dir=os.path.split(pin)[0]
131 title=os.path.split(pin)[1]
132 title=os.path.splitext(title)[0]
133 audiopath=os.path.join(dir,title+u"_audio.raw")
134 videopath=os.path.join(dir,title+u"_video.h264")
135 timecodepath=os.path.join(dir,title+u"_1_timecode.txt")
136 tmpmp4=os.path.join(dir,title+u".tmp.mp4")
137 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
138 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
139 exe2=exe+u" -new -fps 29.970030 -add \'"+videopath+u"\'#video -add \'"+audiopath+u"\'#audio \'"+tmpmp4+u"\'"
140 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
141 logo=pin.replace(".avi",".log")
142 os.environ['LANG']="ja_JP.UTF-8"
143 txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
145 txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
146 txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
147 txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
148 txt = txt+unicode(commands.getoutput(exe3.encode('utf-8')),'utf-8')
153 txt = "\n####MKV2MP4-log####\n"+txt
155 f.write(txt.encode('utf-8'))
158 if os.path.exists(pout):
159 if os.path.exists(audiopath):
161 if os.path.exists(videopath):