ffmpeg fix

This commit is contained in:
2026-04-03 09:28:03 -03:00
parent 36e8358fc9
commit 3f76670169
5 changed files with 138 additions and 19 deletions

View File

@@ -72,27 +72,23 @@ def extract_scene_frames(input_path, output_dir, scene_threshold=0.10,
meaningfully vs the previous frame. No periodic fallback so static content
produces no spurious frames.
start_time/duration: applied via the select filter expression (NOT as -ss/-t
input options, which break h264 scene detection on MKV).
Uses -ss input seeking for O(1) startup regardless of file size.
pts_time in showinfo output is relative to the seek point.
Returns (stdout, stderr) as decoded strings for timestamp parsing.
"""
scene_expr = f"gt(scene,{scene_threshold})"
# Add time range filter if specified (incremental processing)
time_conditions = []
if start_time > 0:
time_conditions.append(f"gte(t,{start_time})")
# With -ss input seeking, t starts at 0 from the seek point.
# Only need end boundary (duration), start is handled by -ss.
if duration is not None:
time_conditions.append(f"lte(t,{start_time + duration})")
scene_expr = f"({scene_expr})*lte(t,{duration})"
if time_conditions:
time_filter = "*".join(time_conditions)
select_expr = f"({scene_expr})*{time_filter}"
else:
select_expr = scene_expr
input_kwargs = {}
if start_time > 0:
input_kwargs["ss"] = start_time
stream = ffmpeg.input(str(input_path))
stream = stream.filter("select", select_expr).filter("showinfo")
stream = ffmpeg.input(str(input_path), **input_kwargs)
stream = stream.filter("select", scene_expr).filter("showinfo")
output = (
ffmpeg.output(