From 88a53b6f7ed49a945691ee44fde8288dc3ff57ee Mon Sep 17 00:00:00 2001 From: Chaakh Date: Sun, 23 Aug 2026 08:53:20 +0200 Subject: [PATCH 1/4] fix: escape the sendcmd path so TRACK reframing works on Windows reframe_v2 built its filtergraph as sendcmd=f='' 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 ` 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 Claude-Session: https://claude.ai/code/session_01QiYkHKB7Tp7X6NdnEutda2 --- ffmpeg_utils.py | 20 ++++++++++++++++++++ main.py | 12 ++++++++++-- reframe_v2.py | 5 +++-- subtitles.py | 9 +++++++-- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/ffmpeg_utils.py b/ffmpeg_utils.py index 26621b0..b398513 100644 --- a/ffmpeg_utils.py +++ b/ffmpeg_utils.py @@ -154,3 +154,23 @@ def video_encode_args(tier=QUALITY): f"(FFMPEG_ENCODER={mode})") 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("'", "\\'") diff --git a/main.py b/main.py index ec2a2a7..f294524 100644 --- a/main.py +++ b/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" audio_track_path = stem + ".v1audio.aac" 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) print(f"🎬 Processing clip: {input_video}") @@ -1582,7 +1584,13 @@ if __name__ == '__main__': # 2. Decision: Analyze clips or process whole? if args.skip_analysis: 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) else: # Get duration (needed by both the transcript and the vision path). diff --git a/reframe_v2.py b/reframe_v2.py index c12be39..0f180bd 100644 --- a/reframe_v2.py +++ b/reframe_v2.py @@ -26,7 +26,8 @@ import camera_inset import punch_in import screencast_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 @@ -522,7 +523,7 @@ def render(input_video, final_output_video, aspect_ratio, content_ranges=None, with open(cmd_path, "w") as f: f.write("\n".join(lines) + "\n") graph = ( - f"[0:v]sendcmd=f='{cmd_path}'," + f"[0:v]sendcmd=f='{escape_filter_value(cmd_path)}'," f"crop@c={init}," f"scale={out_w}:{out_h},setsar=1[v]" ) diff --git a/subtitles.py b/subtitles.py index baab575..4e8c0e0 100644 --- a/subtitles.py +++ b/subtitles.py @@ -3,7 +3,8 @@ import re import subprocess 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 @@ -100,8 +101,12 @@ def _escape_ffmpeg_filter_value(value): interpolated into a filter. Callers generate their own subtitle filenames, so they control this: use a neutral name (``subs__.ass``), never one 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=''` 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): From 362fe661f95ae3f0bac5b9de912d22cbfc77bb67 Mon Sep 17 00:00:00 2001 From: Chaakh Date: Sun, 23 Aug 2026 10:26:10 +0200 Subject: [PATCH 2/4] fix: spawn main.py with sys.executable, not bare "python" The job runner built its command as ["python", "-u", "main.py"], which resolves against PATH. Inside the Docker image there is exactly one interpreter so it works, but in the documented non-Docker install -- a venv -- PATH points at whatever Python came first, not the one running the server. Every job then dies immediately: ModuleNotFoundError: No module named 'cv2' The CLI works fine in the same checkout, so it presents as "the dashboard is broken" rather than anything to do with interpreters. _run_quality_probe five hundred lines up already uses sys.executable for exactly this reason; this makes the two agree. Verified: same job, same venv, failed before and completed after. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01QiYkHKB7Tp7X6NdnEutda2 --- app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 39a08e4..9897f1b 100644 --- a/app.py +++ b/app.py @@ -1670,7 +1670,11 @@ async def process_endpoint( os.makedirs(job_output_dir, exist_ok=True) # Prepare Command - cmd = ["python", "-u", "main.py"] # -u for unbuffered + # sys.executable, not "python": bare "python" resolves against PATH, which + # outside Docker is whatever interpreter happens to be first — not the venv + # running this server. Every job then dies on `import cv2`. The quality + # probe above already gets this right. + cmd = [sys.executable, "-u", "main.py"] # -u for unbuffered env = os.environ.copy() env["GEMINI_API_KEY"] = api_key # Override with key from request From df0bc19df2e38ec370ca86ecf5da709278d744b1 Mon Sep 17 00:00:00 2001 From: Chaakh Date: Sun, 23 Aug 2026 12:23:06 +0200 Subject: [PATCH 3/4] fix: force UTF-8 on stdio so the server starts on a Windows console MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every log line in app.py is emoji-prefixed and a Windows console is cp1252 by default, so _recover_jobs_from_disk() kills the server during startup: print(f"♻️ Recovered {recovered} completed job(s) from disk.") UnicodeEncodeError: 'charmap' codec can't encode characters in 0-1 ERROR: Application startup failed. Exiting. It never binds a port, so the dashboard is simply unreachable on a stock Windows box. PYTHONIOENCODING=utf-8 works around it, but that has to be known before the first run, and the traceback does not suggest it. subtitles._configure_stdio already does exactly this for the transcription path. The server needs it too, and needs it before the first print, so it runs at module scope rather than in the lifespan hook. Verified: uvicorn with no PYTHONIOENCODING, and an import under a stdout forced to cp1252/strict. Both start and log the emoji correctly. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01QiYkHKB7Tp7X6NdnEutda2 --- app.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app.py b/app.py index 9897f1b..03b5803 100644 --- a/app.py +++ b/app.py @@ -64,6 +64,22 @@ MIN_SOURCE_SECONDS = int(os.environ.get("MIN_SOURCE_SECONDS", "45")) QUALITY_PROBE_SCRIPT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "quality_probe.py") DISABLE_YOUTUBE_URL = os.environ.get("DISABLE_YOUTUBE_URL", "false").lower() in ("1", "true", "yes") +# Every log line in this module is emoji-prefixed, and a Windows console is +# cp1252 by default. _recover_jobs_from_disk() prints one during startup, so +# without this the server dies before it ever listens: +# +# UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1 +# ERROR: Application startup failed. Exiting. +# +# subtitles._configure_stdio solved this for the transcription path; the server +# needs it too, and needs it before the first print. +for _stream in (sys.stdout, sys.stderr): + if hasattr(_stream, "reconfigure"): + try: + _stream.reconfigure(encoding="utf-8", errors="replace") + except Exception: + pass + # ---- Cloud billing (paid / managed-keys) integration -------------------------- # All paid-mode code lives in the optional `cloud/` package and is imported ONLY # when BILLING_ENABLED is set. With the flag off, the app behaves exactly as the From 6e439785c683102df72dc5531618efc5199af0bc Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Mon, 24 Aug 2026 00:32:17 +0200 Subject: [PATCH 4/4] fix: pass PYTHONIOENCODING to the job subprocess too The stdio reconfigure only covers the API process. main.py prints an emoji on its first line and configures nothing, so on a cp1252 console the server now starts but every job dies before rendering. --- app.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app.py b/app.py index 03b5803..fd33bb1 100644 --- a/app.py +++ b/app.py @@ -1693,6 +1693,11 @@ async def process_endpoint( cmd = [sys.executable, "-u", "main.py"] # -u for unbuffered env = os.environ.copy() env["GEMINI_API_KEY"] = api_key # Override with key from request + # The stdio fix above only covers this process. main.py prints an emoji on + # its first line and configures nothing, so on a cp1252 console the child + # still dies before it renders anything -- the server starts and every job + # fails instead. setdefault, so an explicit PYTHONIOENCODING still wins. + env.setdefault("PYTHONIOENCODING", "utf-8") # Optional layouts are per job. The renderer reads these at import time in # the subprocess, so they must be set before Popen — same path WATERMARK