Improve process_frame_stream logic and ensure safe argument handling in start_ffmpeg_writer
parent
45f284adb6
commit
11d2e93d72
|
@ -263,7 +263,12 @@ 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:
|
||||||
|
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:
|
if STREAM_SOURCE_FACE is None:
|
||||||
source_img = cv2.imread(source_path)
|
source_img = cv2.imread(source_path)
|
||||||
if source_img is not None:
|
if source_img is not None:
|
||||||
|
@ -271,5 +276,3 @@ def process_frame_stream(source_path: str, frame: Frame) -> Frame:
|
||||||
if STREAM_SOURCE_FACE is not None:
|
if STREAM_SOURCE_FACE is not None:
|
||||||
return process_frame(STREAM_SOURCE_FACE, frame)
|
return process_frame(STREAM_SOURCE_FACE, frame)
|
||||||
return frame
|
return frame
|
||||||
else:
|
|
||||||
return process_frame_v2(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:
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue