4 # Rec10 TS Recording Tools
5 # Copyright (C) 2009 Yukikaze
14 def ts2mkv(pin, pout, opt):
15 dir=os.path.split(pout)[0]
16 title=os.path.split(pout)[1]
17 title=os.path.splitext(title)[0]
18 tpavi=os.path.join(dir,title+".avi")
19 tpmkv=os.path.join(dir, title+".mkv")
20 tv2avi.ts2avi(pin, tpavi, opt)
22 avi2mkv(tpavi,tpmkv,opt)
23 def avi2mkv(pin,pout,opt):
24 dir=os.path.split(pout)[0]
25 title=os.path.split(pout)[1]
26 title=os.path.splitext(title)[0]
28 if re.search("v", opt):
30 exe = configreader.getpath("mkvmerge")
32 os.environ['LANG']="ja_JP.UTF-8"
34 wineexe=configreader.getpath("wine")
35 cfr2tc=configreader.getpath("cfr2tc")
36 cap2ass=configreader.getpath("Caption2Ass")
37 pin120=pin.replace(".avi",".120.avi")
38 pints=pin.replace(".avi",".ts")
39 pintimecode=pin.replace(".avi",".timecode.txt")
40 pincap=pin.replace(".avi",".srt")
41 pinaac=pin.replace(".avi",".aac")
42 e0="ffmpeg -i '"+pints+"' -vn -f aac -acodec copy '"+pinaac+"'"
43 e1=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+pin+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
44 e2=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
45 e3=exe +" -o '"+pout+u"' --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0"
46 e3s=exe +" -o '"+pout+u"' --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --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"
50 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
54 if (not os.path.exists(pin.replace(".avi",".120.avi"))and (not os.path.exists(pout))):
55 txt=txt+"CFR2TC error. maybe avi file is over 1GB.(ODML error would have happend.)"
56 ptmp=pin.replace(".avi",".noodml.avi")
57 e1="mencoder -noodml -forceidx -oac copy -ovc copy -o \'"+ptmp+"\'"+" \'"+pin+"\'"
58 e2=wineexe+u" "+cfr2tc+u" '"+"Z:\\"+ptmp+"' '"+"Z:\\"+pin120+u"' '"+"Z:\\"+pintimecode+u"' 2"
59 e3=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
60 e4=exe +" -o '"+pout+u"' --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --forced-track 0:no -a 0 -D -S '"+pinaac+"' --track-order 0:0,1:0"
61 e4s=exe +" -o '"+pout+u"' --forced-track 0:no --timecodes '0:"+pintimecode+"' -d 0 -A -S '"+pin120+"' --sync 0:-225 --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"
63 cmdt=cmdt+execcomd(e2)
64 cmdt=cmdt+execcomd(e3)
65 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
75 wineexe=configreader.getpath("wine")
76 pincap=pin.replace(".avi",".srt")
77 cap2ass=configreader.getpath("Caption2Ass")
78 pints=pin.replace(".avi",".ts")
79 e0=wineexe+u" "+cap2ass+u" -format srt \"Z:\\"+pints+"\" \"Z:\\"+pincap+"\""
80 e1=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"
81 e1s=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"
83 if os.path.exists(pincap) and (os.path.getsize(pincap)>1000):
87 logo=pout.replace(".mkv",".log")
88 if status.getSettings_auto_del_tmp()==1:
90 txt = "\n####mkvmerge-log####\n"+txt
92 f.write(txt.encode('utf-8'))
96 cmdt=u"nice -n 17 "+cmd
98 txt=u"Cmd : "+cmd+"\n"
99 txt2=commands.getoutput(cmdt.encode('utf-8'))
100 txt=txt+unicode(txt2,"utf-8")+"\n"
104 def deltitle(path,title):
106 dp.append(os.path.join(path,title+".avi"))
107 dp.append(os.path.join(path,title+".120.avi"))
108 dp.append(os.path.join(path,title+".noodml.avi"))
109 dp.append(os.path.join(path,title+".aac"))
110 dp.append(os.path.join(path,title+".srt"))
111 if os.path.exists(os.path.join(path,title+".ts"))and os.path.exists(os.path.join(path,title+".ts.b25")):
112 if os.path.getsize(os.path.join(path,title+".ts"))*10>os.path.getsize(os.path.join(path,title+".ts.b25")):
113 if os.path.getsize(os.path.join(path,title+".ts"))>1000*1000*100:
114 dp.append(os.path.join(path,title+".ts.b25"))