OSDN Git Service

implement new mp4 encoding(beta).
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Thu, 4 Mar 2010 01:29:49 +0000 (01:29 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Thu, 4 Mar 2010 01:29:49 +0000 (01:29 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@452 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/timerec.py
rec10/trunk/src/tv2mp4.py

index 265cf24..1ef4cee 100644 (file)
@@ -531,9 +531,23 @@ def type_encode_que(typetxt,chtxt,title,bt,et,opt):
                     if not os.path.exists(paac2) and not os.path.exists(pmp32):
                         tv2avi.pentaaudio2sep(os.path.join(recpath, title+".ts"))
                 time.sleep(3)
-            pout = recpath + "/" + title + ".mkv"
+            makeMP4=0
+            try:
+                if configreader.getenv("make_mp4")==1:
+                    makeMP4=1
+            except:
+                ""
+            if re.search("m", opt):
+                makeMP4=0
+            if re.search("4", opt):
+                makeMP4=1
             recdblist.printutf8(pin)
-            tv2mkv.ts2mkv(pin, pout, opt)
+            if makeMP4==1:
+                pout = recpath + "/" + title + ".mp4"
+                tv2mp4.ts2mp4(pin, pout, opt)
+            else:
+                pout = recpath + "/" + title + ".mkv"
+                tv2mkv.ts2mkv(pin, pout, opt)
             recdb.del_reckey(typetxting, title, chtxt, btime)
             time.sleep(10)
             if re.search("E", opt):
index b9e705c..641b352 100644 (file)
@@ -13,18 +13,24 @@ import base64
 import time\r
 import recdblist\r
 import configreader\r
+import status\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
+    """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
+    avi2mp4(tpavi,pout,opt)"""\r
+    tpraw=os.path.join(dir, title+".264")\r
+    tpmp4=os.path.join(dir, title+".mp4")\r
+    tv2avi.ts2raw(pin, tpraw, opt)\r
+    time.sleep(10)\r
+    raw2mp4(tpraw, tpmp4, opt)\r
 def raw2mp4(pin,pout,opt):\r
     dir=os.path.split(pout)[0]\r
     title=os.path.split(pout)[1]\r
@@ -58,15 +64,15 @@ def raw2mp4(pin,pout,opt):
         if not os.path.exists(paac2):\r
             paac2=pin.replace(".264","_2.mp3")\r
         e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""\r
-        e1=exe +u" "+duration+" -add \""+pin+" -new \""+pout+"\""\r
-        e1a1=exe +u" -add \""+paac1+" \""+pout+"\""\r
-        e1a2=exe +u" -add \""+paac2+" \""+pout+"\""\r
-        e1s=exe +u" -add \""+pincap+" \""+pout+"\""\r
+        e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""\r
+        e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\""\r
+        e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\""\r
+        e1s=exe +u" -add \""+pincap+"\" \""+pout+"\""\r
+        if os.path.isfile(cap2ass):\r
+            txt=txt+execcomd(e0)\r
         execmp4box(pin, pout, e1)\r
         addmp4(paac1, pout, e1a1)\r
         addmp4(paac2, pout, e1a2)\r
-        if os.path.isfile(cap2ass):\r
-            txt=txt+execcomd(e0)\r
         if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):\r
             addmp4(pincap, pout, e1s)\r
     elif ispentaaudio==1:\r
@@ -82,15 +88,15 @@ def raw2mp4(pin,pout,opt):
         if not os.path.exists(paac2):\r
             paac2=pin.replace(".264","_2.mp3")\r
         e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""\r
-        e1=exe +u" "+duration+" -add \""+pin+" -new \""+pout+"\""\r
-        e1a1=exe +u" -add \""+paac1+" \""+pout+"\""\r
-        e1a2=exe +u" -add \""+paac2+" \""+pout+"\""\r
-        e1s=exe +u" -add \""+pincap+" \""+pout+"\""\r
+        e1=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""\r
+        e1a1=exe +u" -add \""+paac1+"\" \""+pout+"\""\r
+        e1a2=exe +u" -add \""+paac2+"\" \""+pout+"\""\r
+        e1s=exe +u" -add \""+pincap+"\" \""+pout+"\""\r
+        if os.path.isfile(cap2ass):\r
+            txt=txt+execcomd(e0)\r
         execmp4box(pin, pout, e1)\r
         addmp4(paac1, pout, e1a1)\r
         addmp4(paac2, pout, e1a2)\r
-        if os.path.isfile(cap2ass):\r
-            txt=txt+execcomd(e0)\r
         if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):\r
             addmp4(pincap, pout, e1s)\r
     else:\r
@@ -101,14 +107,14 @@ def raw2mp4(pin,pout,opt):
         pinaac=pin.replace(".264",".aac")\r
         e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""\r
         e1="ffmpeg -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\""\r
