Skip to content

Instantly share code, notes, and snippets.

Last active March 2, 2023 22:33
  • Star 40 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A python function utilising `ffprobe` to find any metadata related to a video file. Examples of what it can find include bitrate, fps, codec details, duration and many more. This gist returns the video height and width as an example.
import subprocess
import shlex
import json
# function to find the resolution of the input video file
def findVideoMetada(pathToInputVideo):
cmd = "ffprobe -v quiet -print_format json -show_streams"
args = shlex.split(cmd)
# run the ffprobe process, decode stdout into utf-8 & convert to JSON
ffprobeOutput = subprocess.check_output(args).decode('utf-8')
ffprobeOutput = json.loads(ffprobeOutput)
# prints all the metadata available:
import pprint
pp = pprint.PrettyPrinter(indent=2)
# for example, find height and width
height = ffprobeOutput['streams'][0]['height']
width = ffprobeOutput['streams'][0]['width']
print(height, width)
return height, width
Copy link

How to get fps?

Copy link

Thanks for this

Copy link

Thank you for making this. This is helping me a bunch with working on a plugin

Copy link

Elishai commented Mar 2, 2019

looking great but i got "OSError: [WinError 6] The handle is invalid".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment