From f6c151ceed9d4adcebd9d4b8c512f4471e643eac Mon Sep 17 00:00:00 2001 From: gn64_jp Date: Sun, 2 May 2010 07:51:45 +0000 Subject: [PATCH] implement caption/audio 0 byte error auto skip system. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@575 4e526526-5e11-4fc0-8910-f8fd03428081 --- rec10/trunk/src/tv2audio.py | 47 +++++++++++- rec10/trunk/src/tv2mp4.py | 177 ++++++++++++++++++++++++++++---------------- 2 files changed, 158 insertions(+), 66 deletions(-) diff --git a/rec10/trunk/src/tv2audio.py b/rec10/trunk/src/tv2audio.py index d28d310..7f0c793 100644 --- a/rec10/trunk/src/tv2audio.py +++ b/rec10/trunk/src/tv2audio.py @@ -1,5 +1,3 @@ -import commands -import os.path #!/usr/bin/python # coding: UTF-8 # Rec10 TS Recording Tools @@ -7,6 +5,11 @@ import os.path import os import configreader import recdblist +import commands +import os.path +import tv2audio +import subprocess +import signal def wav2aac_nero(pin,pout): os.environ['LANG']="ja_JP.UTF-8" neroaac=configreader.getpath('NeroAAC') @@ -31,4 +34,42 @@ def wav2mp3_lame(pin,pout): txt=txt+commands.getoutput(exe.encode('utf-8')) except: "" - recdblist.addlog(pin, txt, "Wav2aac_Lame log") \ No newline at end of file + recdblist.addlog(pin, txt, "Wav2aac_Lame log") +def ts2single_audio(pts): + ffmpeg=configreader.getpath("ffmpeg") + e0=ffmpeg+" -i \""+pts+"\" -vn -f aac -acodec copy \""+paac+"\"" + p0=subprocess.Popen(e0,shell=True) + time.sleep(60) + if p0.poll==-1:#実行中 + if os.path.getsize(paac)<1000:#1mで1kb以下の場合自動で終了 + os.kill(p0.pid,signal.SIGKILL) + os.remove(paac) + ts2singlewav(pts) + useNero=0 + try: + if configreader.getpath("useNeroAAC")=="1" and os.path.exists(configreader.getpath("NeroAAC")): + useNero=1 + except: + useNero=0 + if useNero==1: + aout=pts.replace(".ts",".aac") + ain=pts.replace(".ts",".wav") + tv2audio.wav2aac_nero(ain,aout) + else: + aout=pts.replace(".ts",".mp3") + ain=pts.replace(".ts",".wav") + tv2audio.wav2mp3_lame(ain,aout) + else: + os.waitpid(p0.pid, 0) +def ts2singlewav(pts): + bontsdemux = configreader.getpath('bontsdemux') + bonpin = "Z:\\" + pts[1:] + outf = os.path.splitext(pts)[0] + bonpout = "Z:\\" + outf[1:] + xvfb = configreader.getpath('xvfb-run') + exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit" + #recdblist.printutf8(exe) + exe = xvfb + ' -a ' + exe + recdblist.printutf8(exe) + p=subprocess.Popen(exe.encode('utf-8'),shell=True) + os.waitpid(p.pid, 0) diff --git a/rec10/trunk/src/tv2mp4.py b/rec10/trunk/src/tv2mp4.py index 86d2083..21b7345 100644 --- a/rec10/trunk/src/tv2mp4.py +++ b/rec10/trunk/src/tv2mp4.py @@ -14,6 +14,9 @@ import time import recdblist import configreader import status +import subprocess +import signal +import tv2audio def ts2mp4(pin, pout, opt): dir=os.path.split(pout)[0] @@ -52,80 +55,86 @@ def raw2mp4(pin,pout,opt): os.environ['LANG']="ja_JP.UTF-8" if isdualaac==1: wineexe=configreader.getpath("wine") - pincap=pin.replace(".264",".srt") - try: - cap2ass=configreader.getpath("caption2ass") - except: - cap2ass="" + #pincap=pin.replace(".264",".srt") + #try: + # cap2ass=configreader.getpath("caption2ass") + #except: + # cap2ass="" pints=pin.replace(".264",".ts") - paac1=pin.replace(".264","_1.aac") - paac2=pin.replace(".264","_2.aac") - recdblist.printutf8(paac1) - if not os.path.exists(paac1): - paac1=pin.replace(".264","_1.mp3") - if not os.path.exists(paac2): - paac2=pin.replace(".264","_2.mp3") - e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\"" + #paac1=pin.replace(".264","_1.aac") + #paac2=pin.replace(".264","_2.aac") + #recdblist.printutf8(paac1) + #if not os.path.exists(paac1): + # paac1=pin.replace(".264","_1.mp3") + #if not os.path.exists(paac2): + # paac2=pin.replace(".264","_2.mp3") + #e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\"" e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" - e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\"" - e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\"" - e1s=exe +u" -add \""+pincap+"\" \""+pout+"\"" - if os.path.isfile(cap2ass): - txt=txt+execcomd(e0) + #e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\"" + #e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\"" + #e1s=exe +u" -add \""+pincap+"\" \""+pout+"\"" + #if os.path.isfile(cap2ass): + # txt=txt+execcomd(e0) execmp4box(pin, pout, e1) - addmp4(paac1, pout, e1a1) - addmp4(paac2, pout, e1a2) - if os.path.exists(pincap) and (os.path.getsize(pincap)>1000): - addmp4(pincap, pout, e1s) + #addmp4(paac1, pout, e1a1) + #addmp4(paac2, pout, e1a2) + addAudio(pints, pout, opt) + addCaption(pints, pout) + #if os.path.exists(pincap) and (os.path.getsize(pincap)>1000): + # addmp4(pincap, pout, e1s) elif ispentaaudio==1: - wineexe=configreader.getpath("wine") - pincap=pin.replace(".264",".srt") - try: - cap2ass=configreader.getpath("caption2ass") - except: - cap2ass="" + #wineexe=configreader.getpath("wine") + #pincap=pin.replace(".264",".srt") + #try: + # cap2ass=configreader.getpath("caption2ass") + #except: + # cap2ass="" pints=pin.replace(".264",".ts") - paac1=pin.replace(".264","_1.aac") - paac2=pin.replace(".264","_2.aac") - recdblist.printutf8(paac1) - if not os.path.exists(paac1): - paac1=pin.replace(".264","_1.mp3") - if not os.path.exists(paac2): - paac2=pin.replace(".264","_2.mp3") - e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\"" + #paac1=pin.replace(".264","_1.aac") + #paac2=pin.replace(".264","_2.aac") + #recdblist.printutf8(paac1) + #if not os.path.exists(paac1): + # paac1=pin.replace(".264","_1.mp3") + #if not os.path.exists(paac2): + # paac2=pin.replace(".264","_2.mp3") + #e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\"" e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" - e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\"" - e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\"" - e1s=exe +u" -add \""+pincap+"\" \""+pout+"\"" - if os.path.isfile(cap2ass): - txt=txt+execcomd(e0) + #e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\"" + #e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\"" + #e1s=exe +u" -add \""+pincap+"\" \""+pout+"\"" + #if os.path.isfile(cap2ass): + # txt=txt+execcomd(e0) execmp4box(pin, pout, e1) - addmp4(paac1, pout, e1a1) - addmp4(paac2, pout, e1a2) - if os.path.exists(pincap) and (os.path.getsize(pincap)>1000): - addmp4(pincap, pout, e1s) + addAudio(pints, pout, opt) + #addmp4(paac1, pout, e1a1) + #addmp4(paac2, pout, e1a2) + addCaption(pints, pout) + #if os.path.exists(pincap) and (os.path.getsize(pincap)>1000): + # addmp4(pincap, pout, e1s) else: - wineexe=configreader.getpath("wine") - pincap=pin.replace(".264",".srt") - try: - cap2ass=configreader.getpath("caption2ass") - except: - cap2ass="" + #wineexe=configreader.getpath("wine") + #pincap=pin.replace(".264",".srt") + #try: + # cap2ass=configreader.getpath("caption2ass") + #except: + # cap2ass="" pints=pin.replace(".264",".ts") - pinaac=pin.replace(".264",".aac") - e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\"" - e1=ffmpeg+" -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\"" + #pinaac=pin.replace(".264",".aac") + #e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\"" + #e1=ffmpeg+" -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\"" e2=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" - e2a=exe +u" -add \""+pinaac+"\" \""+pout+"\"" - e2s=exe +u" -add \""+pincap+"\" \""+pout+"\"" - if os.path.isfile(cap2ass): - txt=txt+execcomd(e0) - txttt=execcomd(e1) - recdblist.addlog(pin, txttt, "get_aac") + #e2a=exe +u" -add \""+pinaac+"\" \""+pout+"\"" + #e2s=exe +u" -add \""+pincap+"\" \""+pout+"\"" + #if os.path.isfile(cap2ass): + # txt=txt+execcomd(e0) + #txttt=execcomd(e1) + #recdblist.addlog(pin, txttt, "get_aac") execmp4box(pin, pout, e2) - addmp4(pinaac, pout, e2a) - if os.path.exists(pincap) and (os.path.getsize(pincap)>1000): - addmp4(pincap, pout, e2s) + addAudio(pints, pout, opt) + #addmp4(pinaac, pout, e2a) + addCaption(pints, pout) + #if os.path.exists(pincap) and (os.path.getsize(pincap)>1000): + # addmp4(pincap, pout, e2s) recdblist.addlog(pout, txt, "mp4box-log") if status.getSettings_auto_del_tmp()==1: if os.path.exists(pout): @@ -170,6 +179,48 @@ def mkv2mp4(pin,pout): if os.path.exists(pout): if os.path.getsize(pout)>100*1000*1000: deltitle(dir,title) + +def addCaption(pts,pmp4):##字幕の追加を試みる。 + wineexe=configreader.getpath("wine") + pincap=pts.replace(".ts",".srt") + try: + cap2ass=configreader.getpath("caption2ass") + except: + cap2ass="" + if os.path.isfile(cap2ass): + e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pts+"\" \"Z:\\"+pincap+"\"" + p0=subprocess.Popen(e0,shell=True) + time.sleep(120) + if p0.poll==-1:#実行中 + if os.path.getsize(pincap)<1000:#2mで1kb以下の場合自動で終了 + os.kill(p0.pid,signal.SIGKILL) + else: + os.waitpid(p0.pid, 0) + if os.path.getsize(pincap)>1000: + exe = configreader.getpath("mp4box") + e1s=exe +u" -add \""+pincap+"\" \""+pout+"\"" + addmp4(pincap,pmp4,e1s) +def addAudio(pts,pmp4,opt):#オプションに応じた音声の追加を行う + exe = configreader.getpath("mp4box") + if re.search("d",opt) or re.search("5",opt):#二カ国語放送/5.1ch放送の場合 + paac1=pts.replace(".ts","_1.aac") + paac2=pts.replace(".ts","_2.aac") + recdblist.printutf8(paac1) + if not os.path.exists(paac1): + paac1=pts.replace(".ts","_1.mp3") + if not os.path.exists(paac2): + paac2=pts.replace(".ts","_2.mp3") + e1a1=exe +u" -add \""+paac1+"\" \""+pmp4+"\"" + e1a2=exe +u" -add \""+paac2+"\" \""+pmp4+"\"" + addmp4(paac1, pmp4, e1a1) + addmp4(paac2, pmp4, e1a2) + else: + tv2audio.ts2single_audio(pts) + pinaac=pts.replace(".ts",".aac") + if os.path.exists(pinaac): + pinaac=pinaac.replace(".aac",".mp3") + e1a=exe +u" -add \""+pinaac+"\" \""+pmp4+"\"" + addmp4(paac1, pmp4, e1a) def execmp4box(pin,pout,cmd): title=os.path.splitext(os.path.split(pin)[1])[0] ptin=os.path.join(os.path.dirname(pin),base64.b16encode(title.encode('utf-8'))+".264") -- 2.11.0