OSDN Git Service

implement neroaac encoding.
authorgn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Sun, 10 Jan 2010 05:41:33 +0000 (05:41 +0000)
committergn64_jp <gn64_jp@4e526526-5e11-4fc0-8910-f8fd03428081>
Sun, 10 Jan 2010 05:41:33 +0000 (05:41 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/rec10@390 4e526526-5e11-4fc0-8910-f8fd03428081

rec10/trunk/src/install.py
rec10/trunk/src/rec10.conf
rec10/trunk/src/timerec.py
rec10/trunk/src/ts2x264.py
rec10/trunk/src/tv2audio.py [new file with mode: 0644]
rec10/trunk/src/tv2avi.py
rec10/trunk/src/tv2mkv.py
rec10/trunk/src/tv2mp4.py

index 4241b4f..718685d 100644 (file)
@@ -78,7 +78,7 @@ def move():
     path = str(os.path.dirname(os.path.abspath(__file__)))
     recdblist.printutf8(u"rec10 ver 0.9.1 installer.")
     recdblist.printutf8(u"rec10のインストールを開始します。")
-    maxn=9
+    maxn=10
     configwriter.setpath(u"wine", getpath(u"wine"))
     configwriter.setpath(u"recpt1", getpath(u"recpt1"))
     #configwriter.setpath(u"xvfb-run", getpath(u"xvfb-run"))
@@ -114,8 +114,19 @@ def move():
     else:
         enc_max=str(int(enc_max))
     configwriter.setenv("enc_max", enc_max)
-    
-    recdblist.printutf8(u"チャンネルの設定に入ります(7/"+str(maxn)+")")
+
+    recdblist.printutf8(u"二カ国語放送/5.1ch放送の音声変換の設定です。\nNeroAACエンコーダーを使用しますか?(NeroAACEncを別途入手してtstoolsに入れてください。))")
+    recdblist.printutf8(u"入手先:http:\/\/www.nero.com\/jpn\/technologies-aac-codec.html\n (7/"+str(maxn)+")")
+    audioenc=raw_input("[y/N]:  ")
+    if audioenc=="y" or audioenc=="Y":
+        configwriter.setpath("useNeroAAC", "1")
+        recdblist.printutf8(u"NeroAACEncのパスを指定してください")
+        aacpath=raw_input("[/usr/local/bin/neroAacEnc] : ")
+        if aacpath.replace(" ","")!="":
+            configwriter.setpath("NeroAAC", aacpath)
+    recdblist.printutf8(u"lameを使用します。")
+
+    recdblist.printutf8(u"チャンネルの設定に入ります(8/"+str(maxn)+")")
     recdblist.printutf8(u"rec10を設置する地域を選んでください。")
     recdblist.printutf8(u"1:東京 2:神戸 3:名古屋 4:その他")
     ch=raw_input()
@@ -130,14 +141,14 @@ def move():
         recdblist.printutf8(u"チャンネルの設定が必要です。")
         recdblist.printutf8(u"chlist_sample_*を参考にchlist.xmlを作成した後に次のステップに進んでください。")
         time.sleep(5)
-    recdblist.printutf8(u"BS放送は受信可能ですか?(8/"+str(maxn)+")")
+    recdblist.printutf8(u"BS放送は受信可能ですか?(9/"+str(maxn)+")")
     bsok=raw_input("y/N:")
     if bsok=="Y" or bsok == "y" :
         bsok="1"
     else:
         bsok="0"
     configwriter.setenv("bs", bsok)
-    recdblist.printutf8(u"CS放送(スカパーe2)は受信可能ですか?(9/"+str(maxn)+")")
+    recdblist.printutf8(u"CS放送(スカパーe2)は受信可能ですか?(10/"+str(maxn)+")")
     csok=raw_input("y/N:")
     if csok=="Y" or csok == "y" :
         csok="1"
index 939cbb3..de8c38d 100644 (file)
@@ -33,6 +33,8 @@ b25 = /usr/local/bin/b25
 #b25_remoteを使う場合、下記の"192.168.0.1"および"/~~~/b25-client.so"を書き換えてください。
 #b25_env = "export B25_SERVER_IP=192.168.0.1 && export LD_PRELOAD=/~~~/b25-client.so"
 
+useNeroAAC = 0
+NeroAAC = /usr/local/bin/neroAacEnc
 [db]
 db = MySQL
 mysql_dbname=rec10
index 8d0508a..405fee5 100644 (file)
@@ -465,12 +465,7 @@ def type_decode_que(typetxt,chtxt,title,bt,et,opt):
                 etime = et.strftime("%Y-%m-%d %H:%M:%S")
                 recdb.rec_reckey(typetxtencque, title, chtxt, btime, etime, opt)
             else:
-                if opt.rfind("d")>=0:
-                    shutil.copy(os.path.join(recpath,title+".sa.avi"),os.path.join(movepath,title+".sa.avi"))
-                elif opt.rfind("5")>=0:
-                    shutil.copy(os.path.join(recpath,title+".sa.avi"),os.path.join(movepath,title+".sa.avi"))
-                else:
-                    shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts"))
+                shutil.copy(os.path.join(recpath,title+".ts"), os.path.join(movepath,title+".ts"))
                 recdb.rec_reckey(recdblist.REC_MOVE_END, title, chtxt, btime, etime, opt)
             if checker.checkB25Decode(recpath + "/" + title + ".ts.b25", recpath + "/" + title + ".ts") == 1:
                 os.remove(recpath + "/" + title + ".ts.b25")
@@ -500,9 +495,9 @@ def type_encode_que(typetxt,chtxt,title,bt,et,opt):
             recdblist.printutf8(opt)
             pin = recpath + "/" + title + ".ts"
             if re.search("d", opt):
-                pin = recpath + "/" + title + ".sa.avi"
+                pin = recpath + "/" + title + ".m2v"
                 if not os.path.exists(pin):
-                    tv2avi.dualaudiots2avi(os.path.join(recpath, title+".ts"), pin)
+                    tv2avi.dualaudio2sep(os.path.join(recpath, title+".ts"),"167")
                 time.sleep(3)
             if re.search("5", opt):
                 pin = recpath + "/" + title + ".sa.avi"
index 922265e..faa98cf 100644 (file)
@@ -32,7 +32,10 @@ def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
         isvfr=1
     if re.search("a", opts):
         is24fps=1
-    encode(pin, pout,size,isvfr,dualpass,is24fps)
+    if re.search("d",opt):
+        encode_ffmpeg(pin, pout, size, dualpass)
+    else:
+        encode(pin, pout,size,isvfr,dualpass,is24fps)
 def encode(pin,pout,size,isvfr,is2pass,is24fps):
     encvf=""
     txt=""
@@ -43,7 +46,7 @@ def encode(pin,pout,size,isvfr,is2pass,is24fps):
     bm=1
     scale=""
     x264enc1=":me=hex:bframes=3"
-    x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b"
+    x264enc2=":direct=auto:me=umh:bframes=3"
     crf=""
     if is24fps==1:
         ofps="-ofps 24000/1001"
@@ -52,7 +55,7 @@ def encode(pin,pout,size,isvfr,is2pass,is24fps):
         harddup=",pp=ac,pp=l5,hqdn3d=2:1:2,harddup"
         bm=1
         x264enc1=":me=hex:bframes=3"
-        x264enc2=":frameref=3:subq=7:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b"
+        x264enc2=x264enc2=":frameref=3:subq=7:subme=6:trellis=2:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b"
         harddup=""
     if isvfr==1:
         ofps="-ofps 60000/1001"
@@ -126,11 +129,13 @@ def encode_ffmpeg(pin,pout,size,is2pass):
     #ffmpeg -i input.m2v -vsync 400 -vcodec h264 -b bitrate k -s sizexsize -deinterlace -
     #x264enc1=":me=hex:bframes=3"
     #:frameref=3:subq=7:partitions=all:8x8dct:direct=auto:me=umh:bframes=3:weight_b
+    #directpred 3
     ffmpeg="ffmpeg"
     vf1="-me hex -bframes 3 "
     vf1="-ref 1 -subme 1 -me dia "
     #vf2="-ref 3 -subq 7 -partitions all -direct auto -me umh -level 42 -profile high -bframes 3 -flags2 8x8dct+bpyramid+wpred+mixed_refs+brdo "
-    vf2="-vpre hq "
+    #vf2="-vpre hq -refs 3 -subq 7 -partitions all -level 42 -me_method umh -bf 3 -flags2 dct8x8+bpyramid+wpred+mixed_refs "
+    vf2="-vpre hq -level 42 -me_method umh -bf 3 "
     if size == "HD":
         s = "-s 1280x720 "
         bitrate = str(tv2avi.Bitrate_HD)
diff --git a/rec10/trunk/src/tv2audio.py b/rec10/trunk/src/tv2audio.py
new file mode 100644 (file)
index 0000000..20418c4
--- /dev/null
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+# coding: UTF-8
+# Rec10 TS Recording Tools
+# Copyright (C) 2009-2010 Yukikaze
+import os
+def wav2aac_nero(pin,pout):
+    neroaac=configreader.getpath('NeroAAC')
+    exe=neroaac+" -br 128000 -2pass -if \""+pin+"\" -of \""+pout+"\""
+    os.system(exe)
+def wav2mp3_lame(pin,pout):
+    lame="lame"
+    exe=lame+" -b 128 \""+pin+"\" \""+pout+"\""
+    os.system(exe)
\ No newline at end of file
index 1155e6e..eb23485 100644 (file)
@@ -8,6 +8,7 @@ import os
 import re
 import shutil
 import time
+import os.path
 
 import chdb
 import configreader
@@ -15,6 +16,9 @@ import status
 import ts2x264
 import tv2ts
 import recdblist
+import tv2audio
+
+
 global Bitrate_SD
 global Bitrate_HD
 global Bitrate_FHD
@@ -68,15 +72,15 @@ def b252ts(pout, chtxt, btime, etime, opt):
         elif re.search(u'\(二\)', pout):
             dualaudio = 1
         if dualaudio == 1:
-            dualaudiots2avi(aviin, tsout + ".sa.avi")
+            dualaudio2sep(aviin,"167")
         if pentaaudio == 1:
-            dualaudiots2avi(aviin, tsout + ".sa.avi")
+            pentaaudiots2avi(aviin, tsout + ".sa.avi")
     except Exception, inst:
         print "Error happend in b252ts in tv2avi"
         print type(inst)
         print inst
     status.changeB25Decoding(-1)
-def timetv2avi(pout, chtxt, btime, etime, opt):
+"""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)
@@ -124,9 +128,9 @@ def timetv2avi(pout, chtxt, btime, etime, opt):
     if pentaaudio == 1:
         dualaudiots2avi(aviin, tsout + ".sa.avi")
         aviin = tsout + ".sa.avi"
+"""
 def ts2avi(pin, pout, opt):
     status.changeEncoding(1)
-    #status.setEncoding(status.getEncoding() + 1)
     try:
         ts2x264.ts2x264(pin, pout, opt)
     except Exception, inst:
@@ -134,8 +138,7 @@ def ts2avi(pin, pout, opt):
         print type(inst)
         print inst
     status.changeEncoding(-1)
-    #status.setEncoding(status.getEncoding()-1)
-def tv2avi(pout, chtxt, btime, etime, opt):
+"""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
@@ -176,7 +179,8 @@ def tv2avi(pout, chtxt, btime, etime, opt):
         aviin = tsout + ".sa.avi"
     ts2x264.ts2x264(aviin, pout, opts)
     #os.remove(aviin)
-def b252avi(pout, chtxt, opt):
+    """
+"""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'])
@@ -213,7 +217,7 @@ def b252avi(pout, chtxt, opt):
     if pentaaudio == 1:
         dualaudiots2avi(aviin, tsout + ".sa.avi")
         aviin = tsout + ".sa.avi"
-    ts2x264.ts2x264(aviin, pout, opts)
+    ts2x264.ts2x264(aviin, pout, opts)"""
 def dualaudiots2avi(pin, pout):
     bontsdemux = configreader.getpath('bontsdemux')
     bonpin = "Z:\\" + pin[1:]
@@ -234,7 +238,7 @@ def dualaudiots2avi(pin, pout):
     os.system(exe.encode('utf-8'))
     os.remove(ffpin1)
     os.remove(ffpin2)
-def dualaudio2sep(pin, pout, delay):
+def dualaudio2sep(pin, delay):
     """
     delay is string
     """
@@ -245,16 +249,15 @@ def dualaudio2sep(pin, pout, delay):
     outf = os.path.splitext(pin)[0]
     bonpout = "Z:\\" + outf[1:]
     exe = wine + ' ' + bontsdemux + " -i \"" + bonpin + "\" -delay " + delay + " -nd -sound 1 -o \"" + bonpout + "\" -start -quit"
-    #recdblist.printutf8(exe)
     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_delay" + delay + ".wav"
-    ffpout2 = ffpin + "2_delay" + delay + ".wav"
-    ffpout3 = ffpin + "_delay" + delay + ".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
@@ -263,20 +266,19 @@ def dualaudio2sep(pin, pout, delay):
     #os.system(exe)
     shutil.move(ffpin1, ffpout2)
     shutil.move(ffpin2, ffpout3)
-    #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
-    aexe = "ffmpeg -i \"" + ffpout3 + "\" -i \"" + ffpout1 + "\" -i \"" + ffpout2 + "\" -r 29.97 -vsync 200 -vcodec copy -acodec copy -f avi " + pout + " -acodec copy -newaudio"
-    recdblist.printutf8(aexe)
-    #os.system(aexe1)
-    #os.system(aexe2)
-    commands.getoutput(aexe.encode('utf-8'))
-    #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)
-    
-    #os.remove(ffpin1)
-    #os.remove(ffpin2)
+    ffpout21=ffpout1.replace(".wav",".mp3")
+    ffpout22=ffpout2.replace(".wav",".mp3")
+    if 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)
+
+    os.remove(ffout1)
+    os.remove(ffout2)
 
 def pentaaudiots2avi(pin, pout):
     bontsdemux = configreader.getpath('bontsdemux')
@@ -285,19 +287,14 @@ def pentaaudiots2avi(pin, pout):
     outf = os.path.splitext(pin)[0]
     bonpout = "Z:\\" + outf[1:]
     exe = 'wine ' + bontsdemux + " -i \"" + bonpin + "\" -delay 167 -nd -sound 3 -o \"" + bonpout + "\" -start -quit"
-    #recdblist.printutf8(exe)
     exe = xvfb + ' -a ' + exe
-    #exe = 'xvfb-run -a ' + exe
-    #exe='export Display=:2&&'+exe
     recdblist.printutf8(exe)
     commands.getoutput(exe.encode('utf-8'))
-    #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 + "\'"
     recdblist.printutf8(exe)
     commands.getoutput(exe.encode('utf-8'))
-    #os.system(exe)
     os.remove(ffpin1)
     os.remove(ffpin2)
 
index 483ce53..1def18c 100644 (file)
@@ -25,10 +25,12 @@ def avi2mkv(pin,pout,opt):
     title=os.path.split(pout)[1]
     title=os.path.splitext(title)[0]
     isvfr=0
+    isdualaac=0
     if re.search("v", opt):
         isvfr=1
     if re.search("d",opt):
         isvfr=0
+        isdualaac=1
     elif re.search("5",opt):
         isvfr=0
     exe = configreader.getpath("mkvmerge")
