-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmediainfo.py
executable file
·59 lines (42 loc) · 1.65 KB
/
mediainfo.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
#!/usr/bin/python
import sys
import subprocess
import re
import time
#APP_NAME = 'mediainfo'
# if len(sys.argv) < 2:
# print 'Shows media info about input file.\n Usage:', APP_NAME, '<media file>'
# sys.exit()
#
# infile = sys.argv[1]
#Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 21389 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 1200 tbc
#Stream #0.*?(\d+(?:\.\d+))
#Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720, 4817 kb/s, 14 fps, 14 tbr, 600 tbn, 1200 tbc
#Stream #0.*?(\d+(?:\.\d+)?)\s*fps
def get_frames(infile):
args = ['ffmpeg', '-i', infile]
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
pattern1 = re.compile(r'Duration: (\d\d):(\d\d):(\d\d)')
match = pattern1.search(stderr)
hours = int(match.groups()[0])
minutes = int(match.groups()[1])
seconds = int(match.groups()[2])
total_seconds = hours * 3600 + minutes * 60 + seconds
pattern2 = re.compile(r'Stream #0.*?(\d+(?:\.\d+)?)\s*fps')
match = pattern2.search(stderr)
fps = float(match.groups()[0])
return total_seconds * fps
def get_fps(infile):
args = ['ffmpeg', '-i', infile]
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
pattern1 = re.compile(r'Stream #0.*?(\d+(?:\.\d+)?)\s*fps')
match = pattern1.search(stderr)
fps = float(match.groups()[0])
return fps
def get_length_str(frames, fps):
total_seconds = frames / fps
return time.strftime('%H:%M:%S', time.gmtime(total_seconds))
# frames = get_frames(infile)
# print frames