iff =
bs = 0
cs = 0
+x264_preset=4#エンコードの重さの設定 大きければ大きいほど(1-6)速度は遅くなるが同じ画質でもサイズが小さくなる。
+crf=18
+animation_crf=16
# Rec10 TS Recording Tools
# Copyright (C) 2009-2010 Yukikaze
import commands
+import configreader
import os
+import os.path
import re
-import time
-import tv2avi
+import base64
import recdblist
def ts2x264(pin, pout, opts):#sizeは"HD"か"SD"
"""
pinで指定されたファイルをpoutにx264でエンコードして書き出す
"""
dualpass = 0
- isvfr=0
is24fps=0
- islight=0
- size="Tall"
- quality=5
+ size="HD"
+ crf=18
+ quality=4
+ quality=int(configreader.getenv("x264_preset"))
+ crf=int(configreader.getenv("crf"))
if re.search("2", opts):
dualpass = 1
if re.search("H", opts):
size = "HD"
if re.search("S", opts):
size = "SD"
- quality=quality-2
if re.search("F", opts):
- size = "FHD"
- if re.search("L", opts):
- size = "Short"
- quality=quality-2
- if re.search("G", opts):
- size = "LowHD"
+ size = "FullHD"
+ if re.search("W",opts):
+ size = "WVGA"
if re.search("v", opts):
is24fps=1
+ crf=int(configreader.getenv("animation_crf"))
if re.search("a", opts):
is24fps=1
- quality=quality+2
- if re.search("l",opts):
+ crf=int(configreader.getenv("animation_crf"))
+ if re.search("q",opts):
quality=quality-2
- if re.search("h",opts):
+ if re.search("w",opts):
+ quality=quality-1
+ if re.search("e",opts):
+ quality=quality+1
+ if re.search("r",opts):
quality=quality+2
+ if re.search("u",opts):
+ crf=crf+2
+ if re.search("i",opts):
+ crf=crf+1
+ if re.search("o",opts):
+ crf=crf-1
+ if re.search("p",opts):
+ crf=crf-2
if re.search("d",opts):
- encode_ffmpeg(pin, pout, size, dualpass ,is24fps , quality)
+ encode_ffmpeg(pin,pout,size,is24fps,quality,crf)
elif re.search("5",opts):
- encode_ffmpeg(pin, pout, size, dualpass ,is24fps , quality)
+ encode_ffmpeg(pin,pout,size,is24fps,quality,crf)
else:
encode(pin, pout,size,dualpass,is24fps,quality)
-def encode(pin,pout,size,is2pass,is24fps,quality):
+def encode(pin,pout,size,is24fps,quality,crf):
encvf=""
txt=""
encvf="-vf yadif=0,pp=l5"
harddup=",hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup"
ofps="-ofps 30000/1001"
fps="-fps 30000/1001"
- bm=1
- scale=""
- bnum=2000
+ x264fps="--fps 30000/1001"
+ x264streamsize=""
+ x264preset=""
+ x264tune=""
if size == "HD":
encvf = encvf + ",scale=1280:720::0:3"+harddup
- bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
- bnum=tv2avi.Bitrate_HD*bm
- crf="crf=20"
+ x264streamsize=u"1280x720"
+ elif size == "WVGA":
+ encvf = encvf + ",scale=854:480::0:3"+harddup
+ x264streamsize=u"854x480"
+ elif size == "FullHD":
+ encvf = encvf + ",scale=1920:1080::0:3"+harddup
+ x264streamsize=u"1920x1080"
elif size == "SD":
encvf = encvf + ",scale=720:480::0:3"+harddup
- bitrate = "bitrate=" + str(tv2avi.Bitrate_SD*bm)
- bnum=tv2avi.Bitrate_SD*bm
- crf="crf=20"
- elif size == "FHD":
- encvf = encvf + ",scale=1920:1080::0:3"+harddup
- bitrate = "bitrate=" + str(tv2avi.Bitrate_FHD*bm)
- bnum=tv2avi.Bitrate_FHD*bm
- crf="crf=22"
- elif size == "Short":
- encvf = encvf +harddup
- bitrate = "bitrate=" + str(tv2avi.Bitrate_Short*bm)
- bnum=tv2avi.Bitrate_Short*bm
- crf="crf=20"
- elif size == "LowHD":
- encvf = encvf + ",scale=1280:720::0:3"+harddup
- bitrate = "bitrate=" + str(tv2avi.Bitrate_LowHD*bm)
- bnum=tv2avi.Bitrate_LowHD*bm
- crf="crf=22"
+ x264streamsize=u"720x480"
else:
encvf = encvf + ",scale=1280:720::0:3"+harddup
- bitrate = "bitrate=" + str(tv2avi.Bitrate_HD*bm)
- bnum=tv2avi.Bitrate_HD*bm
- crf="crf=22"
- x264enc=""
- x264enc1=""
- x264enc2=""
- #mencoder "./test.ts" -vfm ffmpeg -nosound -sws 9 -vf pullup,softskip,scale=1280:720::0:3,hqdn3d=2:1:2,unsharp=l3x3:0.75:c3x3:0.75,harddup,format=i420 -ofps 24000/1001 -fps 30000/1001 -ovc raw -of rawvideo -o "stream"& x264 --crf 18 --fps 24000/1001 -o "./test.mkv" stream 1280x720
- if quality<3:
- x264enc=":me=dia:partitions=none:frameref=1:subq=2:scenecut=0:trellis=0"
- x264enc1=x264enc
- x264enc2=x264enc1
- elif quality<5:
- x264enc=":me=dia:partitions=i8x8,i4x4:frameref=1:subq=4:trellis=0"
- x264enc1=x264enc
- x264enc2=x264enc1
- elif quality<7:
- x264enc=":8x8dct:bframes=1"
- x264enc1=x264enc
- x264enc2=x264enc1
- elif quality<9:
- x264enc=":direct_pred=auto:frameref=5:subq=6:8x8dct:bframes=3:trellis=1"
- x264enc1=x264enc
- x264enc2=x264enc1
- elif quality<11:
- x264enc=":frameref=5:subq=7:trellis=2:partitions=all:8x8dct:direct_pred=auto:me=umh:bframes=3"
- x264enc1=x264enc
- x264enc2=x264enc1
- crf=""
+ x264streamsize=u"1280x720"
+ if quality==1:
+ x264preset=u"--perset ultrafast"
+ elif quality==2:
+ x264preset=u"--perset veryfast"
+ elif quality==3:
+ x264preset=u"--perset fast"
+ elif quality==4:
+ x264preset=u"--perset medium"
+ elif quality==5:
+ x264preset=u"--perset slow"
+ elif quality==6:
+ x264preset=u"--perset slower"
+ x264crf=u"--crf "+str(crf)
if is24fps==1:
ofps="-ofps 24000/1001"
fps="-fps 30000/1001"
+ x264fps="--fps 24000/1001"
encvf="-vf pullup,softskip"
harddup=",pp=l5,unsharp=l3x3:0.75:c3x3:0.75,hqdn3d=2:1:2,harddup"
- bm=1
- if quality<3:
- vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
- x264enc=":me=dia:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=none:frameref=1:subq=2:scenecut=0:trellis=0"
- x264enc1=x264enc+vbv
- x264enc2=x264enc1
- elif quality<5:
- vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
- x264enc=":me=dia:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=i8x8,i4x4:frameref=1:subq=4:trellis=0"
- x264enc1=x264enc+vbv
- x264enc2=x264enc1
- elif quality<7:
- vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
- x264enc=":aq-strength=0.6:8x8dct:deblock=1,1:psy-rd=0.4:bframes=1"
- x264enc1=x264enc+vbv
- x264enc2=x264enc1
- elif quality<9:
- vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
- x264enc=":direct_pred=auto:aq-strength=0.6:deblock=1,1:psy-rd=0.4:8x8dct:frameref=5:subq=6:bframes=3:trellis=1"
- x264enc1=x264enc+vbv
- x264enc2=x264enc1
- elif quality<11:
- vbv=":vbv_maxrate="+str(bnum*2)+":vbv_bufsize="+str(bnum*4)
- x264enc=":frameref=5:subme=8:subq=7:trellis=2:aq-strength=0.6:deblock=1,1:psy-rd=0.4:partitions=all:8x8dct:direct_pred=auto:me=umh:bframes=3"
- x264enc1=x264enc+vbv
- x264enc2=x264enc1
- if is2pass == 1:
- pas1exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -nosound -sws 9 -ovc x264 " + encvf +" "+fps+" "+ofps+" -x264encopts " + bitrate +x264enc1+ ":threads=auto:level_idc=41:pass=1:turbo=2 -passlogfile \'" + pin + ".log\' " + " -o /dev/null"
- pas2exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -sws 9 -ovc x264 " + encvf +" "+fps+ " "+ofps+" -x264encopts " + bitrate +x264enc2+ ":level_idc=41:threads=auto:pass=2 -passlogfile \'" + pin + ".log\' -oac mp3lame -lameopts cbr:br=256 -o \'" + pout + "\'"
- pas1exe = "nice -n 19 " + pas1exe
- pas2exe = "nice -n 19 " + pas2exe
- recdblist.printutf8(pas1exe)
- txt=txt+"Cmd : "+pas1exe+"\n"
- txtt=""
- try:
- txtt=unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
- except:
- ""
- txt=txt+txtt
- recdblist.printutf8(pas2exe)
- time.sleep(5)
- txtt=""
- try:
- txtt=unicode(commands.getoutput(pas2exe.encode('utf-8')),'utf-8')
- except:
- ""
- txt=txt+txtt
- else:
- pas1exe = "mencoder \'" + pin + "\' -vfm ffmpeg -quiet -sws 9 -ovc x264 " + encvf+" "+fps + " "+ofps+" -x264encopts " + bitrate +x264enc+":level_idc=41:threads=auto -oac mp3lame -lameopts cbr:br=256 -o \'" + pout + "\'"
- pas1exe = "nice -n 19 " + pas1exe
- recdblist.printutf8(pas1exe)
- txt=txt+"Cmd : "+pas1exe+"\n"
- txtt=""
- try:
- txtt=unicode(commands.getoutput(pas1exe.encode('utf-8')),'utf-8')
- except:
- ""
- txt=txt+txtt
+ os.environ['LANG']="ja_JP.UTF-8"
+ streampath=os.path.join(os.path.dirname(pin),base64.b32encode(os.path.split(pin)[1])[0:10])
+ os.system(u"mkfifo "+streampath)
+ encexe=u"mencoder \""+pin+u"\" -vfm ffmpeg -quiet -sws 9 "+encvf+u" "+fps+" "+ofps+" -ovc raw -of rawvideo -o \""+streampath+"\" &"
+ encexe=encexe+u" x264 "+x264crf+" --level 41 --profile high"+x264preset+" "+x264tune+" "+x264fps+" "+x264crf+" -o \""+pout+"\" "+streampath+" "+x264streamsize
+ encexe=u"nice -n 19 " +encexe
+ recdblist.printutf8(encexe)
+ txt=txt+"Cmd : "+encexe+"\n"
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(encexe.encode('utf-8')),'utf-8')
+ except:
+ ""
+ os.system("rm "+streampath)
+ txt=txt+txtt
recdblist.addlog( pin, txt, "mencoder-log")
-def encode_ffmpeg(pin,pout,size,is2pass,is24fps,quality):
+def encode_ffmpeg(pin,pout,size,is24fps,quality,crf):
"""
"""
ffmpeg="ffmpeg"
- if quality<3:
- x264enc="-level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 "
- x264enc1=x264enc
- x264enc2=x264enc1
- elif quality<5:
- x264enc="-level 42 -me_method dia -partitions parti8x8+parti4x4 -refs 1 -trellis 0 "
- x264enc1="-level 42 -me_method dia -partitions none -refs 1 -trellis 0 "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<7:
- x264enc="-level 42 "
- x264enc1="-level 42 -me_method dia -partitions none "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<9:
- x264enc="-level 42 -directpred auto -refs 5 -subq 6 -bf 1 -trellis 1 "
- x264enc1="-level 42 -me_method dia -partitions none -refs 1 -subq 6 -bf 1 -trellis 1 "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<11:
- x264enc="-level 42 -refs 5 -subq 7 -trellis 2 -partitions all -directpred auto -me_method umh -bf 3 "
- x264enc1="-level 42 -me_method dia -partitions none -refs 1 -subq 7 -trellis 2 -directpred auto -bf 3 "
- x264enc1=x264enc
- x264enc2=x264enc
- if is24fps==1:
- if quality<3:
- x264enc="-level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
- x264enc1="-level 42 -me_method dia -partitions none -refs 1 -scenecut 0 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<5:
- x264enc="-level 42 -me_method dia -partitions parti8x8+parti4x4 -refs 1 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
- x264enc1="-level 42 -me_method dia -partitions none -refs 1 -trellis 0 -deblockalpha 1 -deblockbeta 1 "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<7:
- x264enc="-level 42 -deblockalpha 1 -deblockbeta 1 "
- x264enc1="-me_method dia -partitions none -vpre hq -level 42 -deblockalpha 1 -deblockbeta 1 "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<9:
- x264enc="-level 42 -directpred auto -refs 5 -subq 6 -bf 1 -trellis 1 -deblockalpha 1 -deblockbeta 1 "
- x264enc1="-level 42 -directpred auto -me_method dia -partitions none -refs 1 -subq 6 -bf 1 -trellis 1 -deblockalpha 1 -deblockbeta 1 "
- x264enc1=x264enc
- x264enc2=x264enc
- elif quality<11:
- x264enc="-level 42 -refs 5 -subq 7 -trellis 2 -partitions all -directpred auto -me_method umh -bf 3 -deblockalpha 1 -deblockbeta 1 "
- x264enc1="-level 42 -refs 1 -subq 7 -trellis 2 -partitions none -directpred auto -me_method dia -bf 3 -deblockalpha 1 -deblockbeta 1 "
- x264enc1=x264enc
- x264enc2=x264enc
+ fps=u"-r 29.970030 "
+ x264fps="--fps 30000/1001"
+ x264streamsize=""
+ x264preset=""
+ x264tune=""
if size == "HD":
s = "-s 1280x720 "
- bitrate = str(tv2avi.Bitrate_HD)
- crf="crf=20"
+ x264streamsize=u"1280x720"
+ elif size == "WVGA":
+ s = "-s 854x480 "
+ x264streamsize=u"854x480"
+ elif size == "FullHD":
+ s = "-s 1920x1080 "
+ x264streamsize=u"1920x1080"
elif size == "SD":
- s ="-s 720x480 "
- bitrate = str(tv2avi.Bitrate_SD)
- crf="crf=20"
- elif size == "FHD":
- s ="-s 1920x1080 "
- bitrate = str(tv2avi.Bitrate_FHD)
- crf="crf=22"
- elif size == "Short":
- s= ""
- bitrate = str(tv2avi.Bitrate_Short)
- crf="crf=20"
- elif size == "LowHD":
- s = "-s 1280x720 "
- bitrate = str(tv2avi.Bitrate_LowHD)
- crf="crf=22"
+ s = "-s 720x480 "
+ x264streamsize=u"720x480"
else:
s = "-s 1280x720 "
- bitrate = str(tv2avi.Bitrate_LowHD)
- crf="crf=22"
+ x264streamsize=u"1280x720"
+ if quality==1:
+ x264preset=u"--perset ultrafast"
+ elif quality==2:
+ x264preset=u"--perset veryfast"
+ elif quality==3:
+ x264preset=u"--perset fast"
+ elif quality==4:
+ x264preset=u"--perset medium"
+ elif quality==5:
+ x264preset=u"--perset slow"
+ elif quality==6:
+ x264preset=u"--perset slower"
+ x264crf=u"--crf "+str(crf)
txt=""
- if is2pass==1:
- os.environ['LANG']="ja_JP.UTF-8"
- exe1=ffmpeg+" -y -i \""+pin+"\" -pass 1 -vsync 400 -vcodec libx264 -vpre fastfirstpass -b "+bitrate+"k "+x264enc1+s+"-deinterlace -an -f avi /dev/null"
- exe2=ffmpeg+" -y -i \""+pin+"\" -pass 2 -vsync 400 -vcodec libx264 -vpre hq -b "+bitrate+"k "+x264enc2+s+"-deinterlace -an -f avi \"" +pout+"\"" #aviにすべきかどうか
- recdblist.printutf8(exe1)
- exe1 = "nice -n 19 " + exe1
- exe2 = "nice -n 19 " + exe2
- txt=txt+u"Cmd : "+exe1+"\n"
- txtt=""
- try:
- txtt=unicode(commands.getoutput(exe1.encode('utf-8')),'utf-8')
- except:
- ""
- txt=txt+txtt
- recdblist.addlog( pin, txt, "dual audio ffmpeg-log - 1pass")
- txt=""
- txt=txt+u"Cmd : "+exe2+"\n"
- txtt=""
- try:
- txtt=unicode(commands.getoutput(exe2.encode('utf-8')),'utf-8')
- except:
- ""
- txt=txt+txtt
- recdblist.addlog( pin, txt, "dual audio ffmpeg-log - 2pass")
- else:
- os.environ['LANG']="ja_JP.UTF-8"
- exe=ffmpeg+" -y -i \""+pin+"\" -vsync 400 -vcodec libx264 -vpre hq -b "+bitrate+"k "+x264enc+s+"-deinterlace -an \"" +pout+"\""
- txt=txt+"Cmd : "+exe+"\n"
- exe = "nice -n 19 " + exe
- txt=txt+"Cmd : "+exe+"\n"
- txtt=""
- try:
- txtt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
- except:
- ""
- txt=txt+txtt
- recdblist.addlog( pin, txt, "dual audio ffmpeg-log")
+ os.environ['LANG']="ja_JP.UTF-8"
+ exe=ffmpeg+u" -y -i \""+pin+"\" -vsync 400 -vcodec rawvideo -pix_fmt yuv420p "+s+r+"-deinterlace -an -f rawvideo - |"
+ exe=exe+u" x264 "+x264crf+" --level 41 --profile high"+x264preset+" "+x264tune+" "+x264fps+" "+x264crf+" -o \""+pout+"\" - "+x264streamsize
+ txt=txt+"Cmd : "+exe+"\n"
+ exe = "nice -n 19 " + exe
+ txt=txt+"Cmd : "+exe+"\n"
+ txtt=""
+ try:
+ txtt=unicode(commands.getoutput(exe.encode('utf-8')),'utf-8')
+ except:
+ ""
+ txt=txt+txtt
+ recdblist.addlog( pin, txt, "dual audio ffmpeg-log")
\ No newline at end of file
print type(inst)
print inst
status.changeEncoding(-1)
+def ts2raw(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
+ status.changeEncoding(-1)
def dualaudiots2avi(pin, pout):
bontsdemux = configreader.getpath('bontsdemux')
bonpin = "Z:\\" + pin[1:]
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")
+ ##use avi
+ """tpavi=os.path.join(dir,title+".avi")
tpmkv=os.path.join(dir, title+".mkv")
tv2avi.ts2avi(pin, tpavi, opt)
time.sleep(10)
- avi2mkv(tpavi,tpmkv,opt)
+ avi2mkv(tpavi,tpmkv,opt)"""
+ tpraw=os.path.join(dir, title+".264")
+ tpmkv=os.path.join(dir, title+".mkv")
+ tv2avi.ts2raw(pin, tpraw, opt)
+ time.sleep(10)
+ raw2mkv(tpraw, tpmkv, opt)
+def raw2mkv(pin,pout,opt):#x264
+ dir=os.path.split(pout)[0]
+ title=os.path.split(pout)[1]
+ title=os.path.splitext(title)[0]
+ duration="--default-duration 0:30000/1001fps "
+ isdualaac=0
+ ispentaaudio=0
+ if re.search("a",opt):
+ duration="--default-duration 0:24000/1001fps "
+ elif re.search("v",opt):
+ duration="--default-duration 0:24000/1001fps "
+ if re.search("d",opt):
+ isdualaac=1
+ duration="--default-duration 0:30000/1001fps "##ffmpegが24fpsに対応していないための措置
+ elif re.search("5",opt):
+ ispentaaudio=1
+ duration="--default-duration 0:30000/1001fps "##ffmpegが24fpsに対応していないための措置
+ exe = configreader.getpath("mkvmerge")
+ txt=""
+ os.environ['LANG']="ja_JP.UTF-8"
+ if isdualaac==1:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".264",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ pints=pin.replace(".264",".ts")
+ paac1=pin.replace(".264","_1.aac")
+ paac2=pin.replace(".264","_2.aac")
+ recdblist.printutf8(paac1)
+ if not os.path.exists(paac1):
+ paac1=pin.replace(".264","_1.mp3")
+ if not os.path.exists(paac2):
+ paac2=pin.replace(".264","_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 "+duration+u"--forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --track-order 0:0,1:1,2:1"
+ e1s=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 "+duration+u"--forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --forced-track 0:no -s 0 -D -A \""+pincap+"\" --track-order 0:0,1:1,2:1,3:0"
+ if os.path.isfile(cap2ass):
+ txt=txt+execcomd(e0)
+ if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
+ txt=txt+execcomd(e1s)
+ else:
+ txt=txt+execcomd(e1)
+ elif ispentaaudio==1:
+ wineexe=configreader.getpath("wine")
+ pincap=pin.replace(".264",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ pints=pin.replace(".264",".ts")
+ paac1=pin.replace(".264","_1.aac")
+ paac2=pin.replace(".264","_2.aac")
+ recdblist.printutf8(paac1)
+ if not os.path.exists(paac1):
+ paac1=pin.replace(".264","_1.mp3")
+ if not os.path.exists(paac2):
+ paac2=pin.replace(".264","_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 "+duration+u"--forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --track-order 0:0,1:1,2:1"
+ e1s=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 "+duration+u"--forced-track 0:no -a 1 -D -S \""+paac1+"\" --forced-track 0:no -a 1 -D -S \""+paac2+"\" --forced-track 0:no -s 0 -D -A \""+pincap+"\" --track-order 0:0,1:1,2:1,3:0"
+ if os.path.isfile(cap2ass):
+ 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(".264",".srt")
+ cap2ass=configreader.getpath("Caption2Ass")
+ pints=pin.replace(".264",".ts")
+ pinaac=pin.replace(".264",".aac")
+ e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
+ e1="ffmpeg -i \""+pints+"\" -vn -f aac -acodec copy \""+pinaac+"\""
+ e2=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 "+duration+u"--forced-track 0:no -a 0 -D -S \""+pinaac+"\" --track-order 0:0,1:0"
+ e2s=exe +" -o \""+pout+u"\" --forced-track 0:no -d 0 -A -S \""+pin+"\" --sync 0:0 "+duration+u"--forced-track 0:no -a 0 -D -S \""+pinaac+"\" --forced-track 0:no -s 0 -D -A \""+pincap+"\" --track-order 0:0,1:0,2:0"
+ if os.path.isfile(cap2ass):
+ txt=txt+execcomd(e0)
+ txt=txt+execcomd(e1)
+ if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
+ txt=txt+execcomd(e2s)
+ else:
+ txt=txt+execcomd(e2)
+ recdblist.addlog(pout, txt, "mkvmerge-log")
+ logo=pout.replace(".mkv",".log")
+ if status.getSettings_auto_del_tmp()==1:
+ if os.path.exists(pout):
+ if os.path.getsize(pout)>100*1000*1000:
+ deltitle(dir,title)
def avi2mkv(pin,pout,opt):
dir=os.path.split(pout)[0]
title=os.path.split(pout)[1]
import os\r
import re\r
import os.path\r
+import string\r
import base64\r
import time\r
import recdblist\r
if os.path.exists(pin):\r
tpavi=pin\r
avi2mp4(tpavi,pout,opt)\r
+def raw2mp4(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
+ duration="-fps 29.970030 "\r
+ isdualaac=0\r
+ ispentaaudio=0\r
+ if re.search("a",opt):\r
+ duration="-fps 23.976023 "\r
+ elif re.search("v",opt):\r
+ duration="-fps 23.976023 "\r
+ if re.search("d",opt):\r
+ isdualaac=1\r
+ duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置\r
+ elif re.search("5",opt):\r
+ ispentaaudio=1\r
+ duration="-fps 29.970030 "##ffmpegが24fpsに対応していないための措置\r
+ exe = configreader.getpath("mp4box")\r
+ txt=""\r
+ os.environ['LANG']="ja_JP.UTF-8"\r
+ if isdualaac==1:\r
+ wineexe=configreader.getpath("wine")\r
+ pincap=pin.replace(".264",".srt")\r
+ cap2ass=configreader.getpath("Caption2Ass")\r
+ pints=pin.replace(".264",".ts")\r
+ paac1=pin.replace(".264","_1.aac")\r
+ paac2=pin.replace(".264","_2.aac")\r
+ recdblist.printutf8(paac1)\r
+ if not os.path.exists(paac1):\r
+ paac1=pin.replace(".264","_1.mp3")\r
+ 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
+ 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
+ wineexe=configreader.getpath("wine")\r
+ pincap=pin.replace(".264",".srt")\r
+ cap2ass=configreader.getpath("Caption2Ass")\r
+ pints=pin.replace(".264",".ts")\r
+ paac1=pin.replace(".264","_1.aac")\r
+ paac2=pin.replace(".264","_2.aac")\r
+ recdblist.printutf8(paac1)\r
+ if not os.path.exists(paac1):\r
+ paac1=pin.replace(".264","_1.mp3")\r
+ 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
+ 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
+ wineexe=configreader.getpath("wine")\r
+ pincap=pin.replace(".264",".srt")\r
+ cap2ass=configreader.getpath("Caption2Ass")\r
+ pints=pin.replace(".264",".ts")\r
+ 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
+ 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, e2s)\r
+ recdblist.addlog(pout, txt, "mp4box-log")\r
+ if status.getSettings_auto_del_tmp()==1:\r
+ if os.path.exists(pout):\r
+ if os.path.getsize(pout)>100*1000*1000:\r
+ deltitle(dir,title)\r
def avi2mp4(pin,pout,opt):\r
isvfr=0\r
if re.search(u"v", opt):\r
os.remove(timecodepath)\r
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
+ 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
+ cmdn=string.replace(cmd,pin,ptin)\r
+ cmdn=string.replace(cmdn,pout,ptout)\r
+ txt=""\r
+ try:\r
+ txt=execcomd(cmdn)\r
+ except Exception, inst:\r
+ txt= "error occures in execmp4box\n"\r
+ txt=txt+ str(type(inst))+"\n"\r
+ txt=txt+str(inst)\r
+ recdblist.addlog(pin, txt, "MP4Box-log")\r
+ time.sleep(3)\r
+ shutil.move(ptout,pout)\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
+ 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
+ cmdn=string.replace(cmd,padd,ptadd)\r
+ cmdn=string.replace(cmdn,pout,ptout)\r
+ txt=""\r
+ try:\r
+ txt=execcomd(cmdn)\r
+ except Exception, inst:\r
+ 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
+ shutil.move(ptout,pout)\r
def execcomd(cmd):\r
txt=""\r
try:\r