fix: escape the sendcmd path so TRACK reframing works on Windows
reframe_v2 built its filtergraph as sendcmd=f='<abs path>' with the path interpolated raw. On Windows tempfile.mkdtemp() returns C:\Users\..., and the drive colon terminates the filter option, so ffmpeg exits non-zero and every TRACK scene silently falls back to the v1 Python frame loop. GENERAL and SPLIT hide the bug because only the TRACK branch emits a sendcmd. subtitles._escape_ffmpeg_filter_value already solved exactly this for the ass/fontsdir filter three modules away, so this moves it to ffmpeg_utils as escape_filter_value() and uses it in both places. subtitles keeps its wrapper and its docstring; behaviour there is unchanged (verified equal output on absolute, relative and space/comma paths). Measured on a 12s 1280x720 clip with one face, Windows 10 + ffmpeg 9: before 53.5s "Reframe v2 failed (CalledProcessError ...)" -> v1 loop after 30.8s v2 native, same framing Also: `-o <dir>` crashed with PermissionError [WinError 5] because --skip-analysis passed the directory straight through as the output filename and it reached os.remove(). --output is documented as "directory or file", so derive the filename when it names a directory, and guard the stale-file sweep with isfile() so a directory can never be handed to os.remove(). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QiYkHKB7Tp7X6NdnEutda2
This commit is contained in:
parent
e0fa3fd591
commit
88a53b6f7e
4 changed files with 40 additions and 6 deletions
|
|
@ -154,3 +154,23 @@ def video_encode_args(tier=QUALITY):
|
||||||
f"(FFMPEG_ENCODER={mode})")
|
f"(FFMPEG_ENCODER={mode})")
|
||||||
|
|
||||||
return list((_NVENC_ARGS if use_nvenc else _X264_ARGS)[tier])
|
return list((_NVENC_ARGS if use_nvenc else _X264_ARGS)[tier])
|
||||||
|
|
||||||
|
|
||||||
|
def escape_filter_value(value):
|
||||||
|
r"""Escape a path/value for use inside a quoted FFmpeg filter argument.
|
||||||
|
|
||||||
|
Windows absolute paths are why this exists: ``:`` separates filter options,
|
||||||
|
so an interpolated ``C:/x/y.txt`` makes the parser look for an option named
|
||||||
|
``/x/y.txt`` and the whole filtergraph fails to build.
|
||||||
|
|
||||||
|
NOTE: an apostrophe in the path cannot be made safe here. ffmpeg's
|
||||||
|
filtergraph parser is not a shell -- the shell idiom ``'\''`` was tried on
|
||||||
|
29-jul-2026 and is worse than doing nothing: it drops the apostrophe AND
|
||||||
|
swallows the following option, so ``ass='...Earth'\''s.ass':fontsdir='...'``
|
||||||
|
resolved to a filename of "...Earths.ass:fontsdir=..." and failed to open.
|
||||||
|
|
||||||
|
The only reliable answer is to keep apostrophes OUT of any path that is
|
||||||
|
interpolated into a filter. Callers generate their own filenames, so they
|
||||||
|
control this: use a neutral name, never one derived from a video title.
|
||||||
|
"""
|
||||||
|
return value.replace('\\', '/').replace(':', '\\:').replace("'", "\\'")
|
||||||
|
|
|
||||||
12
main.py
12
main.py
|
|
@ -1084,7 +1084,9 @@ def process_video_to_vertical(input_video, final_output_video, aspect_ratio=ASPE
|
||||||
silent_video_path = stem + ".v1video.mp4"
|
silent_video_path = stem + ".v1video.mp4"
|
||||||
audio_track_path = stem + ".v1audio.aac"
|
audio_track_path = stem + ".v1audio.aac"
|
||||||
for stale in (silent_video_path, audio_track_path, final_output_video):
|
for stale in (silent_video_path, audio_track_path, final_output_video):
|
||||||
if os.path.exists(stale):
|
# isfile, not exists: a caller that hands us a directory should not
|
||||||
|
# take an EACCES here, and must never have it deleted either.
|
||||||
|
if os.path.isfile(stale):
|
||||||
os.remove(stale)
|
os.remove(stale)
|
||||||
|
|
||||||
print(f"🎬 Processing clip: {input_video}")
|
print(f"🎬 Processing clip: {input_video}")
|
||||||
|
|
@ -1582,7 +1584,13 @@ if __name__ == '__main__':
|
||||||
# 2. Decision: Analyze clips or process whole?
|
# 2. Decision: Analyze clips or process whole?
|
||||||
if args.skip_analysis:
|
if args.skip_analysis:
|
||||||
print("⏩ Skipping analysis, processing entire video...")
|
print("⏩ Skipping analysis, processing entire video...")
|
||||||
output_file = args.output if args.output else os.path.join(output_dir, f"{video_title}_vertical.mp4")
|
# --output is documented as "directory or file". When it names a
|
||||||
|
# directory we still need a filename: passing the directory through
|
||||||
|
# ends up in os.remove() on it further down and dies with EACCES.
|
||||||
|
output_file = args.output
|
||||||
|
if (not output_file or os.path.isdir(output_file)
|
||||||
|
or output_file.endswith(("/", os.sep))):
|
||||||
|
output_file = os.path.join(output_dir, f"{video_title}_vertical.mp4")
|
||||||
render_clip(input_video, output_file, output_format)
|
render_clip(input_video, output_file, output_format)
|
||||||
else:
|
else:
|
||||||
# Get duration (needed by both the transcript and the vision path).
|
# Get duration (needed by both the transcript and the vision path).
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ import camera_inset
|
||||||
import punch_in
|
import punch_in
|
||||||
import screencast_layout
|
import screencast_layout
|
||||||
import split_layout
|
import split_layout
|
||||||
from ffmpeg_utils import video_encode_args, QUALITY_FAST, METADATA_SCRUB
|
from ffmpeg_utils import (video_encode_args, escape_filter_value, QUALITY_FAST,
|
||||||
|
METADATA_SCRUB)
|
||||||
|
|
||||||
ANALYSIS_MAX_WIDTH = 640
|
ANALYSIS_MAX_WIDTH = 640
|
||||||
|
|
||||||
|
|
@ -522,7 +523,7 @@ def render(input_video, final_output_video, aspect_ratio, content_ranges=None,
|
||||||
with open(cmd_path, "w") as f:
|
with open(cmd_path, "w") as f:
|
||||||
f.write("\n".join(lines) + "\n")
|
f.write("\n".join(lines) + "\n")
|
||||||
graph = (
|
graph = (
|
||||||
f"[0:v]sendcmd=f='{cmd_path}',"
|
f"[0:v]sendcmd=f='{escape_filter_value(cmd_path)}',"
|
||||||
f"crop@c={init},"
|
f"crop@c={init},"
|
||||||
f"scale={out_w}:{out_h},setsar=1[v]"
|
f"scale={out_w}:{out_h},setsar=1[v]"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ffmpeg_utils import video_encode_args, QUALITY, METADATA_SCRUB
|
from ffmpeg_utils import (video_encode_args, escape_filter_value, QUALITY,
|
||||||
|
METADATA_SCRUB)
|
||||||
|
|
||||||
|
|
||||||
_STDIO_CONFIGURED = False
|
_STDIO_CONFIGURED = False
|
||||||
|
|
@ -100,8 +101,12 @@ def _escape_ffmpeg_filter_value(value):
|
||||||
interpolated into a filter. Callers generate their own subtitle filenames,
|
interpolated into a filter. Callers generate their own subtitle filenames,
|
||||||
so they control this: use a neutral name (``subs_<i>_<ts>.ass``), never one
|
so they control this: use a neutral name (``subs_<i>_<ts>.ass``), never one
|
||||||
derived from a video title.
|
derived from a video title.
|
||||||
|
|
||||||
|
The implementation now lives in ffmpeg_utils so the reframe engine can use
|
||||||
|
it too: it was building `sendcmd=f='<abs path>'` unescaped, which is the
|
||||||
|
same bug this function was written for.
|
||||||
"""
|
"""
|
||||||
return value.replace('\\', '/').replace(':', '\\:').replace("'", "\\'")
|
return escape_filter_value(value)
|
||||||
|
|
||||||
|
|
||||||
def _normalize_subtitle_word(value):
|
def _normalize_subtitle_word(value):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue