3 # Rec10 TS Recording Tools
\r
4 # Copyright (C) 2009-2010 Yukikaze
\r
18 def ts2mp4(pin, pout, opt):
\r
19 dir=os.path.split(pout)[0]
\r
20 title=os.path.split(pout)[1]
\r
21 title=os.path.splitext(title)[0]
\r
22 tpraw=os.path.join(dir, title+".264")
\r
23 tpmp4=os.path.join(dir, title+".mp4")
\r
24 if os.path.isfile(pin) and os.path.getsize(pin)>10*1000:
\r
25 tv2avi.ts2raw(pin, tpraw, opt)
\r
27 if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000:
\r
28 raw2mp4(tpraw, tpmp4, opt)
\r
30 if os.path.exists(tpraw):
\r
32 def raw2mp4(pin,pout,opt):
\r
33 dir=os.path.split(pout)[0]
\r
34 title=os.path.split(pout)[1]
\r
35 title=os.path.splitext(title)[0]
\r
36 duration="-fps 29.970030 "
\r
37 ffmpeg=configreader.getpath("ffmpeg")
\r
40 if re.search("a",opt):
\r
41 duration="-fps 23.976023 "
\r
42 elif re.search("v",opt):
\r
43 duration="-fps 23.976023 "
\r
44 if re.search("d",opt):
\r
46 duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置
\r
47 elif re.search("5",opt):
\r
49 duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置
\r
50 exe = configreader.getpath("mp4box")
\r
52 os.environ['LANG']="ja_JP.UTF-8"
\r
54 wineexe=configreader.getpath("wine")
\r
55 pincap=pin.replace(".264",".srt")
\r
57 cap2ass=configreader.getpath("caption2ass")
\r
60 pints=pin.replace(".264",".ts")
\r
61 paac1=pin.replace(".264","_1.aac")
\r
62 paac2=pin.replace(".264","_2.aac")
\r
63 recdblist.printutf8(paac1)
\r
64 if not os.path.exists(paac1):
\r
65 paac1=pin.replace(".264","_1.mp3")
\r
66 if not os.path.exists(paac2):
\r
67 paac2=pin.replace(".264","_2.mp3")
\r
68 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
\r
69 e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""
\r
70 e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\""
\r
71 e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\""
\r
72 e1s=exe +u" -add \""+pincap+"\" \""+pout+"\""
\r
73 if os.path.isfile(cap2ass):
\r
74 txt=txt+execcomd(e0)
\r
75 execmp4box(pin, pout, e1)
\r
76 addmp4(paac1, pout, e1a1)
\r
77 addmp4(paac2, pout, e1a2)
\r
78 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
\r
79 addmp4(pincap, pout, e1s)
\r
80 elif ispentaaudio==1:
\r
81 wineexe=configreader.getpath("wine")
\r
82 pincap=pin.replace(".264",".srt")
\r
84 cap2ass=configreader.getpath("caption2ass")
\r
87 pints=pin.replace(".264",".ts")
\r
88 paac1=pin.replace(".264","_1.aac")
\r
89 paac2=pin.replace(".264","_2.aac")
\r
90 recdblist.printutf8(paac1)
\r
91 if not os.path.exists(paac1):
\r
92 paac1=pin.replace(".264","_1.mp3")
\r
93 if not os.path.exists(paac2):
\r
94 paac2=pin.replace(".264","_2.mp3")
\r
95 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
\r
96 e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""
\r
97 e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\""
\r
98 e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\""
\r
99 e1s=exe +u" -add \""+pincap+"\" \""+pout+"\""
\r
100 if os.path.isfile(cap2ass):
\r
101 txt=txt+execcomd(e0)
\r
102 execmp4box(pin, pout, e1)
\r
103 addmp4(paac1, pout, e1a1)
\r
104 addmp4(paac2, pout, e1a2)
\r
105 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
\r
106 addmp4(pincap, pout, e1s)
\r
108 wineexe=configreader.getpath("wine")
\r
109 pincap=pin.replace(".264",".srt")
\r
111 cap2ass=configreader.getpath("caption2ass")
\r
114 pints=pin.replace(".264",".ts")
\r
115 pinaac=pin.replace(".264",".aac")
\r
116 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
\r
117 e1=ffmpeg+" -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\""
\r
118 e2=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""
\r
119 e2a=exe +u" -add \""+pinaac+"\" \""+pout+"\""
\r
120 e2s=exe +u" -add \""+pincap+"\" \""+pout+"\""
\r
121 if os.path.isfile(cap2ass):
\r
122 txt=txt+execcomd(e0)
\r
123 txt=txt+execcomd(e1)
\r
124 execmp4box(pin, pout, e2)
\r
125 addmp4(pinaac, pout, e2a)
\r
126 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
\r
127 addmp4(pincap, pout, e2s)
\r
128 recdblist.addlog(pout, txt, "mp4box-log")
\r
129 if status.getSettings_auto_del_tmp()==1:
\r
130 if os.path.exists(pout):
\r
131 if os.path.getsize(pout)>100*1000*1000:
\r
132 deltitle(dir,title)
\r
133 def mkv2mp4(pin,pout):
\r
134 exeb = configreader.getpath(u"mkvextract")
\r
135 exe = configreader.getpath(u"mp4Box")
\r
136 #dtsedit=configreader.getpath("DtsEdit")
\r
137 wineexe=configreader.getpath("wine")
\r
138 dir=os.path.split(pin)[0]
\r
139 title=os.path.split(pin)[1]
\r
140 title=os.path.splitext(title)[0]
\r
141 etitle=base64.b16encode(title.encode('utf-8'))
\r
142 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
143 videopath=os.path.join(dir,etitle+u"_video.264")
\r
144 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
\r
145 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
\r
146 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
\r
147 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
\r
148 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
\r
149 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
\r
150 os.environ['LANG']="ja_JP.UTF-8"
\r
153 txt=txt+execcomd(exe0)+"\n"
\r
154 txt=txt+execcomd(exe1)+"\n"
\r
155 txt=txt+execcomd(exe2)+"\n"
\r
156 txt=txt+execcomd(exe3)+"\n"
\r
159 recdblist.addlog(pin, txt, "MKV2MP4-log")
\r
160 txt = "\n####MKV2MP4-log####\n"+txt
\r
162 if status.getSettings_auto_del_tmp()==1:
\r
163 if os.path.exists(pout):
\r
164 if os.path.getsize(pout)>100*1000*1000:
\r
165 deltitle(dir,title)
\r
166 def execmp4box(pin,pout,cmd):
\r
167 title=os.path.splitext(os.path.split(pin)[1])[0]
\r
168 ptin=os.path.join(os.path.dirname(pin),base64.b16encode(title.encode('utf-8'))+".264")
\r
169 recdblist.printutf8(ptin)
\r
170 shutil.move(pin,ptin)
\r
172 ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")
\r
173 cmdn=string.replace(cmd,pin,ptin)
\r
174 cmdn=string.replace(cmdn,pout,ptout)
\r
175 recdblist.printutf8(cmdn)
\r
179 except Exception, inst:
\r
180 txt= "error occures in execmp4box\n"
\r
181 txt=txt+ str(type(inst))+"\n"
\r
183 recdblist.addlog(pin, txt, "MP4Box-log")
\r
185 shutil.move(ptin,pin)
\r
186 shutil.move(ptout,pout)
\r
188 def addmp4(padd,pout,cmd):#without video
\r
189 title=os.path.splitext(os.path.split(padd)[1])[0]
\r
190 ext=os.path.splitext(os.path.split(padd)[1])[1]
\r
191 ptadd=os.path.join(os.path.dirname(padd),base64.b16encode(title.encode('utf-8'))+ext)
\r
192 ptoutb=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+"_b.mp4")
\r
193 ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")
\r
194 shutil.move(padd,ptadd)
\r
195 if os.path.isfile(pout):
\r
196 shutil.move(pout,ptoutb)
\r
198 cmdn=string.replace(cmd,padd,ptadd)
\r
199 cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)
\r
200 cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)
\r
201 cmdn=string.replace(cmdn,pout,ptout)
\r
202 recdblist.printutf8(cmdn)
\r
206 except Exception, inst:
\r
207 txt= "error occures in addmp4\n"
\r
208 txt=txt+ str(type(inst))+"\n"
\r
210 recdblist.addlog(pout, txt, "MP4Box-log-add")
\r
213 shutil.move(ptadd,padd)
\r
214 shutil.move(ptout,pout)
\r
219 txt=u"Cmd : "+cmd+"\n"
\r
220 txt2=commands.getoutput(cmd.encode('utf-8'))
\r
221 txt=txt+unicode(txt2,"utf-8")+"\n"
\r
226 def deltitle(path,title):
\r
228 dp.append(os.path.join(path,title+".avi"))
\r
229 dp.append(os.path.join(path,title+".264"))
\r
230 dp.append(os.path.join(path,title+".120.avi"))
\r
231 dp.append(os.path.join(path,title+".noodml.avi"))
\r
232 dp.append(os.path.join(path,title+".aac"))
\r
233 dp.append(os.path.join(path,title+".m2v"))
\r
234 dp.append(os.path.join(path,title+"_1.aac"))
\r
235 dp.append(os.path.join(path,title+"_2.aac"))
\r
236 dp.append(os.path.join(path,title+"_1.mp3"))
\r
237 dp.append(os.path.join(path,title+"_2.mp3"))
\r
238 dp.append(os.path.join(path,title+".srt"))
\r
239 if configreader.getenv("remove_ts")=="1":
\r
240 dp.append(os.path.join(path,title+".ts"))
\r
241 if os.path.exists(os.path.join(path,title+".ts"))and os.path.exists(os.path.join(path,title+".ts.b25")):
\r
242 if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
\r
243 if os.path.getsize(os.path.join(path,title+".ts"))>1000*1000*100:
\r
244 dp.append(os.path.join(path,title+".ts.b25"))
\r
245 if os.path.exists(os.path.join(path,title+".mp4")):
\r
246 if os.path.getsize(os.path.join(path,title+".mp4"))>1000*1000*10:
\r