3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2011 Yukikaze
18 def wav2aac_nero(pin,pout):
19 os.environ['LANG']="ja_JP.UTF-8"
20 neroaac=configreader.getConfPath('NeroAAC')
21 exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\""
23 txt=commands.getoutput(exe.encode('utf-8'))
24 recdblist.addLog(pin, exe, u"Wav2aac_Neroログ-コマンド")
25 recdblist.addLog(pin, txt, u"Wav2aac_Neroログ-詳細")
27 if not os.path.exists(pout):
29 exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
30 txt=commands.getoutput(exe.encode('utf-8'))
31 recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド")
32 recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細")
33 def wav2mp3_lame(pin,pout):
34 os.environ['LANG']="ja_JP.UTF-8"
35 lame=configreader.getConfPath('lame')
36 exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
38 txt=commands.getoutput(exe.encode('utf-8'))
41 recdblist.addLog(pin, exe, u"Wav2aac_Lameログ-コマンド")
42 recdblist.addLog(pin, txt, u"Wav2aac_Lameログ-詳細")
43 def ts2single_audio(pts,opts):
44 paac=pts.replace(".ts",".aac")
45 ffmpeg=configreader.getConfPath("ffmpeg")
46 e0=ffmpeg+" -i \""+pts+"\" -y -vn -acodec copy \""+paac+"\""
47 p0=subprocess.Popen(e0,shell=True)
50 if os.path.exists(paac):
51 if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了
53 logt=unicode(p0.communicate()[0], "UTF-8")
54 recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")
55 recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")
58 recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)
59 os.kill(p0.pid,signal.SIGKILL)
61 ts2single_mp3_ffmpeg(pts)
62 if not os.path.exists(pts.replace(".ts",".mp3")):
63 ts2single_fp_BonTsDemux(pts,opts)
65 logt=unicode(p0.communicate()[0], "UTF-8")
66 recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")
67 recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")
70 logt=unicode(p0.communicate()[0], "UTF-8")
71 recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")
72 recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")
75 recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)
77 os.kill(p0.pid,signal.SIGKILL)
80 ts2single_mp3_ffmpeg(pts)
81 if not os.path.exists(pts.replace(".ts",".mp3")):
82 ts2single_fp_BonTsDemux(pts,opts)
84 if os.path.exists(paac):
85 if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了
87 logt=unicode(p0.communicate()[0], "UTF-8")
88 recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")
89 recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")
92 recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)
94 ts2single_mp3_ffmpeg(pts)
95 if not os.path.exists(pts.replace(".ts",".mp3")):
96 ts2single_fp_BonTsDemux(pts,opts)
99 logt=unicode(p0.communicate()[0], "UTF-8")
100 recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")
101 recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")
106 logt=unicode(p0.communicate()[0], "UTF-8")
107 recdblist.addLog(pts,e0, "FFmpeg音声取り出しログ-コマンド")
108 recdblist.addLog(pts,logt, "FFmpeg音声取り出しログ-詳細")
111 recdblist.addCommonlogEX("[Error]", "ffmpeg aac getting. (ts2single_audio@tv2audio.py)", u"AAC demux error(ffmpeg)", "", verbose_level=200, log_level=200)
112 ts2single_mp3_ffmpeg(pts)
113 if not os.path.exists(pts.replace(".ts",".mp3")):
114 ts2single_fp_BonTsDemux(pts,opts)
115 def ts2singlewav(pts,opts):
116 bontsdemux = configreader.getConfPath('bontsdemux')
117 bonpin = "Z:\\" + pts[1:]
118 outf = os.path.splitext(pts)[0]
119 bonpout = "Z:\\" + outf[1:]
121 exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" "+delayt+" -nd -sound 0 -o \"" + bonpout + "\""
122 #recdblist.printutf8(exe)
123 recdblist.printutf8(exe)
124 txt=commands.getoutput(exe.encode('utf-8'))
125 recdblist.addCommandLog(pts, u"BonTsDemux 音声取り出し", exe, txt)
126 def ts2single_mp3_ffmpeg(pts):
127 pmp3=pts.replace(".ts",".mp3")
128 ffmpeg=configreader.getConfPath("ffmpeg")
129 e0=ffmpeg+" -i \""+pts+"\" -y -vn -ab 128k \""+pmp3+"\""
130 p0=subprocess.Popen(e0,shell=True)
131 os.waitpid(p0.pid, 0)
133 logt=unicode(p0.communicate()[0], "UTF-8")
134 recdblist.addLog(pts,e0, "FFmpeg_mp3音声取り出しログ-コマンド")
135 recdblist.addLog(pts,logt, "FFmpeg_mp3音声取り出しログ-詳細")
138 def ts2single_aac_ffmpeg(pts):
139 ts2singlewav(pts,opts)
140 aout=pts.replace(".ts",".aac")
141 ain=pts.replace(".ts",".wav")
142 wav2aac_ffmpeg(ain,aout)
143 def wav2aac_ffmpeg(pin,pout):
144 paac=pts.replace(".ts",".aac")
145 ffmpeg=configreader.getConfPath("ffmpeg")
146 e0=ffmpeg+" -i \""+pin+"\" -y \""+pout+"\""
147 p0=subprocess.Popen(e0,shell=True)
148 os.waitpid(p0.pid, 0)
150 logt=unicode(p0.communicate()[0], "UTF-8")
151 recdblist.addLog(pts,e0, "FFmpeg_wav2aac音声取り出しログ-コマンド")
152 recdblist.addLog(pts,logt, "FFmpeg_wav2aac音声取り出しログ-詳細")
155 def ts2single_fp_BonTsDemux(pts,opts):
158 if configreader.getConfPath("useNeroAAC")=="1" and os.path.exists(configreader.getConfPath("NeroAAC")):
163 ts2single_aac_BonTsDemux_Nero(pts,opts)
165 ts2single_aac_ffmpeg(pts)
166 if not os.path.exists(pts.replace(".ts",".aac")):
167 ts2single_mp3_BonTsDemux(pts,opts)
168 def ts2single_aac_BonTsDemux_Nero(pts,opts):
169 ts2singlewav(pts,opts)
170 aout=pts.replace(".ts",".aac")
171 ain=pts.replace(".ts",".wav")
172 wav2aac_nero(ain,aout)
173 def ts2single_mp3_BonTsDemux(pts,opts):
174 ts2singlewav(pts,opts)
175 aout=pts.replace(".ts",".mp3")
176 ain=pts.replace(".ts",".wav")
177 wav2mp3_lame(ain,aout)
178 def ts2dualaudio_BonTsDemux(pin, delay,opts):
182 bontsdemux = configreader.getConfPath('bontsdemux')
183 wine = configreader.getConfPath('wine')
184 bonpin = "Z:\\" + pin[1:]
185 outf = os.path.splitext(pin)[0]
186 bonpout = "Z:\\" + outf[1:]
187 exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\""
188 recdblist.printutf8(exe)
189 txt=commands.getoutput(exe.encode('utf-8'))
191 recdblist.addCommandLog(pin, u"BonTsDemux 第一音声取り出し", exe, txt)
194 ffpin = pin.replace(".ts", "")
195 ffpin1 = pin.replace("ts", "wav")
196 ffpin2 = pin.replace("ts", "m2v")
197 ffpout1 = ffpin + "_1.wav"
198 ffpout2 = ffpin + "_2.wav"
199 ffpout3 = ffpin + ".m2v"
200 shutil.move(ffpin1, ffpout1)
201 exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\""
202 recdblist.printutf8(exe)
203 txt=commands.getoutput(exe.encode('utf-8'))
205 recdblist.addCommandLog(pin, u"BonTsDemux 第二音声取り出し", exe, txt)
209 shutil.move(ffpin1, ffpout2)
210 shutil.move(ffpin2, ffpout3)
211 ffpout21=ffpout1.replace(".wav",".mp3")
212 ffpout22=ffpout2.replace(".wav",".mp3")
215 if os.path.exists(configreader.getConfPath("NeroAAC")):
220 ffpout21=ffpout1.replace(".wav",".aac")
221 ffpout22=ffpout2.replace(".wav",".aac")
222 wav2aac_nero(ffpout1, ffpout21)
223 wav2aac_nero(ffpout2, ffpout22)
225 wav2mp3_lame(ffpout1, ffpout21)
226 wav2mp3_lame(ffpout2, ffpout22)
230 def ts2pentaaudio_BonTsDemux(pin, delay,opts):
231 bontsdemux = configreader.getConfPath('bontsdemux')
232 wine = configreader.getConfPath('wine')
233 bonpin = "Z:\\" + pin[1:]
234 outf = os.path.splitext(pin)[0]
235 bonpout = "Z:\\" + outf[1:]
236 exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 3 -o \"" + bonpout + "\""
237 recdblist.printutf8(exe)
238 txt=commands.getoutput(exe.encode('utf-8'))
240 recdblist.addCommandLog(pin, u"BonTsDemux5.1ch 第一音声取り出し", exe, txt)
243 ffpin = pin.replace(".ts", "")
244 ffpin1 = pin.replace("ts", "wav")
245 ffpin2 = pin.replace("ts", "m2v")
246 ffpout1 = ffpin + "_1.wav"
247 ffpout2 = ffpin + "_2.aac"
248 shutil.move(ffpin1, ffpout1)
249 exe = "ffmpeg -i '"+pin+"' -vn -f aac -acodec copy '"+ffpout2+"'"
250 recdblist.printutf8(exe)
251 txt=commands.getoutput(exe.encode('utf-8'))
253 recdblist.addCommandLog(pin, u"FFmpeg 5.1ch 第二音声(raw AAC)取り出し", exe, txt)
256 ffpout21=ffpout1.replace(".wav",".mp3")
259 if os.path.exists(configreader.getConfPath("NeroAAC")):
264 ffpout21=ffpout1.replace(".wav",".aac")
265 wav2aac_nero(ffpout1, ffpout21)
267 wav2mp3_lame(ffpout1, ffpout21)
268 if not os.path.exists(ffpout21):
269 exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay "+delay+" -nd -sound 0 -o \"" + bonpout + "\""
270 recdblist.printutf8(exe)
271 txt=commands.getoutput(exe.encode('utf-8'))
273 recdblist.addCommandLog(pin, u"BonTsDemux 修正版第二音声(2chDownmix)取り出し", exe, txt)
276 shutil.move(ffpin1, ffpout1)
278 ffpout21=ffpout1.replace(".wav",".aac")
279 wav2aac_nero(ffpout1, ffpout21)
281 wav2mp3_lame(ffpout1, ffpout21)
283 ffpout21=ffpout1.replace(".wav",".aac")
284 if os.path.exists(ffpout21):
285 if os.path.getsize(ffpout21)>10*1000*1000: