Enhance Avisynth video workflow and metadata tools

This commit is contained in:
ajp_anton
2026-07-30 03:20:19 +00:00
parent d60ce51b14
commit 100cad1cb5
26 changed files with 2350 additions and 1161 deletions
+23 -5
View File
@@ -5,6 +5,7 @@ from pathlib import Path
from tools.avisynth_render import AvisynthClipInfo
from tools.video_encode_output import AudioEncodeOptions
from tools.video_formatting import rate_value
from tools.video_probe import VideoProbe
from tools.video_timeline import OutputTimeline
@@ -24,10 +25,6 @@ def preserves_entire_source_timeline(timeline: OutputTimeline) -> bool:
)
def missing_source_frames_between_kept(timeline: OutputTimeline) -> int:
return missing_source_frames([frame.source_frame for frame in timeline.frames])
def missing_source_frames(source_frames: list[int]) -> int:
missing = 0
for previous, current in zip(source_frames, source_frames[1:]):
@@ -106,14 +103,35 @@ def encoded_duration_seconds(
def has_avisynth_speed_changes(
timelines: dict[Path, OutputTimeline],
clip_infos: dict[Path, AvisynthClipInfo],
probes_by_path: dict[Path, VideoProbe],
) -> bool:
for path, timeline in timelines.items():
clip_info = clip_infos.get(path)
if clip_info is not None and avisynth_duration_differs(clip_info, timeline):
if clip_info is None or not avisynth_duration_differs(clip_info, timeline):
continue
probe = probes_by_path.get(path)
if probe is not None and _matches_source_rate(clip_info, probe):
continue
if clip_info.duration_seconds is not None:
return True
return False
def _matches_source_rate(clip_info: AvisynthClipInfo, probe: VideoProbe) -> bool:
if clip_info.fps_num <= 0 or clip_info.fps_den <= 0:
return False
clip_rate = clip_info.fps_num / clip_info.fps_den
source_rates = [
rate_value(probe.avg_frame_rate),
rate_value(probe.r_frame_rate),
]
return any(
rate is not None and abs(clip_rate - rate) / rate <= 0.005
for rate in source_rates
if rate is not None and rate > 0
)
def audio_tempo_factor(timeline: OutputTimeline, output_duration: float) -> float:
if output_duration <= 0:
raise RuntimeError("Encoded output duration must be positive")