OSDN Git Service

fix mkv2mp4.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Tue, 22 Dec 2009 02:45:29 +0000 (02:45 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Tue, 22 Dec 2009 02:45:29 +0000 (02:45 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@341 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/tv2mp4.py

index 25c11bc..502786c 100644 (file)
-#!/usr/bin/python
-# coding: UTF-8
-# Rec10 TS Recording Tools
-# Copyright (C) 2009 Yukikaze
-import commands
-import shutil
-import tv2avi
-import os
-import re
-import os.path
-import base64
-import time
-import recdblist
-import configreader
-
-def ts2mp4(pin, pout, opt):
-    dir=os.path.split(pout)[0]
-    title=os.path.split(pout)[1]
-    title=os.path.splitext(title)[0]
-    tpavi=os.path.join(dir, title+".avi")
-    tv2avi.ts2avi(pin, tpavi, opt)
-    time.sleep(10)
-    if not os.path.exists(tpavi):
-        if os.path.exists(pin):
-            tpavi=pin
-    avi2mp4(tpavi,pout,opt)
-def avi2mp4(pin,pout,opt):
-    isvfr=0
-    if re.search(u"v", opt):
-        isvfr=1
-    exe = configreader.getpath(u"MP4Box")
-    dir=os.path.split(pin)[0]
-    title=os.path.split(pin)[1]
-    title=os.path.splitext(title)[0]
-    etitle=base64.b16encode(title.encode('utf-8'))
-    audiopath=os.path.join(dir,etitle+u"_audio.raw")
-    videopath=os.path.join(dir,etitle+u"_video.264")
-    exes=[]
-    os.environ['LANG']="ja_JP.UTF-8"
-    txt=""
-    if isvfr==1:
-        wineexe=configreader.getpath("wine")
-        cfr2tc=configreader.getpath("cfr2tc")
-        dtsedit=configreader.getpath("DtsEdit")
-        pin120=os.path.join(dir,etitle+u".120.avi")
-        pints=os.path.join(dir,title+u".ts")
-        pmp4=os.path.join(dir,etitle+u".tmp.mp4")
-        pintimecode=os.path.join(dir,etitle+u".timecode.txt")
-        pinaac=os.path.join(dir,etitle+u".aac")
-        evfr=[]
-        evfr.append("ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'")
-        evfr.append(wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2")
-        evfr.append(exe+u" -aviraw video \'"+pin120+u"\'")
-        videotpath=os.path.join(dir,etitle+u".120_video.h264")
-        evfr.append(exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'")
-        evfr.append(wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'")
-        exes=evfr
-        for e in exes:
-            recdblist.printutf8(e)
-            txt=txt+e+"\n"
-            try:
-                txt=txt+unicode(commands.getoutput(e.encode('utf-8')),'utf-8')
-            except:
-                ""
-        if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
-            txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
-            ptmp=pin.replace(".avi",".noodml.avi")
-            e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
-            ex="nice -n 17 "+e
-            e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
-            ex2="nice -n 17 "+e2
-            e3=exe+u" -aviraw video \'"+pin120+u"\'"
-            ex3="nice -n 17 "+e3
-            e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"
-            ex4="nice -n 17 "+e4
-            e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"
-            ex5="nice -n 17 "+e5
-            recdblist.printutf8(e)
-            txt=txt+e+"\n"
-            try:
-                cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')
-            except:
-                ""
-            try:
-                cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')
-            except:
-                ""
-            try:
-                cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')
-            except:
-                ""
-            try:
-                cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')
-            except:
-                ""
-            try:
-                cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')
-            except:
-                ""
-            try:
-                os.remove(ptmp)
-            except:
-                ""
-            txt=txt+cmdt+"\n"
-    else:
-        try:
-            shutil.move(pin,os.path.join(dir,etitle+".avi"))
-        except:
-            ""
-        e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"
-        e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"
-        os.system(e0)
-        os.system(e1)
-        if not os.path.exists(audiopath):
-            if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):
-                audiopath=os.path.join(dir,etitle+u"_audio.mp3")
-            elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):
-                audiopath=os.path.join(dir,etitle+u"_audio.aac")
-        else:
-            shutil.move(audiopath,os.path.join(dir,etitle+u"_audio.aac"))
-            audiopath=os.path.join(dir,etitle+u"_audio.aac")
-        ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))
-        e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"
-        os.system(e2)
-        shutil.move(ptmp,pout)
-    logo=pin.replace(u".avi",u".log")
-    txt = "\n####MP4Box-log####\n"+txt
-    f=open(logo,'a')
-    f.write(txt.encode('utf-8'))
-    f.close()
-    time.sleep(10)
-    delpath=[]
-    delpath.append(pin.replace(u".avi",u".120.avi"))
-    delpath.append(pin.replace(u".avi",u".sa.avi"))
-    delpath.append(pin.replace(u".avi",u".ts"))
-    delpath.append(pin.replace(u".avi",u".aac"))
-    delpath.append(pin.replace(u".avi",u".m2v"))
-    delpath.append(pin.replace(u".avi",u".120_video.264"))
-    delpath.append(pin.replace(u".avi",u".ts.b25"))
-    if os.path.exists(pout):
-        if os.path.exists(audiopath):
-            os.remove(audiopath)
-        if os.path.exists(videopath):
-            os.remove(videopath)
-        """
-        for dp in delpath:
-            try:
-                os.remove(dp)
-            except:
-                ""
-        """
-def mkv2mp4(pin,pout):
-    exeb = configreader.getpath(u"mkvextract")
-    exe = configreader.getpath(u"MP4Box")
-    dtsedit=configreader.getpath("DtsEdit")
-    wineexe=configreader.getpath("wine")
-    dir=os.path.split(pin)[0]
-    title=os.path.split(pin)[1]
-    title=os.path.splitext(title)[0]
-    etitle=base64.b16encode(title.encode('utf-8'))
-    audiopath=os.path.join(dir,etitle+u"_audio.aac")
-    videopath=os.path.join(dir,etitle+u"_video.264")
-    timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")
-    tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")
-    exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"
-    exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"
-    exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"
-    exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"
-    logo=pin.replace(".avi",".log")
-    os.environ['LANG']="ja_JP.UTF-8"
-    txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"
-    try:
-        txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')
-    except:
-        ""
-    try:
-        txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
-    except:
-        ""
-    try:
-        txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
-    except:
-        ""
-    try:
-        os.system(exe3.encode('utf-8'))
-    except:
-        ""
-    txt = "\n####MKV2MP4-log####\n"+txt
-    f=open(logo,'a')
-    f.write(txt.encode('utf-8'))
-    f.close()
-    time.sleep(10)
-    if os.path.exists(pout):
-        if os.path.exists(audiopath):
-            os.remove(audiopath)
-        if os.path.exists(videopath):
-            os.remove(videopath)
-        if os.path.exists(timecodepath):
-            os.remove(timecodepath)
-        if os.path.exists(tmpmp4):
-            os.remove(tmpmp4)
\ No newline at end of file
+#!/usr/bin/python\r
+# coding: UTF-8\r
+# Rec10 TS Recording Tools\r
+# Copyright (C) 2009 Yukikaze\r
+import commands\r
+import shutil\r
+import tv2avi\r
+import os\r
+import re\r
+import os.path\r
+import base64\r
+import time\r
+import recdblist\r
+import configreader\r
+\r
+def ts2mp4(pin, pout, opt):\r
+    dir=os.path.split(pout)[0]\r
+    title=os.path.split(pout)[1]\r
+    title=os.path.splitext(title)[0]\r
+    tpavi=os.path.join(dir, title+".avi")\r
+    tv2avi.ts2avi(pin, tpavi, opt)\r
+    time.sleep(10)\r
+    if not os.path.exists(tpavi):\r
+        if os.path.exists(pin):\r
+            tpavi=pin\r
+    avi2mp4(tpavi,pout,opt)\r
+def avi2mp4(pin,pout,opt):\r
+    isvfr=0\r
+    if re.search(u"v", opt):\r
+        isvfr=1\r
+    exe = configreader.getpath(u"MP4Box")\r
+    dir=os.path.split(pin)[0]\r
+    title=os.path.split(pin)[1]\r
+    title=os.path.splitext(title)[0]\r
+    etitle=base64.b16encode(title.encode('utf-8'))\r
+    audiopath=os.path.join(dir,etitle+u"_audio.raw")\r
+    videopath=os.path.join(dir,etitle+u"_video.264")\r
+    exes=[]\r
+    os.environ['LANG']="ja_JP.UTF-8"\r
+    txt=""\r
+    if isvfr==1:\r
+        wineexe=configreader.getpath("wine")\r
+        cfr2tc=configreader.getpath("cfr2tc")\r
+        dtsedit=configreader.getpath("DtsEdit")\r
+        pin120=os.path.join(dir,etitle+u".120.avi")\r
+        pints=os.path.join(dir,title+u".ts")\r
+        pmp4=os.path.join(dir,etitle+u".tmp.mp4")\r
+        pintimecode=os.path.join(dir,etitle+u".timecode.txt")\r
+        pinaac=os.path.join(dir,etitle+u".aac")\r
+        evfr0="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"\r
+        evfr1=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' 'Z:\\"+pintimecode+u"' 2"\r
+        evfr2=exe+u" -aviraw video \'"+pin120+u"\'"\r
+        videotpath=os.path.join(dir,etitle+u".120_video.h264")\r
+        evfr3=exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"\r
+        evfr4=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"\r
+        try:\r
+            recdblist.printutf8(evfr0)\r
+            txt=txt+evfr0+"\n"\r
+            txt=txt+unicode(commands.getoutput(evfr0.encode('utf-8')),'utf-8')\r
+        except:\r
+            ""\r
+        try:\r
+            recdblist.printutf8(evfr1)\r
+            txt=txt+evfr1+"\n"\r
+            txt=txt+unicode(commands.getoutput(evfr1.encode('utf-8')),'utf-8')\r
+        except:\r
+            ""\r
+        try:\r
+            if not os.path.exists(pin120):\r
+                evfr2=exe+u" -aviraw video \'"+pin+u"\'"\r
+                videotpath=os.path.join(dir,etitle+u"_video.h264")\r
+                evfr3=exe+u" -fps 29.970030 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"\r
+            recdblist.printutf8(evfr2)\r
+            txt=txt+evfr2+"\n"\r
+            txt=txt+unicode(commands.getoutput(evfr2.encode('utf-8')),'utf-8')\r
+        except:\r
+            ""\r
+        try:\r
+            recdblist.printutf8(evfr3)\r
+            txt=txt+evfr3+"\n"\r
+            txt=txt+unicode(commands.getoutput(evfr3.encode('utf-8')),'utf-8')\r
+        except:\r
+            ""\r
+        try:\r
+            recdblist.printutf8(evfr4)\r
+            txt=txt+evfr4+"\n"\r
+            txt=txt+unicode(commands.getoutput(evfr4.encode('utf-8')),'utf-8')\r
+        except:\r
+            ""\r
+        if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):\r
+            txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"\r
+            ptmp=pin.replace(".avi",".noodml.avi")\r
+            e="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"\r
+            ex="nice -n 17 "+e\r
+            e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"\r
+            ex2="nice -n 17 "+e2\r
+            e3=exe+u" -aviraw video \'"+pin120+u"\'"\r
+            ex3="nice -n 17 "+e3\r
+            e4=exe+u" -fps 29.97 -add \'"+videotpath+"\' -add \'"+pinaac+"\' -new \'"+pmp4+"\'"\r
+            ex4="nice -n 17 "+e4\r
+            e5=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+pintimecode+u"\' \'Z:\\"+pmp4+"\' -o \'Z:\\"+pout+"\'"\r
+            ex5="nice -n 17 "+e5\r
+            recdblist.printutf8(e)\r
+            txt=txt+e+"\n"\r
+            try:\r
+                cmdt=unicode(commands.getoutput(ex.encode('utf-8')),'utf-8')\r
+            except:\r
+                ""\r
+            try:\r
+                cmdt=unicode(commands.getoutput(ex2.encode('utf-8')),'utf-8')\r
+            except:\r
+                ""\r
+            try:\r
+                if os.path.exists(pin120):\r
+                    cmdt=unicode(commands.getoutput(ex3.encode('utf-8')),'utf-8')\r
+            except:\r
+                ""\r
+            try:\r
+                cmdt=unicode(commands.getoutput(ex4.encode('utf-8')),'utf-8')\r
+            except:\r
+                ""\r
+            try:\r
+                cmdt=unicode(commands.getoutput(ex5.encode('utf-8')),'utf-8')\r
+            except:\r
+                ""\r
+            try:\r
+                os.remove(ptmp)\r
+            except:\r
+                ""\r
+            txt=txt+cmdt+"\n"\r
+    else:\r
+        try:\r
+            shutil.move(pin,os.path.join(dir,etitle+".avi"))\r
+        except:\r
+            ""\r
+        if os.path.exists(os.path.join(dir,etitle+".avi")):\r
+            e0=exe+u" -aviraw audio \'"+os.path.join(dir,etitle+".avi")+u"\'"\r
+            e1=exe+u" -aviraw video \'"+os.path.join(dir,etitle+".avi")+u"\'"\r
+            os.system(e0)\r
+            os.system(e1)\r
+        if not os.path.exists(audiopath):\r
+            if os.path.exists(os.path.join(dir,etitle+u"_audio.mp3")):\r
+                audiopath=os.path.join(dir,etitle+u"_audio.mp3")\r
+            elif os.path.exists(os.path.join(dir,etitle+u"_audio.aac")):\r
+                audiopath=os.path.join(dir,etitle+u"_audio.aac")\r
+        else:\r
+            shutil.move(audiopath,os.path.join(dir,etitle+u"_audio.aac"))\r
+            audiopath=os.path.join(dir,etitle+u"_audio.aac")\r
+        ptmp=os.path.exists(os.path.join(dir,etitle+u".mp4"))\r
+        e2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+ptmp+u"\'"\r
+        os.system(e2)\r
+        shutil.move(ptmp,pout)\r
+    logo=pin.replace(u".avi",u".log")\r
+    txt = "\n####MP4Box-log####\n"+txt\r
+    f=open(logo,'a')\r
+    f.write(txt.encode('utf-8'))\r
+    f.close()\r
+    time.sleep(10)\r
+    delpath=[]\r
+    delpath.append(pin.replace(u".avi",u".120.avi"))\r
+    delpath.append(pin.replace(u".avi",u".sa.avi"))\r
+    delpath.append(pin.replace(u".avi",u".ts"))\r
+    delpath.append(pin.replace(u".avi",u".aac"))\r
+    delpath.append(pin.replace(u".avi",u".m2v"))\r
+    delpath.append(pin.replace(u".avi",u".120_video.264"))\r
+    delpath.append(pin.replace(u".avi",u".ts.b25"))\r
+    if os.path.exists(pout):\r
+        if os.path.exists(audiopath):\r
+            os.remove(audiopath)\r
+        if os.path.exists(videopath):\r
+            os.remove(videopath)\r
+        """\r
+        for dp in delpath:\r
+            try:\r
+                os.remove(dp)\r
+            except:\r
+                ""\r
+        """\r
+def mkv2mp4(pin,pout):\r
+    exeb = configreader.getpath(u"mkvextract")\r
+    exe = configreader.getpath(u"MP4Box")\r
+    dtsedit=configreader.getpath("DtsEdit")\r
+    wineexe=configreader.getpath("wine")\r
+    dir=os.path.split(pin)[0]\r
+    title=os.path.split(pin)[1]\r
+    title=os.path.splitext(title)[0]\r
+    etitle=base64.b16encode(title.encode('utf-8'))\r
+    audiopath=os.path.join(dir,etitle+u"_audio.aac")\r
+    videopath=os.path.join(dir,etitle+u"_video.264")\r
+    timecodepath=os.path.join(dir,etitle+u"_1_timecode.txt")\r
+    tmpmp4=os.path.join(dir,etitle+u".tmp.mp4")\r
+    exe0=exeb+u" tracks \'"+pin+u"\' 1:\'"+videopath+u"\' 2:\'"+audiopath+u"\'"\r
+    exe1=exeb+u" timecodes_v2 \'"+pin+"\' 1:\'"+timecodepath+"\'"\r
+    exe2=exe+u" -fps 29.970030 -add \'"+videopath+u"\' -add \'"+audiopath+u"\' -new \'"+tmpmp4+u"\'"\r
+    exe3=wineexe+u" "+dtsedit+u" -tc \'Z:\\"+timecodepath+u"\' \'Z:\\"+tmpmp4+u"\' -o \'Z:\\"+pout+u"\'"\r
+    logo=pin.replace(".avi",".log")\r
+    os.environ['LANG']="ja_JP.UTF-8"\r
+    txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exe3+"\n"\r
+    try:\r
+        txt = txt+unicode(commands.getoutput(exe0.encode('utf-8')),'utf-8')\r
+    except:\r
+        ""\r
+    try:\r
+        txt = txt+unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')\r
+    except:\r
+        ""\r
+    try:\r
+        txt = txt+unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')\r
+    except:\r
+        ""\r
+    try:\r
+        os.system(exe3.encode('utf-8'))\r
+    except:\r
+        ""\r
+    txt = "\n####MKV2MP4-log####\n"+txt\r
+    f=open(logo,'a')\r
+    f.write(txt.encode('utf-8'))\r
+    f.close()\r
+    time.sleep(10)\r
+    if os.path.exists(pout):\r
+        if os.path.exists(audiopath):\r
+            os.remove(audiopath)\r
+        if os.path.exists(videopath):\r
+            os.remove(videopath)\r
+        if os.path.exists(timecodepath):\r
+            os.remove(timecodepath)\r
+        if os.path.exists(tmpmp4):\r
+            os.remove(tmpmp4)\r