Improve process_frame_stream logic and ensure safe argument handling in start_ffmpeg_writer

pull/1340/head
Christoph9211 2025-06-08 17:00:55 -05:00
parent 45f284adb6
commit 11d2e93d72
2 changed files with 17 additions and 13 deletions

View File

@ -263,13 +263,16 @@ STREAM_SOURCE_FACE = None
def process_frame_stream(source_path: str, frame: Frame) -> Frame: def process_frame_stream(source_path: str, frame: Frame) -> Frame:
global STREAM_SOURCE_FACE global STREAM_SOURCE_FACE
if not modules.globals.map_faces: if modules.globals.map_faces:
if STREAM_SOURCE_FACE is None: result = process_frame_v2(frame)
source_img = cv2.imread(source_path) if result is not None:
if source_img is not None: return result
STREAM_SOURCE_FACE = get_one_face(source_img) else:
if STREAM_SOURCE_FACE is not None: return frame # Fallback to original frame if process_frame_v2 returns None
return process_frame(STREAM_SOURCE_FACE, frame) if STREAM_SOURCE_FACE is None:
return frame source_img = cv2.imread(source_path)
else: if source_img is not None:
return process_frame_v2(frame) STREAM_SOURCE_FACE = get_one_face(source_img)
if STREAM_SOURCE_FACE is not None:
return process_frame(STREAM_SOURCE_FACE, frame)
return frame

View File

@ -39,13 +39,14 @@ def run_ffmpeg(args: List[str]) -> bool:
def start_ffmpeg_writer(width: int, height: int, fps: float, output_path: str) -> subprocess.Popen: def start_ffmpeg_writer(width: int, height: int, fps: float, output_path: str) -> subprocess.Popen:
# Pass all arguments as a list to avoid shell injection
commands = [ commands = [
"ffmpeg", "ffmpeg",
"-hide_banner", "-hide_banner",
"-hwaccel", "-hwaccel",
"auto", "auto",
"-loglevel", "-loglevel",
modules.globals.log_level, str(modules.globals.log_level),
"-f", "-f",
"rawvideo", "rawvideo",
"-pix_fmt", "-pix_fmt",
@ -57,7 +58,7 @@ def start_ffmpeg_writer(width: int, height: int, fps: float, output_path: str) -
"-i", "-i",
"-", "-",
"-c:v", "-c:v",
modules.globals.video_encoder, str(modules.globals.video_encoder),
"-crf", "-crf",
str(modules.globals.video_quality), str(modules.globals.video_quality),
"-pix_fmt", "-pix_fmt",
@ -65,7 +66,7 @@ def start_ffmpeg_writer(width: int, height: int, fps: float, output_path: str) -
"-vf", "-vf",
"colorspace=bt709:iall=bt601-6-625:fast=1", "colorspace=bt709:iall=bt601-6-625:fast=1",
"-y", "-y",
output_path, str(output_path),
] ]
return subprocess.Popen(commands, stdin=subprocess.PIPE) return subprocess.Popen(commands, stdin=subprocess.PIPE)