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 re.search(opt,"MW8") or re.search(opt,"MW9"):
\r
132 if os.path.getsize(pout)>50*1000*1000:
\r
133 deltitle(dir,title)
\r
134 elif re.search(opt,"8") or re.search(opt,"9"):
\r
137 if os.path.getsize(pout)>100*1000*1000:
\r
138 deltitle(dir,title)
\r
139 def mkv2mp4(pin,pout):
\r
140 exeb = configreader.getpath(u"mkvextract")
\r
141 exe = configreader.getpath(u"mp4Box")
\r
142 #dtsedit=configreader.getpath("DtsEdit")
\r
143 wineexe=configreader.getpath("wine")
\r
144 dir=os.path.split(pin)[0]
\r
145 title=os.path.split(pin)[1]
\r
146 title=os.path.splitext(title)[0]
\r
147 etitle=base64.b16encode(title.encode('utf-8'))
\r
148 audiopath=os.path.join(dir,etitle+u"_audio.aac")
\r
149 videopath=os.path.join(dir,etitle+u"_video.264")
\r
150 timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
\r
151 tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
\r
152 exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
\r
153 exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
\r
154 exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
\r
155 exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
\r
156 os.environ['LANG']="ja_JP.UTF-8"
\r
159 txt=txt+execcomd(exe0)+"\n"
\r
160 txt=txt+execcomd(exe1)+"\n"
\r
161 txt=txt+execcomd(exe2)+"\n"
\r
162 txt=txt+execcomd(exe3)+"\n"
\r
165 recdblist.addlog(pin, txt, "MKV2MP4-log")
\r
166 txt = "\n####MKV2MP4-log####\n"+txt
\r
168 if status.getSettings_auto_del_tmp()==1:
\r
169 if os.path.exists(pout):
\r
170 if os.path.getsize(pout)>100*1000*1000:
\r
171 deltitle(dir,title)
\r
172 def execmp4box(pin,pout,cmd):
\r
173 title=os.path.splitext(os.path.split(pin)[1])[0]
\r
174 ptin=os.path.join(os.path.dirname(pin),base64.b16encode(title.encode('utf-8'))+".264")
\r
175 recdblist.printutf8(ptin)
\r
176 shutil.move(pin,ptin)
\r
178 ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")
\r
179 cmdn=string.replace(cmd,pin,ptin)
\r
180 cmdn=string.replace(cmdn,pout,ptout)
\r
181 recdblist.printutf8(cmdn)
\r
185 except Exception, inst:
\r
186 txt= "error occures in execmp4box\n"
\r
187 txt=txt+ str(type(inst))+"\n"
\r
189 recdblist.addlog(pin, txt, "MP4Box-log")
\r
191 shutil.move(ptin,pin)
\r
192 shutil.move(ptout,pout)
\r
194 def addmp4(padd,pout,cmd):#without video
\r
195 title=os.path.splitext(os.path.split(padd)[1])[0]
\r
196 ext=os.path.splitext(os.path.split(padd)[1])[1]
\r
197 ptadd=os.path.join(os.path.dirname(padd),base64.b16encode(title.encode('utf-8'))+ext)
\r
198 ptoutb=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+"_b.mp4")
\r
199 ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")
\r
200 shutil.move(padd,ptadd)
\r
201 if os.path.isfile(pout):
\r
202 shutil.move(pout,ptoutb)
\r
204 cmdn=string.replace(cmd,padd,ptadd)
\r
205 cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)
\r
206 cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)
\r
207 cmdn=string.replace(cmdn,pout,ptout)
\r
208 recdblist.printutf8(cmdn)
\r
212 except Exception, inst:
\r
213 txt= "error occures in addmp4\n"
\r
214 txt=txt+ str(type(inst))+"\n"
\r
216 recdblist.addlog(pout, txt, "MP4Box-log-add")
\r
219 shutil.move(ptadd,padd)
\r
220 shutil.move(ptout,pout)
\r
225 txt=u"Cmd : "+cmd+"\n"
\r
226 txt2=commands.getoutput(cmd.encode('utf-8'))
\r
227 txt=txt+unicode(txt2,"utf-8")+"\n"
\r
232 def deltitle(path,title):
\r
234 dp.append(os.path.join(path,title+".avi"))
\r
235 dp.append(os.path.join(path,title+".264"))
\r
236 dp.append(os.path.join(path,title+".120.avi"))
\r
237 dp.append(os.path.join(path,title+".noodml.avi"))
\r
238 dp.append(os.path.join(path,title+".aac"))
\r
239 dp.append(os.path.join(path,title+".m2v"))
\r
240 dp.append(os.path.join(path,title+"_1.aac"))
\r
241 dp.append(os.path.join(path,title+"_2.aac"))
\r
242 dp.append(os.path.join(path,title+"_1.mp3"))
\r
243 dp.append(os.path.join(path,title+"_2.mp3"))
\r
244 dp.append(os.path.join(path,title+".srt"))
\r
245 if configreader.getenv("remove_ts")=="1":
\r
246 dp.append(os.path.join(path,title+".ts"))
\r
247 if os.path.exists(os.path.join(path,title+".ts"))and os.path.exists(os.path.join(path,title+".ts.b25")):
\r
248 if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
\r
249 if os.path.getsize(os.path.join(path,title+".ts"))>1000*1000*100:
\r
250 dp.append(os.path.join(path,title+".ts.b25"))
\r
251 if os.path.exists(os.path.join(path,title+".mp4")):
\r
252 if os.path.getsize(os.path.join(path,title+".mp4"))>1000*1000*10:
\r