+import auto_process
#!/usr/bin/python
# coding: UTF-8
# Rec10 TS Recording Tools
# Copyright (C) 2009-2010 Yukikaze
-import status
import os
-import commands
-import tv2avi
import os.path
-import time
-import re
-import recdblist
+import tv2mp4
import configreader
+import subprocess
def ts2mkv(pin, pout, opt):
- 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")
- tpmkv=os.path.join(dir, title+".mkv")
- tv2avi.ts2avi(pin, tpavi, opt)
- time.sleep(10)
- avi2mkv(tpavi,tpmkv,opt)
-def avi2mkv(pin,pout,opt):
- dir=os.path.split(pout)[0]
- 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
+ tpout=pout.replace(".mkv",".mp4")
+ tv2mp4.ts2mp4(pin, tpout, opt)
+ mp42mkv(pout, tpout)
+ if os.path.exists(pout) and os.path.getsize(pout)>os.path.getsize(tpout)*0.9:
+ os.remove(tpout)
+def mp42mkv(pmkv,pmp4):
exe = configreader.getpath("mkvmerge")
- txt=""
- os.environ['LANG']="ja_JP.UTF-8"
- if isvfr==1:
- wineexe=configreader.getpath("wine")
- cap2ass=configreader.getpath("Caption2Ass")
- pints=pin.replace(".avi",".ts")
- pincap=pin.replace(".avi",".srt")
- pinaac=pin.replace(".avi",".aac")
- e0="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"
- #e1=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
- e2=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
- #e3=exe +" -o '"+pout+u"' --forced-track 0:no -d 0 -A -S '"+pin+"' --sync 0:-100 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0"
- #e3s=exe +" -o '"+pout+u"' --forced-track 0:no -d 0 -A -S '"+pin+"' --sync 0:-100 --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"
- e3=exe +" -o '"+pout+u"' --forced-track 0:no -d 0 -a 1 -S '"+pin+"' --sync 0:0 --track-order 0:0,0:1"
- e3s=exe +" -o '"+pout+u"' --forced-track 0:no -d 0 -a 1 -S '"+pin+"' --sync 0:0 --forced-track 0:no -s 0 -D -A '"+pincap+"' --track-order 0:0,0:1,1:0"
- txt=txt+execcomd(e0)
- #txt=txt+execcomd(e1)
- txt=txt+execcomd(e2)
- if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
- 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")
- recdblist.printutf8(paac1)
- if not 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 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 --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"
- 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")
- cap2ass=configreader.getpath("Caption2Ass")
- pints=pin.replace(".avi",".ts")
- pinaac=pin.replace(".avi",".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 --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 --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"
-
-
- #e2=exe + u" -o '" + pout + u"' --forced-track 0:no --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --track-order 0:0,0:1"
- #e2s=exe + u" -o '" + pout + u"' --forced-track 0:no --forced-track 1:no -a 1 -d 0 -S '" + pin + u"' --forced-track 0:no -s 0 -A -D '"+pincap+"' --track-order 0:0,0:1,1:0"
- 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)
- logo=pout.replace(".mkv",".log")
- if status.getSettings_auto_del_tmp()==1:
- deltitle(dir,title)
- txt = "\n####mkvmerge-log####\n"+txt
- f=open(logo,'a')
- f.write(txt.encode('utf-8'))
- f.close()
-def execcomd(cmd):
- txt=""
- cmdt=u"nice -n 17 "+cmd
- try:
- txt=u"Cmd : "+cmd+"\n"
- txt2=commands.getoutput(cmdt.encode('utf-8'))
- txt=txt+unicode(txt2,"utf-8")+"\n"
- except:
- ""
- return txt
-def deltitle(path,title):
- dp=[]
- dp.append(os.path.join(path,title+".avi"))
- 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")):
- if os.path.getsize(os.path.join(path,title+".ts"))>1000*1000*100:
- dp.append(os.path.join(path,title+".ts.b25"))
- for ip in dp:
- try:
- os.remove(ip)
- except:
- ""
-
\ No newline at end of file
+ e1=exe +" -o \""+pmkv+u"\" \""+pmp4+"\""
+ p=subprocess.Popen(e1,shell=True)
+ os.waitpid(p.pid, 0)