Created
December 9, 2021 01:34
-
-
Save raspi/7347d22fcc16471550ebbf80db670717 to your computer and use it in GitHub Desktop.
Get JSON from FFProbe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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