V 1.0 - Only Prints
This commit is contained in:
commit
e00fa1ca80
15 files changed
+1045
No files matched your search
@@ -0,0 +1,40 @@
|
||||
# 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")
|
||||
Reference in new issue
Block a user