OSDN Git Service

bayes suggest implemented.
[rec10/rec10-git.git] / rec10 / trunk / src / tv2mp4.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5 import sys
6 import commands
7 import tv2avi
8 import os
9 import os.path
10 import time
11 def ts2mp4(pin, pout, opt):
12     dir=os.path.split(pin)[0]
13     title=os.path.split(pin)[1]
14     title=os.path.splitext(title)[0]
15     tpavi=os.path.join(dir, title+".avi")
16     tpmp4=os.path.join(dir, title+".mp4")
17     tv2avi.ts2avi(pin, tpavi, opt)
18     time.sleep(10)
19     if not os.path.exists(tpavi):
20         if os.path.exists(pin):
21             tpavi=pin
22     avi2mp4(tpavi,tpmp4)
23 def avi2mp4(pin,pout):
24     exe = "MP4Box"
25     dir=os.path.split(pin)[0]
26     title=os.path.split(pin)[1]
27     title=os.path.splitext(title)[0]
28     audiopath=os.path.join(dir,title+"_audio.mp3")
29     videopath=os.path.join(dir,title+"_video.h264")
30     #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
31     exe1=exe+" -aviraw audio \'"+pin+"\'"
32     exe2=exe+" -aviraw video \'"+pin+"\'"
33     exefin=exe+" -new -fps 29.97 -add \'"+videopath+"\'#video -add \'"+audiopath+"\'#audio \'"+pout+"\'"
34     logo=pin.replace(".avi",".log")
35     os.environ['LANG']="ja_JP.UTF-8"
36     txt= exe1+"\n"+exe2+"\n"+exefin+"\n"
37     txt = txt+commands.getoutput(exe1)
38     txt = txt+commands.getoutput(exe2)
39     txt = txt+commands.getoutput(exefin)
40     #os.remove(audiopath)
41     #os.remove(videopath)
42     txt = "\n####MP4Box-log####\n"+txt
43     f=open(logo,'a')
44     f.write(txt)
45     f.close()
46     sys.stdout.flush()
47     time.sleep(10)
48     if os.path.exists(pout):
49         if os.path.exists(audiopath):
50             os.remove(audiopath)
51         if os.path.exists(videopath):
52             os.remove(videopath)
53
54