OSDN Git Service

implement to work "a bit after start resolution changing movie".
[rec10/rec10-git.git] / rec10 / trunk / src / tv2avi.py
index 3ae806f..f9481f1 100644 (file)
@@ -9,6 +9,7 @@ import re
 import shutil
 import time
 import os.path
+import traceback
 
 import chdb
 import configreader
@@ -39,11 +40,12 @@ def timetv2b25(pout, chtxt, btime, etime, opt):
     tsout = extt[0]
     tnow = datetime.datetime.now()
     wt = bt-tnow
-    waitt = wt.seconds-5
-    time.sleep(waitt)
+    waitt = wt.seconds
+    if waitt>0:
+        time.sleep(waitt)
     tnow = datetime.datetime.now()
     dt = et-tnow
-    rectime = dt.seconds-10
+    rectime = dt.seconds-5
     rectime = str(rectime)
     tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.chtxtsearch(chtxt)['ch'], rectime)
 def b252ts(pout, chtxt, btime, etime, opt):
@@ -53,11 +55,18 @@ def b252ts(pout, chtxt, btime, etime, opt):
     #status.setB25Decoding(status.getB25Decoding() + 1)
     status.changeB25Decoding(1)
     try:
-        tv2ts.b252ts(pout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'])
+        try:
+            ch=chtxt.split("_")[0]
+            csch=chtxt.split("_")[1]
+        except:
+            ch=0
+            csch=0
+        tv2ts.b252ts(pout + ".ts", ch, csch)
         tsout = pout
         aviin = pout + ".ts"
         dualaudio = 0
         pentaaudio = 0
+        singleaudiosplit = 0
         if re.search("5", opt):
             pentaaudio = 1
         if re.search("d", opt):
@@ -69,100 +78,28 @@ def b252ts(pout, chtxt, btime, etime, opt):
         elif re.search(u'\(二\)', pout):
             dualaudio = 1
         if dualaudio == 1:
-            dualaudio2sep(aviin,"167")
+            tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)
         if pentaaudio == 1:
-            pentaaudiots2avi(aviin, tsout + ".sa.avi")
+            tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)
     except Exception, inst:
-        print "Error happend in b252ts in tv2avi"
-        print type(inst)
-        print inst
+        recdblist.Commonlogex("Error", "b252ts(tv2avi.py)", str(type(inst))+traceback.format_exc(), str(inst))
     status.changeB25Decoding(-1)
 def ts2avi(pin, pout, opt):
     status.changeEncoding(1)
     try:
         ts2x264.ts2x264(pin, pout, opt)
     except Exception, inst:
-        print "error occures in tv2avi.py ts2avi"
-        print type(inst)
-        print inst
+        recdblist.printutf8("error occures in tv2avi.py ts2avi")
+        recdblist.printutf8(str(type(inst)))
+        recdblist.printutf8(str(inst)+traceback.format_exc())
+    status.changeEncoding(-1)
+def ts2raw(pin, pout, opt):
+    status.changeEncoding(1)
+    try:
+        ts2x264.ts2x264(pin, pout, opt)
+    except Exception, inst:
+        recdblist.printutf8("error occures in tv2avi.py ts2raw")
+        recdblist.printutf8(str(type(inst)))
+        recdblist.printutf8(str(inst)+traceback.format_exc())
     status.changeEncoding(-1)
-def dualaudiots2avi(pin, pout):
-    bontsdemux = configreader.getpath('bontsdemux')
-    bonpin = "Z:\\" + pin[1:]
-    outf = os.path.splitext(pin)[0]
-    bonpout = "Z:\\" + outf[1:]
-    xvfb = configreader.getpath('xvfb-run')
-    logpath=pin.replace("ts","log")
-    exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit"
-    #recdblist.printutf8(exe)
-    exe = xvfb + ' -a ' + exe
-    recdblist.printutf8(exe)
-    os.system(exe.encode('utf-8'))
-    ffpin1 = pin.replace("ts", "wav")
-    ffpin2 = pin.replace("ts", "m2v")
-    exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
-    recdblist.printutf8(exe)
-    #commands.getoutput(exe)
-    os.system(exe.encode('utf-8'))
-    os.remove(ffpin1)
-    os.remove(ffpin2)
-def dualaudio2sep(pin, delay):
-    """
-    delay is string
-    """
-    bontsdemux = configreader.getpath('bontsdemux')
-    wine = configreader.getpath('wine')
-    xvfb = configreader.getpath('xvfb-run')
-    bonpin = "Z:\\" + pin[1:]
-    outf = os.path.splitext(pin)[0]
-    bonpout = "Z:\\" + outf[1:]
-    exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\" -start -quit"
-    exe = xvfb + ' -a ' + exe
-    recdblist.printutf8(exe)
-    commands.getoutput(exe.encode('utf-8'))
-    ffpin = pin.replace(".ts", "")
-    ffpin1 = pin.replace("ts", "wav")
-    ffpin2 = pin.replace("ts", "m2v")
-    ffpout1 = ffpin + "_1.wav"
-    ffpout2 = ffpin + "_2.wav"
-    ffpout3 = ffpin + ".m2v"
-    shutil.move(ffpin1, ffpout1)
-    exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 2 -encode Demux\(wav\) -o \"" + bonpout + "\" -start -quit"
-    exe = xvfb + ' -a ' + exe
-    recdblist.printutf8(exe)
-    commands.getoutput(exe.encode('utf-8'))
-    #os.system(exe)
-    shutil.move(ffpin1, ffpout2)
-    shutil.move(ffpin2, ffpout3)
-    ffpout21=ffpout1.replace(".wav",".mp3")
-    ffpout22=ffpout2.replace(".wav",".mp3")
-    if configreader.getpath("useNeroAAC")=="1" and os.path.exists(configreader.getpath("NeroAAC")):
-        ffpout21=ffpout1.replace(".wav",".aac")
-        ffpout22=ffpout2.replace(".wav",".aac")
-        tv2audio.wav2aac_nero(ffpout1, ffpout21)
-        tv2audio.wav2aac_nero(ffpout2, ffpout22)
-    else:
-        tv2audio.wav2mp3_lame(ffpout1, ffpout21)
-        tv2audio.wav2mp3_lame(ffpout2, ffpout22)
-    time.sleep(3)
-    os.remove(ffpout1)
-    os.remove(ffpout2)
-
-def pentaaudiots2avi(pin, pout):
-    bontsdemux = configreader.getpath('bontsdemux')
-    bonpin = "Z:\\" + pin[1:]
-    xvfb = configreader.getpath('xvfb-run')
-    outf = os.path.splitext(pin)[0]
-    bonpout = "Z:\\" + outf[1:]
-    exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 3 -o \"" + bonpout + "\" -start -quit"
-    exe = xvfb + ' -a ' + exe
-    recdblist.printutf8(exe)
-    commands.getoutput(exe.encode('utf-8'))
-    ffpin1 = pin.replace("ts", "wav")
-    ffpin2 = pin.replace("ts", "m2v")
-    exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
-    recdblist.printutf8(exe)
-    commands.getoutput(exe.encode('utf-8'))
-    os.remove(ffpin1)
-    os.remove(ffpin2)