-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathffprobe.py
More file actions
31 lines (30 loc) · 1.07 KB
/
ffprobe.py
File metadata and controls
31 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess
import json
def FFprobe(file_path:str):
"""
Runs ffprobe on a file and returns the output as a Python dictionary.
"""
command_array = [
"ffprobe",
"-v", "quiet", # Suppress logging to stderr
"-print_format", "json", # Output in JSON format
"-show_format", # Show format information
"-show_streams", # Show stream information
str(file_path) # File path
]
try:
result = subprocess.run(
command_array,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True, # For Python 3.7+; use universal_newlines=True for older versions
check=True # Raise CalledProcessError if the command fails
)
return json.loads(result.stdout)
except subprocess.CalledProcessError as e:
print(f"Error running ffprobe: {e}")
print(f"Stderr: {e.stderr}")
return None
except FileNotFoundError:
print("Error: ffprobe command not found. Make sure it's installed and in your PATH.")
return None