Get video file information with ffmpeg-python

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

Get video file information with ffmpeg-python
Get information with zabbix api
Get Alembic information with Python
YOLP Get map information XML file with Yahoo! Static Map API
Get weather information with Python & scraping
Get property information by scraping with python
Get BITCOIN LTP information with Raspberry PI
[Python] Get Python package information with PyPI API
Get coincheck virtual currency information with API ♪
Get the latest AMI information with the AWS CLI
Get CPU information of Raspberry Pi with Python
Python script to get note information with REAPER
[Linux] Get Linux resource information
[google-oauth] Get user information
File operations with open — "../"
File upload with django
Get started with MicroPython
Get Tweets with Tweepy
Get date with python
Get started with Mezzanine
[Python] Get user information and article information with Qiita API
Get OpenCV video properties
[Python x Zapier] Get alert information and notify with Slack
Try Juniper JUNOS PyEz (python library) Memo 2 ~ Get information with PyEz ~
Get Japanese stock price information from yahoo finance with pandas
Python: Extract file information from shared drive with Google Drive API
Get country code with python
Get table dynamically with sqlalchemy
Trim mp4 video with python-ffmpeg
Get started with Django! ~ Tutorial ⑤ ~
Get Twitter timeline with python
Get started with influxDB + Grafana
Draw netCDF file with python
Get Youtube data with python
YouTube video management with Python 3
Fast file transfer with fabric
Get started with Django! ~ Tutorial ④ ~
Loop video loading with opencv
Visualize location information with Basemap
Get started with Django! ~ Tutorial ⑥ ~
Receive video streaming with Tello
Bidirectional file transfer with Pythonista 3
Get thread ID with python
Get GitHub information using PyGithub
Get started with Python! ~ ② Grammar ~
Get image features with OpenCV
Get stock price with Python
File upload with Flask + jQuery
Get home directory with python
Get keyboard events with python
Download csv file with python
Create xlsx file with XlsxWriter
Get another tab with pyppeteer
Get ranking with Rakuten API
Get OCTA simulation conditions from a file and save with pandas
PhytoMine-I tried to get the genetic information of plants with Python