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