OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / rec10 / trunk / src / tv2avi.py
index 6fe16f6..f441bee 100644 (file)
@@ -1,29 +1,36 @@
 #!/usr/bin/python
 # coding: UTF-8
 # Rec10 TS Recording Tools
-# Copyright (C) 2009 Yukikaze
-import status
+# Copyright (C) 2009-2011 Yukikaze
+import commands
+import datetime
+import os
+import re
 import shutil
 import time
+import os.path
+import traceback
+
 import chdb
 import configreader
-import datetime
-import os
-import re
+import status
 import ts2x264
-import ts2xvid
 import tv2ts
-import recdb
-import commands
+import recdblist
+import tv2audio
+
+
+global Bitrate_SD
 global Bitrate_HD
 global Bitrate_FHD
-global Bitrate_SD
-global Bitrate_WQVGA
-Bitrate_HD="2000"
-Bitrate_FHD="2500"
-Bitrate_SD="1250"
-Bitrate_WQVGA="200"
-def timetv2b25(pout, chtxt, btime, etime,opt):
+global Bitrate_Short
+global Bitrate_LowHD
+Bitrate_SD = 1250
+Bitrate_HD = 3750
+Bitrate_LowHD = 2500
+Bitrate_FHD = 5000
+Bitrate_Short = 1250
+def timetv2b25(pout, chtxt, btime, etime, opt):
     """
     poutはタイトル
     """
@@ -33,284 +40,72 @@ 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):
+    tv2ts.tv2b25ts(tsout + ".ts.b25", chdb.searchCHFromChtxt(chtxt)['ch'], rectime,chdb.searchCHFromChtxt(chtxt)['tsid'])
+def b252ts(pout, chtxt, btime, etime, opt):
     """
     poutはタイトル(自動的にtitle.b25 title.tsと名前がつきます。)
     """
-    status.setB25Decoding(status.getB25Decoding()+1)
+    #status.setB25Decoding(status.getB25Decoding() + 1)
+    status.changeB25Decoding(1)
     try:
