OSDN Git Service

56608cb53037f2bdb0f81a048f90f1beaa6a384a
[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 import configreader
12 def ts2mp4(pin, pout, opt):
13     dir=os.path.split(pout)[0]
14     title=os.path.split(pout)[1]
15     title=os.path.splitext(title)[0]
16     tpavi=os.path.join(dir, title+".avi")
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,pout)
23 def avi2mp4(pin,pout):
24     exe = configreader.getpath(u"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+u"_audio.mp3")
29     videopath=os.path.join(dir,title+u"_video.h264")
30     #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
31     exe1=exe+u" -aviraw audio u'"+pin+u"\'"
32     exe2=exe+u" -aviraw video \'"+pin+u"\'"
33     exefin=exe+u" -new -fps 29.97 -add \'"+videopath+u"\'#video -add \'"+audiopath+u"\'#audio \'"+pout+u"\'"
34     logo=pin.replace(u".avi",u".log")
35     os.environ['LANG']="ja_JP.UTF-8"
36     txt= exe1+u"\n"+exe2+u"\n"+exefin+u"\n"
37     print txt
38     txt = txt+commands.getoutput(exe1.encode('utf-8'))
39     txt = txt+commands.getoutput(exe2.encode('utf-8'))
40     txt = txt+commands.getoutput(exefin.encode('utf-8'))
41     os.remove(audiopath)
42     os.remove(videopath)
43     txt = "\n####MP4Box-log####\n"+txt
44     f=open(logo,'a')
45     f.write(txt)
46     f.close()
47     sys.stdout.flush()
48     time.sleep(10)
49     if os.path.exists(pout):
50         if os.path.exists(audiopath):
51             os.remove(audiopath)
52         if os.path.exists(videopath):
53             os.remove(videopath)
54 def mkv2mp4(pin,pout):
55     exeb = configreader.getpath("mkvextract")
56     exe = configreader.getpath("MP4Box")
57     dir=os.path.split(pin)[0]
58     title=os.path.split(pin)[1]
59     title=os.path.splitext(title)[0]
60     audiopath=os.path.join(dir,title+"_audio.mp3")
61     if not os.path.exists(audiopath):
62         if os.path.exists(os.path.join(dir,title+"_audio.raw")):
63             audiopath=os.path.join(dir,title+"_audio.raw")
64         if os.path.exists(os.path.join(dir,title+"_audio.aac")):
65             audiopath=os.path.join(dir,title+"_audio.aac")
66     videopath=os.path.join(dir,title+"_video.h264")
67     #doexe = exe.encode('utf-8') + u' \"' + pin.encode('utf-8') + u'\" \"' + pout.encode('utf-8') + u'\"'
68     exe0=exeb+" tracks \'"+pin+"\' 1:\'"+videopath+"\' 2:\'"+audiopath+"\'"
69     exe1=exe+" -aviraw audio \'"+pin+"\'"
70     exe2=exe+" -aviraw video \'"+pin+"\'"
71     exefin=exe+" -new -fps 29.97 -add \'"+videopath+"\'#video -add \'"+audiopath+"\'#audio \'"+pout+"\'"
72     logo=pin.replace(".avi",".log")
73     os.environ['LANG']="ja_JP.UTF-8"
74     txt= exe0+"\n"+exe1+"\n"+exe2+"\n"+exefin+"\n"
75     txt = txt+commands.getoutput(exe0.encode('utf-8'))
76     txt = txt+commands.getoutput(exe1.encode('utf-8'))
77     txt = txt+commands.getoutput(exe2.encode('utf-8'))
78     txt = txt+commands.getoutput(exefin.encode('utf-8'))
79     os.remove(audiopath)
80     os.remove(videopath)
81     txt = "\n####MKV2MP4-log####\n"+txt
82     f=open(logo,'a')
83     f.write(txt)
84     f.close()
85     sys.stdout.flush()
86     time.sleep(10)
87     if os.path.exists(pout):
88         if os.path.exists(audiopath):
89             os.remove(audiopath)
90         if os.path.exists(videopath):
91             os.remove(videopath)