-        e2=exe +u" "+duration+" -add \""+pin+" -new \""+pout+"\""\r
-        e2a=exe +u" -add \""+pinaac+" \""+pout+"\""\r
-        e2s=exe +u" -add \""+pincap+" \""+pout+"\""\r
-        execmp4box(pin, pout, e2)\r
-        addmp4(pinaac, pout, e2a)\r
-        addmp4(pincap, pout, e2s)\r
+        e2=exe +u" "+duration+" -add \""+pin+"\" -new \""+pout+"\""\r
+        e2a=exe +u" -add \""+pinaac+"\" \""+pout+"\""\r
+        e2s=exe +u" -add \""+pincap+"\" \""+pout+"\""\r
         if os.path.isfile(cap2ass):\r
             txt=txt+execcomd(e0)\r
+        txt=txt+execcomd(e1)\r
+        execmp4box(pin, pout, e2)\r
+        addmp4(pinaac, pout, e2a)\r
         if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):\r
             addmp4(pincap, pout, e2s)\r
     recdblist.addlog(pout, txt, "mp4box-log")\r
@@ -310,11 +316,15 @@ def mkv2mp4(pin,pout):
         if os.path.exists(tmpmp4):\r
             os.remove(tmpmp4)\r
 def execmp4box(pin,pout,cmd):\r
-    ptin=os.path.join(os.path.dirname(pin),base64.b32encode(os.path.splitext(os.path.split(pin)[1])[0])+".264")\r
+    title=os.path.splitext(os.path.split(pin)[1])[0]\r
+    ptin=os.path.join(os.path.dirname(pin),base64.b16encode(title.encode('utf-8'))+".264")\r
+    recdblist.printutf8(ptin)\r
     shutil.move(pin,ptin)\r
-    ptout=os.path.join(os.path.dirname(pout),base64.b32encode(os.path.splitext(os.path.split(pout)[1])[0])+".mp4")\r
+    time.sleep(10)\r
+    ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")\r
     cmdn=string.replace(cmd,pin,ptin)\r
     cmdn=string.replace(cmdn,pout,ptout)\r
+    recdblist.printutf8(cmdn)\r
     txt=""\r
     try:\r
         txt=execcomd(cmdn)\r
@@ -323,14 +333,25 @@ def execmp4box(pin,pout,cmd):
         txt=txt+ str(type(inst))+"\n"\r
         txt=txt+str(inst)\r
     recdblist.addlog(pin, txt, "MP4Box-log")\r
-    time.sleep(3)\r
+    time.sleep(5)\r
+    shutil.move(ptin,pin)\r
     shutil.move(ptout,pout)\r
+    time.sleep(5)\r
 def addmp4(padd,pout,cmd):#without video\r
-    ptadd=os.path.join(os.path.dirname(padd),base64.b32encode(os.path.splitext(os.path.split(padd)[1])[0])+"."+os.path.splitext(os.path.split(padd)[1])[1])\r
+    title=os.path.splitext(os.path.split(padd)[1])[0]\r
+    ext=os.path.splitext(os.path.split(padd)[1])[1]\r
+    ptadd=os.path.join(os.path.dirname(padd),base64.b16encode(title.encode('utf-8'))+ext)\r
+    ptoutb=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+"_b.mp4")\r
+    ptout=os.path.join(os.path.dirname(pout),base64.b16encode(title.encode('utf-8'))+".mp4")\r
     shutil.move(padd,ptadd)\r
-    ptout=os.path.join(os.path.dirname(pout),base64.b32encode(os.path.splitext(os.path.split(pout)[1])[0])+".mp4")\r
+    if os.path.isfile(pout):\r
+        shutil.move(pout,ptoutb)\r
+    time.sleep(5)\r
     cmdn=string.replace(cmd,padd,ptadd)\r
+    cmdn=string.replace(cmdn,u"-out \""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)\r
+    cmdn=string.replace(cmdn,u"\""+pout,u"-add \""+ptoutb+"\" -new \""+ptout)\r
     cmdn=string.replace(cmdn,pout,ptout)\r
+    recdblist.printutf8(cmdn)\r
     txt=""\r
     try:\r
         txt=execcomd(cmdn)\r
@@ -338,9 +359,12 @@ def addmp4(padd,pout,cmd):#without video
         txt= "error occures in addmp4\n"\r
         txt=txt+ str(type(inst))+"\n"\r
         txt=txt+str(inst)\r
-    recdblist.addlog(pin, txt, "MP4Box-log-add")\r
-    time.sleep(3)\r
+    recdblist.addlog(pout, txt, "MP4Box-log-add")\r
+    time.sleep(5)\r
+    os.remove(ptoutb)\r
+    shutil.move(ptadd,padd)\r
     shutil.move(ptout,pout)\r
+    time.sleep(5)\r
 def execcomd(cmd):\r
     txt=""\r
     try:\r