8000 Add video_info example · monir-dev/ffmpeg-python@6274e7a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6274e7a

Browse files
committed
Add video_info example
1 parent e1dded8 commit 6274e7a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

examples/video_info.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
from __future__ import unicode_literals, print_function
3+
import argparse
4+
import ffmpeg
5+
import sys
6+
7+
8+
parser = argparse.ArgumentParser(description='Get video information')
9+
parser.add_argument('in_filename', help='Input filename')
10+
11+
12+
if __name__ == '__main__':
13+
args = parser.parse_args()
14+
probe = ffmpeg.probe(args.in_filename)
15+
video_info = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
16+
if video_info is None:
17+
print('No video stream found', file=sys.stderr)
18+
sys.exit(1)
19+
20+
width = int(video_info['width'])
21+
height = int(video_info['height'])
22+
num_frames = int(video_info['nb_frames'])
23+
print('width: {}'.format(width))
24+
print('height: {}'.format(height))
25+
print('num_frames: {}'.format(num_frames))

0 commit comments

Comments
 (0)
0