X-Git-Url: http://git.osdn.net/view?p=rec10%2Frec10-git.git;a=blobdiff_plain;f=rec10%2Ftrunk%2Fsrc%2Ftv2mp4.py;h=1facd363cd35d1b4007677358d92ea7ef1a2c1c6;hp=f46dce27fe1c394d1c1b0f7ddcc2ddc54ddab8c0;hb=4d7f1c26fcb69acdc8387679d87474a018e0f403;hpb=0f5605ea2eb1ca103e28bd11aa01b8fde6433ead diff --git a/rec10/trunk/src/tv2mp4.py b/rec10/trunk/src/tv2mp4.py index f46dce2..1facd36 100644 --- a/rec10/trunk/src/tv2mp4.py +++ b/rec10/trunk/src/tv2mp4.py @@ -1,7 +1,7 @@ #!/usr/bin/python # coding: UTF-8 # Rec10 TS Recording Tools -# Copyright (C) 2009-2010 Yukikaze +# Copyright (C) 2009-2011 Yukikaze import commands import shutil import auto_process @@ -13,13 +13,19 @@ import base64 import time import subprocess import traceback +import zip import tv2avi import recdblist import configreader import status import tv2audio - +path = str(os.path.dirname(os.path.abspath(__file__))) + "/" +tmppath = configreader.getConfPath("tmp")+"/" +if tmppath=="/": + tmppath=path +if not os.path.exists(tmppath): + os.mkdir(tmppath) def ts2mp4(pin, pout, opt): dir=os.path.split(pout)[0] title=os.path.split(pout)[1] @@ -32,8 +38,11 @@ def ts2mp4(pin, pout, opt): if os.path.isfile(tpraw) and os.path.getsize(tpraw)>10*1000: raw2mp4(tpraw, tpmp4, opt) time.sleep(10) - if os.path.exists(tpraw): + if os.path.exists(tpraw) and not re.search("B",opt): os.remove(tpraw) + zip.addFile2FileZip(recdblist.getLogTitle(pin)+".command.log", recdblist.getLogTitle(pin)+".log.zip") + if os.path.exists(recdblist.getLogTitle(pin)+".command.log"): + os.remove(recdblist.getLogTitle(pin)+".command.log") def raw2mp4(pin,pout,opt): dir=os.path.split(pout)[0] title=os.path.split(pout)[1] @@ -41,15 +50,9 @@ def raw2mp4(pin,pout,opt): duration="-fps 29.970030 " if re.search("a",opt): duration="-fps 23.976023 " - elif re.search("v",opt): - duration="-fps 23.976023 " - if re.search("d",opt): - duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置 - elif re.search("5",opt): - duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置 if re.search("I",opt): duration="-fps 29.970030 " - exe = configreader.getpath("mp4box") + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath txt="" os.environ['LANG']="ja_JP.UTF-8" pints=pin.replace(".264",".ts") @@ -57,21 +60,19 @@ def raw2mp4(pin,pout,opt): 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"): - auto_process.deltmpfile(dir, title, ".mp4") - elif re.search(opt,"8") or re.search(opt,"9"): - "" + if re.search("t",opt): + auto_process.deleteTmpFile(dir, title, ".264") + elif re.search("k",opt): + ""#削除しない else: - auto_process.deltmpfile(dir, title, ".mp4") + auto_process.deleteTmpFile(dir, title, ".mp4") def mkv2mp4(pin,pout): - exeb = configreader.getpath(u"mkvextract") - exe = configreader.getpath(u"mp4Box") - #dtsedit=configreader.getpath("DtsEdit") - wineexe=configreader.getpath("wine") + exeb = configreader.getConfPath(u"mkvextract") + exe = configreader.getConfPath(u"mp4Box") + #dtsedit=configreader.getConfPath("DtsEdit") + wineexe=configreader.getConfPath("wine") dir=os.path.split(pin)[0] title=os.path.split(pin)[1] title=os.path.splitext(title)[0] @@ -93,17 +94,17 @@ def mkv2mp4(pin,pout): txt=txt+execcomd(exe3)+"\n" except: "" - recdblist.addlog(pin, txt, u"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): - auto_process.deltmpfile(dir, title, ".mp4") + auto_process.deleteTmpFile(dir, title, ".mp4") def addCaption(pts,pmp4):##字幕の追加を試みる。 - wineexe=configreader.getpath("wine") + wineexe=configreader.getConfPath("wine") pincap=pts.replace(".ts",".srt") try: - cap2ass=configreader.getpath("caption2ass") + cap2ass=configreader.getConfPath("caption2ass") except: cap2ass="" if os.path.isfile(cap2ass): @@ -117,15 +118,16 @@ def addCaption(pts,pmp4):##字幕の追加を試みる。 #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ログ-詳細") + recdblist.addLog(pts,e0, u"Captionログ-コマンド") + recdblist.addLog(pts,logt, u"Captionログ-詳細") + recdblist.addCommandLogZip(pts, "mp4box_caption", "mp4box_caption", e0, logt) if os.path.exists(pincap): if os.path.getsize(pincap)>1000: - exe = configreader.getpath("mp4box") + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath e1s=exe +u" -add \""+pincap+"\" \""+pmp4+"\"" addmp4(pincap,pmp4,e1s) def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う - exe = configreader.getpath("mp4box") + exe = configreader.getConfPath("mp4box")+u" -tmp "+tmppath if re.search("d",opts) or re.search("5",opts):#二カ国語放送/5.1ch放送の場合 paac1=pts.replace(".ts","_1.aac") paac2=pts.replace(".ts","_2.aac") @@ -140,6 +142,13 @@ def addAudio(pts,pmp4,opts):#オプションに応じた音声の追加を行う addmp4(paac1, pmp4, e1a1) if os.path.exists(paac2): addmp4(paac2, pmp4, e1a2) + elif re.search("b",opts):#BonTsDemuxを使って音声をスプリットした場合 + paac=pts.replace(".ts",".aac") + if not os.path.exists(paac): + paac=pts.replace(".ts",".mp3") + e1a1=exe +u" -add \""+paac+"\" \""+pmp4+"\"" + if os.path.exists(paac): + addmp4(paac, pmp4, e1a1) else: tv2audio.ts2single_audio(pts,opts) pinaac=pts.replace(".ts",".aac") @@ -161,6 +170,7 @@ def execmp4box(pin,pout,cmd): cmdn=string.replace(cmd,pin,ptin) cmdn=string.replace(cmdn,pout,ptout) recdblist.printutf8(cmdn) + recdblist.addCommandSelfLog(pin, cmdn) txt="" try: txt=execcomd(cmdn) @@ -168,9 +178,10 @@ def execmp4box(pin,pout,cmd): txt= "error occures in execmp4box\n" txt=txt+ str(type(inst))+"\n" txt=txt+str(inst) - recdblist.Commonlogex("Error", "excecmp4box(tv2mp4.py)", str(type(inst)), str(inst)+traceback.format_exc(),verbose_level=200,log_level=200) - recdblist.addlog(pin, cmdn, u"MP4Boxログ-コマンド") - recdblist.addlog(pin, txt, u"MP4Boxログ-詳細") + recdblist.addCommonlogEX("Error", "excecmp4box(tv2mp4.py)", str(type(inst)), str(inst)+traceback.format_exc(),verbose_level=200,log_level=200) + recdblist.addLog(pin, cmdn, u"MP4Boxログ-コマンド") + recdblist.addLog(pin, txt, u"MP4Boxログ-詳細") + recdblist.addCommandLogZip(pin, "MP4Box", "mp4box", cmdn,txt) time.sleep(5) shutil.move(ptin,pin) shutil.move(ptout,pout) @@ -200,8 +211,9 @@ 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, cmdn, u"MP4Box追加ログ-コマンド") - recdblist.addlog(pout, txt, u"MP4Box追加ログ-詳細") + recdblist.addLog(pout, cmdn, u"MP4Box追加ログ-コマンド") + recdblist.addLog(pout, txt, u"MP4Box追加ログ-詳細") + recdblist.addCommandLogZip(pout, "MP4Box_add", "mp4box_add", cmdn, txt) time.sleep(5) shutil.move(ptadd,padd) if os.path.exists(ptout): @@ -209,7 +221,7 @@ def addmp4(padd,pout,cmd):#without video os.remove(ptoutb) else: txtt=padd+u"のインポートエラー" - recdblist.addlog(pout, txtt, u"MP4Box追加ログ-コマンド") + recdblist.addLog(pout, txtt, u"MP4Box追加ログ-コマンド") shutil.move(ptoutb,pout) time.sleep(5) def execcomd(cmd): @@ -220,4 +232,4 @@ def execcomd(cmd): txt=txt+unicode(txt2,"utf-8")+"\n" except: "" - return txt \ No newline at end of file + return txt