40 lines
1009 B
Python
40 lines
1009 B
Python
# for import needed
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.append(str(Path(__file__).resolve().parent.parent))
|
|
|
|
from utils import run
|
|
### Normal Imports:
|
|
|
|
def probe_video(path: Path) -> tuple[float, float, str, float]:
|
|
"""
|
|
Get video FPS, duration, codec, and stream start time.
|
|
|
|
Args:
|
|
path: To Video File
|
|
|
|
Returns:
|
|
fps, duration, codec, start_time
|
|
"""
|
|
import json
|
|
cmd = [
|
|
"ffprobe",
|
|
"-v", "error",
|
|
"-print_format", "json",
|
|
"-show_streams",
|
|
"-show_format",
|
|
path
|
|
]
|
|
data = json.loads(run(cmd).stdout)
|
|
|
|
duration = float(data["format"]["duration"])
|
|
for s in data["streams"]:
|
|
if s["codec_type"] == "video":
|
|
num, den = s["r_frame_rate"].split("/")
|
|
fps = float(num) / float(den)
|
|
codec = s["codec_name"]
|
|
start_time = float(s.get("start_time", 0))
|
|
return fps, duration, codec, start_time
|
|
|
|
raise RuntimeError("No video stream found") |