diff --git a/modules/processors/frame/face_swapper.py b/modules/processors/frame/face_swapper.py index f38046d..cea0b59 100644 --- a/modules/processors/frame/face_swapper.py +++ b/modules/processors/frame/face_swapper.py @@ -263,13 +263,16 @@ STREAM_SOURCE_FACE = None def process_frame_stream(source_path: str, frame: Frame) -> Frame: global STREAM_SOURCE_FACE - if not modules.globals.map_faces: - if STREAM_SOURCE_FACE is None: - source_img = cv2.imread(source_path) - if source_img is not None: - STREAM_SOURCE_FACE = get_one_face(source_img) - if STREAM_SOURCE_FACE is not None: - return process_frame(STREAM_SOURCE_FACE, frame) - return frame - else: - return process_frame_v2(frame) + if modules.globals.map_faces: + result = process_frame_v2(frame) + if result is not None: + return result + else: + return frame # Fallback to original frame if process_frame_v2 returns None + if STREAM_SOURCE_FACE is None: + source_img = cv2.imread(source_path) + if source_img is not None: + STREAM_SOURCE_FACE = get_one_face(source_img) + if STREAM_SOURCE_FACE is not None: + return process_frame(STREAM_SOURCE_FACE, frame) + return frame diff --git a/modules/utilities.py b/modules/utilities.py index 13bc93b..a146b20 100644 --- a/modules/utilities.py +++ b/modules/utilities.py @@ -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: + # Pass all arguments as a list to avoid shell injection commands = [ "ffmpeg", "-hide_banner", "-hwaccel", "auto", "-loglevel", - modules.globals.log_level, + str(modules.globals.log_level), "-f", "rawvideo", "-pix_fmt", @@ -57,7 +58,7 @@ def start_ffmpeg_writer(width: int, height: int, fps: float, output_path: str) - "-i", "-", "-c:v", - modules.globals.video_encoder, + str(modules.globals.video_encoder), "-crf", str(modules.globals.video_quality), "-pix_fmt", @@ -65,7 +66,7 @@ def start_ffmpeg_writer(width: int, height: int, fps: float, output_path: str) - "-vf", "colorspace=bt709:iall=bt601-6-625:fast=1", "-y", - output_path, + str(output_path), ] return subprocess.Popen(commands, stdin=subprocess.PIPE)