A lot of bug fixes and edge cases
This commit is contained in:
1 parent
3e81425f84
commit
525b9d4dc6
5 files changed
+236
-105
No files matched your search
+20
-12
@@ -7,28 +7,36 @@ sys.path.append(str(Path(__file__).resolve().parent.parent))
|
||||
from utils import run
|
||||
### Normal Imports:
|
||||
|
||||
from subprocess import run, PIPE
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
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
|
||||
str(path), # IMPORTANT
|
||||
]
|
||||
data = json.loads(run(cmd).stdout)
|
||||
|
||||
result = run(cmd, stdout=PIPE, stderr=PIPE, text=True)
|
||||
|
||||
if result.returncode != 0:
|
||||
raise RuntimeError(f"ffprobe failed:\n{result.stderr}")
|
||||
|
||||
if not result.stdout.strip():
|
||||
raise RuntimeError("ffprobe returned empty output")
|
||||
|
||||
try:
|
||||
data = json.loads(result.stdout)
|
||||
except json.JSONDecodeError as e:
|
||||
print("RAW OUTPUT:\n", result.stdout) # debug
|
||||
raise
|
||||
|
||||
duration = float(data["format"]["duration"])
|
||||
|
||||
for s in data["streams"]:
|
||||
if s["codec_type"] == "video":
|
||||
num, den = s["r_frame_rate"].split("/")
|
||||
|
||||
Reference in new issue
Block a user