@@ -54,6 +56,24 @@ def avi2mkv(pin,pout,opt):
             txt=txt+execcomd(e3s)
         else:
             txt=txt+execcomd(e3)
+    elif isdualaac==1:
+        wineexe=configreader.getpath("wine")
+        pincap=pin.replace(".avi",".srt")
+        cap2ass=configreader.getpath("Caption2Ass")
+        pints=pin.replace(".avi",".ts")
+        paac1=pin.replace(".avi","_1.aac")
+        paac2=pin.replace(".avi","_2.aac")
+        if os.path.exists(paac1):
+            paac1=pin.replace(".avi","_1.mp3")
+            paac2=pin.replace(".avi","_2.mp3")
+        e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
+        e1=exe +" -o '"+pout+u"'  --forced-track 0:no -d 0 -A -S '"+pin+"' --sync 0:0 --forced-track 0:no -a 0 -D -S '"+paac1+"' --forced-track 0:no -a 0 -D -S '"+paac2+"' --track-order 0:0,1:0,2:0"
+        e1s=exe +" -o '"+pout+u"'  --forced-track 0:no -d 0 -A -S '"+pin+"' --sync 0:0 --forced-track 0:no -a 0 -D -S '"+paac1+"' --forced-track 0:no -a 0 -D -S '"+paac2+"' --forced-track 0:no -s 0 -D -A '"+pincap+"' --track-order 0:0,1:0,2:0,3:0"
+        txt=txt+execcomd(e0)
+        if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
+            txt=txt+execcomd(e1s)
+        else:
+            txt=txt+execcomd(e1)
     else:
         wineexe=configreader.getpath("wine")
         pincap=pin.replace(".avi",".srt")
@@ -90,6 +110,11 @@ def deltitle(path,title):
     dp.append(os.path.join(path,title+".120.avi"))
     dp.append(os.path.join(path,title+".noodml.avi"))
     dp.append(os.path.join(path,title+".aac"))
+    dp.append(os.path.join(path,title+".m2v"))
+    dp.append(os.path.join(path,title+"_1.aac"))
+    dp.append(os.path.join(path,title+"_2.aac"))
+    dp.append(os.path.join(path,title+"_1.mp3"))
+    dp.append(os.path.join(path,title+"_2.mp3"))
     dp.append(os.path.join(path,title+".srt"))
     if os.path.exists(os.path.join(path,title+".ts"))and os.path.exists(os.path.join(path,title+".ts.b25")):
         if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
index 5ec0fbf..c865c34 100644 (file)
@@ -161,6 +161,11 @@ def avi2mp4(pin,pout,opt):
     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".m2v"))\r
+    delpath.append(pin.replace(u".avi",u"_1.aac"))\r
+    delpath.append(pin.replace(u".avi",u"_2.aac"))\r
+    delpath.append(pin.replace(u".avi",u"_1.mp3"))\r
+    delpath.append(pin.replace(u".avi",u"_2.mp3"))\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