Skip to content

Instantly share code, notes, and snippets.

@raspi
Created December 9, 2021 01:34
Show Gist options
  • Save raspi/7347d22fcc16471550ebbf80db670717 to your computer and use it in GitHub Desktop.
Save raspi/7347d22fcc16471550ebbf80db670717 to your computer and use it in GitHub Desktop.
Get JSON from FFProbe
import json
import subprocess
from pathlib import Path
def ffprobe(path: Path):
cmd = [
"ffprobe",
"-v", "error",
"-select_streams", "v",
"-show_entries", "format=filename:stream=height",
"-of", "json",
path.absolute(),
]
result = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
if result.returncode != 0:
raise RuntimeError(result.stderr)
return json.loads(result.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment