OSDN Git Service

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