-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coder.py
executable file
·73 lines (63 loc) · 1.57 KB
/
Coder.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
import subprocess
import sys
import re
def main(argv=sys.argv):
if len(sys.argv) == 1 or sys.argv[1] == "-h" or sys.argv[1] == "--help":
for line in open('help','r'):
print line,
else:
infile = sys.argv[1]
outfile = sys.argv[2]
st = ""
length = ""
height = ""
width = ""
origw = ""
origh = ""
out = subprocess.Popen(["ffmpeg","-i",infile], stderr = subprocess.STDOUT, stdout = subprocess.PIPE)
for i in iter(out.stdout.readline, ""):
k = i.find("DAR")
if k > -1:
j = k + 4
while i[j].isdigit():
origw = origw + i[j]
j = j + 1
j = j + 1
while i[j].isdigit():
origh = origh + i[j]
j = j + 1
origasp = float(origw)/float(origh)
s = ["ffmpeg",
"-i", infile,
"-f", "mp4",
"-acodec", "libfaac",
"-vcodec", "libx264",
"-threads", "2",
"-y"]
for i in sys.argv :
if re.match("\d\d:\d\d:\d\d", i):
if st == "" :
st = i
else:
length = i
for i in sys.argv :
if i.isdigit() :
if width == "" :
width = i
else:
height = i
if st != "" and length != "":
s = s + ["-ss", st, "-t", length]
if width != "" and height != "":
asp = float(width)/float(height)
if asp < origasp:
height = str(int(float(width) / float(origw) * float(origh)))
else:
width = str(int(float(height) / float(origh) * float(origw)))
s = s + ["-s",width+'x'+height]
print s
s = s + [outfile]
print subprocess.Popen(s, stderr = subprocess.STDOUT, stdout = subprocess.PIPE).communicate()
if __name__ == "__main__":
main()