-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconvert.py
44 lines (35 loc) · 1.29 KB
/
convert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import subprocess
import os
import sys
import optparse
def convert(args):
try:
sys.setdefaultencoding('utf-8')
except:
pass
python_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
currPath = sys.path[0]
highPath = os.path.split(currPath)[0]
env = os.environ.copy()
spliter = ';' if os.name == 'nt' else ':'
env["PATH"] = python_dir + spliter + highPath + spliter + env["PATH"]
parser = optparse.OptionParser(args)
options, args = parser.parse_args()
if (not len(args)):
raise Exception("Missing input file.")
arg0 = os.path.abspath(args[0])
inputvideo = arg0
if (not os.path.isfile(inputvideo)):
raise Exception("Can not open " + inputvideo)
FFMPEG_PARA = \
' -y -hide_banner -loglevel error -stats ' + \
' -c:v mpeg4 -preset slow -b:v 24000k -r 30 -s 1280x720 -acodec aac -strict -2 -ac 2 -ab 256k -ar 44100 -f mp4 '
outputfile = inputvideo + ".cvt.mp4"
print("Convert to " + outputfile)
cmd = "ffmpeg" + ' -i "' + inputvideo + '"' + FFMPEG_PARA + \
'"' + outputfile + '"'
print("Invoking " + cmd)
subprocess.call(cmd, shell=True, env=env)
if __name__ == '__main__':
convert(' '.join(sys.argv[1:]))