X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=rec10%2Ftrunk%2Fsrc%2Ftv2mp4.py;h=c202c0091bbb36f347a5053b69b2dc515fc0432f;hb=894af3141aba10fec8010eeecc9315689911ff9b;hp=21b734528615dfcf8e135373644d2e8bef70b71c;hpb=f6c151ceed9d4adcebd9d4b8c512f4471e643eac;p=rec10%2Frec10-git.git diff --git a/rec10/trunk/src/tv2mp4.py b/rec10/trunk/src/tv2mp4.py index 21b7345..c202c00 100644 --- a/rec10/trunk/src/tv2mp4.py +++ b/rec10/trunk/src/tv2mp4.py @@ -4,18 +4,19 @@ # Copyright (C) 2009-2010 Yukikaze import commands import shutil -import tv2avi +import auto_process import os import re import os.path import string import base64 import time +import subprocess + +import tv2avi import recdblist import configreader import status -import subprocess -import signal import tv2audio def ts2mp4(pin, pout, opt): @@ -37,115 +38,32 @@ def raw2mp4(pin,pout,opt): title=os.path.split(pout)[1] title=os.path.splitext(title)[0] duration="-fps 29.970030 " - ffmpeg=configreader.getpath("ffmpeg") - isdualaac=0 - ispentaaudio=0 if re.search("a",opt): duration="-fps 23.976023 " elif re.search("v",opt): duration="-fps 23.976023 " if re.search("d",opt): - isdualaac=1 duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置 elif re.search("5",opt): - ispentaaudio=1 duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置 exe = configreader.getpath("mp4box") txt="" 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="" - 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+"\"" - 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) - execmp4box(pin, pout, e1) - #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="" - 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+"\"" - 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) - execmp4box(pin, pout, e1) - 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="" - 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+"\"" - 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") - execmp4box(pin, pout, e2) - 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") + pints=pin.replace(".264",".ts") + e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\"" + execmp4box(pin, pout, e1) + addAudio(pints, pout, opt) + addCaption(pints, pout) + #recdblist.addlog(pout, txt, "mp4boxログ-コマンド") + #recdblist.addlog(pout, txt, "mp4boxログ-詳細") if status.getSettings_auto_del_tmp()==1: if os.path.exists(pout): if re.search(opt,"MW8") or re.search(opt,"MW9"): - if os.path.getsize(pout)>50*1000*1000: - deltitle(dir,title) + auto_process.deltmpfile(dir, title, ".mp4") elif re.search(opt,"8") or re.search(opt,"9"): "" else: - if os.path.getsize(pout)>100*1000*1000: - deltitle(dir,title) + auto_process.deltmpfile(dir, title, ".mp4") def mkv2mp4(pin,pout): exeb = configreader.getpath(u"mkvextract") exe = configreader.getpath(u"mp4Box") @@ -172,14 +90,12 @@ def mkv2mp4(pin,pout): txt=txt+execcomd(exe3)+"\n" except: "" - recdblist.addlog(pin, txt, "MKV2MP4-log") + recdblist.addlog(pin, txt, u"MKV2MP4-log") txt = "\n####MKV2MP4-log####\n"+txt time.sleep(10) if status.getSettings_auto_del_tmp()==1: if os.path.exists(pout): - if os.path.getsize(pout)>100*1000*1000: - deltitle(dir,title) - + auto_process.deltmpfile(dir, title, ".mp4") def addCaption(pts,pmp4):##字幕の追加を試みる。 wineexe=configreader.getpath("wine") pincap=pts.replace(".ts",".srt") @@ -189,17 +105,22 @@ def addCaption(pts,pmp4):##字幕の追加を試みる。 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) + recdblist.printutf8(e0) + p0=subprocess.Popen(e0,shell=True,stdout=subprocess.PIPE) + time.sleep(300) + if p0.poll==None:#実行中 + #if os.path.getsize(pincap)<1000:#2mで1kb以下の場合自動で終了 + # os.kill(p0.pid,signal.SIGKILL) + #else: + os.waitpid(p0.pid, 0) + logt=unicode(p0.communicate()[0], "UTF-8") + recdblist.addlog(pts,e0, u"Captionログ-コマンド") + recdblist.addlog(pts,logt, u"Captionログ-詳細") + if os.path.exists(pincap): + if os.path.getsize(pincap)>1000: + exe = configreader.getpath("mp4box") + e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\"" + 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放送の場合 @@ -217,17 +138,20 @@ def addAudio(pts,pmp4,opt):#オプションに応じた音声の追加を行う else: tv2audio.ts2single_audio(pts) pinaac=pts.replace(".ts",".aac") - if os.path.exists(pinaac): + if not os.path.exists(pinaac): pinaac=pinaac.replace(".aac",".mp3") e1a=exe +u" -add \""+pinaac+"\" \""+pmp4+"\"" - addmp4(paac1, pmp4, e1a) + addmp4(pinaac, 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") + nt=base64.b16encode(title.encode('utf-8')) + if len(nt)>200: + nt=nt[:180] + ptin=os.path.join(os.path.dirname(pin),nt+".264") recdblist.printutf8(ptin) shutil.move(pin,ptin) time.sleep(10) - ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4") + ptout=os.path.join(os.path.dirname(pout),nt+".mp4") cmdn=string.replace(cmd,pin,ptin) cmdn=string.replace(cmdn,pout,ptout) recdblist.printutf8(cmdn) @@ -238,7 +162,8 @@ def execmp4box(pin,pout,cmd): txt= "error occures in execmp4box\n" txt=txt+ str(type(inst))+"\n" txt=txt+str(inst) - recdblist.addlog(pin, txt, "MP4Box-log") + recdblist.addlog(pin, cmdn, u"MP4Boxログ-コマンド") + recdblist.addlog(pin, txt, u"MP4Boxログ-詳細") time.sleep(5) shutil.move(ptin,pin) shutil.move(ptout,pout) @@ -246,9 +171,12 @@ def execmp4box(pin,pout,cmd): def addmp4(padd,pout,cmd):#without video title=os.path.splitext(os.path.split(padd)[1])[0] ext=os.path.splitext(os.path.split(padd)[1])[1] - ptadd=os.path.join(os.path.dirname(padd),base64.b16encode(title.encode('utf-8'))+ext) - ptoutb=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+"_b.mp4") - ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4") + nt=base64.b16encode(title.encode('utf-8')) + if len(nt)>200: + nt=nt[:180] + ptadd=os.path.join(os.path.dirname(padd),nt+ext) + ptoutb=os.path.join(os.path.dirname(pout),nt+"_b.mp4") + ptout=os.path.join(os.path.dirname(pout),nt+".mp4") shutil.move(padd,ptadd) if os.path.isfile(pout): shutil.move(pout,ptoutb) @@ -265,7 +193,8 @@ def addmp4(padd,pout,cmd):#without video txt= "error occures in addmp4\n" txt=txt+ str(type(inst))+"\n" txt=txt+str(inst) - recdblist.addlog(pout, txt, "MP4Box-log-add") + recdblist.addlog(pout, cmdn, u"MP4Box追加ログ-コマンド") + recdblist.addlog(pout, txt, u"MP4Box追加ログ-詳細") time.sleep(5) os.remove(ptoutb) shutil.move(ptadd,padd) @@ -279,31 +208,4 @@ def execcomd(cmd): txt=txt+unicode(txt2,"utf-8")+"\n" except: "" - return txt - -def deltitle(path,title): - dp=[] - dp.append(os.path.join(path,title+".avi")) - dp.append(os.path.join(path,title+".264")) - dp.append(os.path.join(path,title+".120.avi")) - dp.append(os.path.join(path,title+".noodml.avi")) - dp.append(os.path.join(path,title+".aac")) - dp.append(os.path.join(path,title+".m2v")) - dp.append(os.path.join(path,title+"_1.aac")) - dp.append(os.path.join(path,title+"_2.aac")) - dp.append(os.path.join(path,title+"_1.mp3")) - dp.append(os.path.join(path,title+"_2.mp3")) - dp.append(os.path.join(path,title+".srt")) - if configreader.getenv("remove_ts")=="1": - dp.append(os.path.join(path,title+".ts")) - if os.path.exists(os.path.join(path,title+".ts"))and os.path.exists(os.path.join(path,title+".ts.b25")): - if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")): - if os.path.getsize(os.path.join(path,title+".ts"))>1000*1000*100: - dp.append(os.path.join(path,title+".ts.b25")) - if os.path.exists(os.path.join(path,title+".mp4")): - if os.path.getsize(os.path.join(path,title+".mp4"))>1000*1000*10: - for ip in dp: - try: - os.remove(ip) - except: - "" + return txt \ No newline at end of file