-        tv2ts.b252ts(pout+".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'])
-        tsout=pout
+        try:
+            chs=chdb.searchCHFromChtxt(chtxt)
+            ch=chs['ch']
+            csch=chs['csch']
+            #print [ch,csch,chtxt]
+        except:
+            ch="0"
+            csch="0"
+        tv2ts.b252ts(pout + ".ts", ch, csch)
+        tsout = pout
         aviin = pout + ".ts"
         dualaudio = 0
         pentaaudio = 0
-        if re.search("5",opt):
+        singleaudiosplit = 0
+        if re.search("5", opt):
             pentaaudio = 1
-        if re.search("d",opt):
+        if re.search("d", opt):
             dualaudio = 1
-        if re.search("\[二\]", pout):
+        if re.search("b", opt):
+            singleaudiosplit = 1
+        if re.search(u"\[二\]", pout):
             dualaudio = 1
-        elif re.search('(二)', pout):
+        elif re.search(u'(二)', pout):
             dualaudio = 1
-        elif re.search('\(二\)', pout):
+        elif re.search(u'\(二\)', pout):
             dualaudio = 1
-        if opt=="":
-            opts=""
-            if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-                opts=opts+"S2"
-                if chtxt == "disch":
-                    ""
-                elif chtxt == "hisch":
-                    ""
-                else:
-                    opts=opts+"a"
-            else:
-                opts=opts+"Ha2"
-        else:
-            opts=opt
         if dualaudio == 1:
-            dualaudiots2avi(aviin, tsout + "sa.avi")
-            aviin = tsout + "sa.avi"
-        if pentaaudio ==1:
-            dualaudiots2avi(aviin, tsout + "sa.avi")
-            aviin = tsout + "sa.avi"
-    except:
-        ""
-    status.setB25Decoding(status.getB25Decoding()-1)
-def timetv2avi(pout, chtxt, btime, etime,opt):
-    bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
-    et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    tnow = datetime.datetime.now()
-    wt = bt-tnow
-    waitt = wt.seconds-5
-    time.sleep(waitt)
-    tnow = datetime.datetime.now()
-    dt = et-tnow
-    rectime = dt.seconds-10
-    rectime = str(rectime)
-    #print tsout+".ts,"+chdb.chtxtsearch(chtxt)['ch']+","+chdb.chtxtsearch(chtxt)['csch']+","+rectime
-    tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], rectime)
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    pentaaudio = 0
-    if re.search("5",opt):
-        pentaaudio = 1
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search("\[二\]", pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    if opt=="":
-        opts=""
-        if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-            opts=opts+"S2"
-            if chtxt == "disch":
-                ""
-            elif chtxt == "hisch":
-                ""
-            else:
-                opts=opts+"a"
-        else:
-            opts=opts+"Ha2"
-    else:
-        opts=opt
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if pentaaudio ==1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-def ts2avi(pin,pout,opt):
-    status.setEncoding(status.getEncoding()+1)
-    if re.search("x",opt):
-        try:
-            ts2xvid.ts2xvid(pin, pout, opt)
-        except:
-            ""
-    else:
-        try:
-            ts2x264.ts2x264(pin, pout, opt)
-        except:
-            ""
-    status.setEncoding(status.getEncoding()-1)
-def tv2avi(pout, chtxt, btime, etime,opt):
-    bt = datetime.datetime.strptime(btime, "%Y-%m-%d %H:%M:%S")
-    et = datetime.datetime.strptime(etime, "%Y-%m-%d %H:%M:%S")
-    dt = et-bt
-    time = dt.seconds-10
-    time = str(time)
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    tv2ts.tv2ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'], time)
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    pentaaudio = 0 
-    if re.search("5",opt):
-        pentaaudio = 1
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search('\[二\]', pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    opts=""
-    if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-        opts=opts+"S2"
-        if chtxt == "disch":
-            ""
-        elif chtxt == "hisch":
-            ""
-        else:
-            opts=opts+"a"
-    else:
-        opts=opts+"Ha2"
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if pentaaudio ==1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    ts2x264.ts2x264(aviin, pout,opts)
-    #os.remove(aviin)
-def b252avi(pout, chtxt,opt):
-    extt = os.path.splitext(pout)
-    tsout = extt[0]
-    tv2ts.b252ts(tsout + ".ts", chdb.chtxtsearch(chtxt)['ch'], chdb.chtxtsearch(chtxt)['csch'])
-    aviin = tsout + ".ts"
-    dualaudio = 0
-    pentaaudio = 0
-    if re.search("5",opt):
-        pentaaudio = 1
-    if re.search("d",opt):
-        dualaudio = 1
-    if re.search('\[二\]', pout):
-        dualaudio = 1
-    elif re.search('(二)', pout):
-        dualaudio = 1
-    elif re.search('\(二\)', pout):
-        dualaudio = 1
-    if opt=="":
-        opts=""
-        if chdb.chtxtsearch(chtxt)['bctype'] == 'cs':
-            opts=opts+"S2"
-            if chtxt == "disch":
-                ""
-            elif chtxt == "hisch":
-                ""
-            else:
-                opts=opts+"a"
-        else:
-            opts=opts+"Ha2"
-    else:
-        opts=opt
-    if re.search("x",opt):
-        makexvid = 0
-    else:
-        makexvid = 1
-    if dualaudio == 1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if pentaaudio ==1:
-        dualaudiots2avi(aviin, tsout + "sa.avi")
-        aviin = tsout + "sa.avi"
-    if makexvid==1:
-        ts2xvid.ts2xvid(aviin, pout,opts)
-    else:
-        ts2x264.ts2x264(aviin, pout,opts)
-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')
-    exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 0 -o \"" + bonpout + "\" -start -quit"
-    #print exe
-    exe = xvfb+' -a ' + exe
-    print exe
-    os.system(exe)
-    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 + "\'"
-    #print exe
-    #commands.getoutput(exe)
-    os.system(exe)
-    os.remove(ffpin1)
-    os.remove(ffpin2)
-def dualaudio2sep(pin,pout,delay):
-    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"
-    #print exe
-    exe = xvfb+' -a ' + exe
-    #exe = 'xvfb-run -a -e xvfberror.txt ' + exe
-    #exe='export Display=:2&&'+exe
-    print exe
-    commands.getoutput(exe)
-    #os.system(exe)
-    ffpin=pin.replace(".ts","")
-    ffpin1 = pin.replace("ts", "wav")
-    ffpin2 = pin.replace("ts", "m2v")
-    ffpout1=ffpin+"1_delay"+delay+".wav"
-    ffpout2=ffpin+"2_delay"+delay+".wav"
-    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
-    print exe
-    commands.getoutput(exe)
-    #os.system(exe)
-    shutil.move(ffpin1, ffpout2)
-    ffpout21=ffpout1.replace(".wav",".ogg")
-    ffpout22=ffpout2.replace(".wav",".ogg")
-    aexe1="ffmpeg -i "+ffpout1+" -vn -acodec vorbis -ar 48000 -ab 128k "+ffpout21
-    aexe2="ffmpeg -i "+ffpout2+" -vn -acodec vorbis -ar 48000 -ab 128k "+ffpout22
-    #os.system(aexe1)
-    #os.system(aexe2)
-    commands.getoutput(aexe1)
-    commands.getoutput(aexe2)
-    #exe = "ffmpeg -y  -i \'" + ffpin1 + "\' -i \'" + ffpin2 + "\' -r 29.97 -vsync 200 -vcodec copy -acodec libmp3lame -async 200 -ab 128k -f avi  \'" + pout + "\'"
-    #print exe
-    
-    #os.remove(ffpin1)
-    #os.remove(ffpin2)
-
-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"
-    #print exe
-    exe = xvfb+' -a ' + exe
-    #exe = 'xvfb-run -a ' + exe
-    #exe='export Display=:2&&'+exe
-    print exe
-    commands.getoutput(exe)
-    #os.system(exe)
-    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 + "\'"
-    print exe
-    commands.getoutput(exe)
-    #os.system(exe)
-    os.remove(ffpin1)
-    os.remove(ffpin2)
+            tv2audio.ts2dualaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)
+        if pentaaudio == 1:
+            tv2audio.ts2pentaaudio_BonTsDemux(aviin, recdblist.BONTSDEMUX_DELAY, opt)
+        if singleaudiosplit == 1:
+            tv2audio.ts2single_fp_BonTsDemux(aviin, opt)
+    except Exception, inst:
+        recdblist.addCommonlogEX("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:
+        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)