Improve process_frame_stream logic and ensure safe argument handling in start_ffmpeg_writer
parent
45f284adb6
commit
11d2e93d72
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue