OSDN Git Service

implement caption/audio 0 byte error auto skip system.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2audio.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009-2010 Yukikaze
5 import os
6 import configreader
7 import recdblist
8 import commands
9 import os.path
10 import tv2audio
11 import subprocess
12 import signal
13 import time
14 def wav2aac_nero(pin,pout):
15     os.environ['LANG']="ja_JP.UTF-8"
16     neroaac=configreader.getpath('NeroAAC')
17     exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\""
18     txt=u"Cmd : "+exe+"\n"
19     try:
20         txt=txt+commands.getoutput(exe.encode('utf-8'))
21         recdblist.addlog(pin, txt, "Wav2aac_Nero log")
22     except:
23         if not os.path.exists(pout):
24             lame="lame"
25             exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
26             txt=u"Cmd : "+exe+"\n"
27             txt=txt+commands.getoutput(exe.encode('utf-8'))
28             recdblist.addlog(pin, txt, "Wav2aac_Lame log")
29 def wav2mp3_lame(pin,pout):
30     os.environ['LANG']="ja_JP.UTF-8"
31     lame="lame"
32     exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
33     txt=u"Cmd : "+exe+"\n"
34     try:
35         txt=txt+commands.getoutput(exe.encode('utf-8'))
36     except:
37         ""
38     recdblist.addlog(pin, txt, "Wav2aac_Lame log")
39 def ts2single_audio(pts):
40     paac=pts.replace(".ts",".aac")
41     ffmpeg=configreader.getpath("ffmpeg")
42     e0=ffmpeg+" -i \""+pts+"\" -y -vn -f aac -acodec copy \""+paac+"\""
43     p0=subprocess.Popen(e0,shell=True)
44     time.sleep(60)
45     if p0.poll==-1:#実行中
46         if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了
47             os.kill(p0.pid,signal.SIGKILL)
48             os.remove(paac)
49             ts2singlewav(pts)
50             useNero=0
51             try:
52                 if configreader.getpath("useNeroAAC")=="1" and os.path.exists(configreader.getpath("NeroAAC")):
53                     useNero=1
54             except:
55                 useNero=0
56             if useNero==1:
57                 aout=pts.replace(".ts",".aac")
58                 ain=pts.replace(".ts",".wav")
59                 tv2audio.wav2aac_nero(ain,aout)
60             else:
61                 aout=pts.replace(".ts",".mp3")
62                 ain=pts.replace(".ts",".wav")
63                 tv2audio.wav2mp3_lame(ain,aout)
64         else:
65             os.waitpid(p0.pid, 0)
66 def ts2singlewav(pts):
67     bontsdemux = configreader.getpath('bontsdemux')
68     bonpin = "Z:\\" + pts[1:]
69     outf = os.path.splitext(pts)[0]
70     bonpout = "Z:\\" + outf[1:]
71     xvfb = configreader.getpath('xvfb-run')
72     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit"
73     #recdblist.printutf8(exe)
74     exe = xvfb + ' -a ' + exe
75     recdblist.printutf8(exe)
76     p=subprocess.Popen(exe.encode('utf-8'),shell=True)
77     os.waitpid(p.pid, 0)