How to get video information in a dictionary for each stream using ffmpeg-python. Install ffmpeg and ffmpeg-python in advance.
get_video_info.py
import sys
from pprint import pprint
import ffmpeg
in_filename = sys.argv[1]
probe = ffmpeg.probe(in_filename)
for stream in probe['streams']:
print('stream {0}: {1}'.format(stream['index'],stream['codec_type']))
pprint(stream) #Python3.8 to sort_dicts=False can be used
print('')
Execution result
$ python get_video_info.py "sample.mp4"
stream 0: video
{'avg_frame_rate': '30000/1001',
'chroma_location': 'left',
'codec_long_name': 'MPEG-2 video',
…abridgement…
'width': 1440}
stream 1: audio
{'avg_frame_rate': '0/0',
'bit_rate': '255750',
'bits_per_sample': 0,
'channel_layout': 'stereo',
…abridgement…
'time_base': '1/90000'}
stream 2: subtitle
{'avg_frame_rate': '0/0',
'codec_long_name': 'ARIB STD-B24 caption',
'codec_name': 'arib_caption',
…abridgement…
'time_base': '1/90000'}
Recommended Posts