Skip to content

Instantly share code, notes, and snippets.

Last active September 22, 2019 05:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 132ikl/4ce09fbb76fe5f3b605612263146e7e1 to your computer and use it in GitHub Desktop.
Python snippet to get a dict of camera's YUYV available resolutions and corresponding FPS values
import subprocess
import re
sp_out =
"v4l2-ctl -d /dev/video0 --list-formats-ext".split(), capture_output=True
# format and remove newlines/tabs
output = str(sp_out.stdout).replace("\\n", " ").replace("\\t", "")
# get only yuyv results
yuyv ="\[\d+\]: 'YUYV' \(YUYV \d:\d:\d\) (.+)(\[\d+\]?|$)", output).group(1)
# group 1: resolution
# group 2: everything up until next instance of Size
modes = {}
for match in re.finditer("Size: \w+ (\d+x\d+) ", yuyv):
resolution =
# get everything from the current resolution to the next resolution
line = + "(.+?)Size", yuyv).group(1)
fpses = set()
for interval in re.finditer("nterval: \w+ \d+\.\d+s \((.+?) fps\)", line):
modes[resolution] = list(fpses)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment