forked from kkroening/ffmpeg-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_info.py
executable file
·31 lines (24 loc) · 921 Bytes
/
video_info.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
#!/usr/bin/env python
from __future__ import unicode_literals, print_function
import argparse
import ffmpeg
import sys
parser = argparse.ArgumentParser(description='Get video information')
parser.add_argument('in_filename', help='Input filename')
if __name__ == '__main__':
args = parser.parse_args()
try:
probe = ffmpeg.probe(args.in_filename)
except ffmpeg.Error as e:
print(e.stderr, file=sys.stderr)
sys.exit(1)
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
if video_stream is None:
print('No video stream found', file=sys.stderr)
sys.exit(1)
width = int(video_stream['width'])
height = int(video_stream['height'])
num_frames = int(video_stream['nb_frames'])
print('width: {}'.format(width))
print('height: {}'.format(height))
print('num_frames: {}'.format(num_frames))