From 2816e6c0e6a9aace8c06c1751bab2ba81e60a3b3 Mon Sep 17 00:00:00 2001 From: FishCat233 <50800434+FishCat233@users.noreply.github.com> Date: Mon, 12 Jan 2026 15:50:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(export):=20=E6=8D=95=E8=8E=B7=E5=B9=B6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95FFmpeg=E5=AD=90=E8=BF=9B=E7=A8=8B=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对FFmpeg子进程stdout和stderr输出的捕获功能,并将其记录到日志中。同时为命令头添加-nostats参数以减少不必要的输出。 --- src/export/core.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/export/core.py b/src/export/core.py index 8b92aa1..2b52d65 100644 --- a/src/export/core.py +++ b/src/export/core.py @@ -48,14 +48,36 @@ def export(task: ExportTask) -> bool: logging.info("导出命令: %s", command) - # 执行命令 + # 执行命令并捕获输出 try: - subprocess.run( - command, shell=False, check=True, creationflags=subprocess.CREATE_NO_WINDOW + result = subprocess.run( + command, + shell=False, + check=True, + capture_output=True, # 捕获stdout和stderr + text=True, # 以文本模式捕获输出 + encoding="utf-8", # 使用UTF-8编码 + errors="replace", # 替换无法解码的字符 + creationflags=subprocess.CREATE_NO_WINDOW, ) + + # 将子进程输出写入日志 + if result.stdout: + logging.info(f"FFmpeg stdout: {result.stdout}") + if result.stderr: + logging.info( + f"FFmpeg stderr: {result.stderr}" + ) # 使用info级别记录,因为ffmpeg通常在stderr输出进度 + logging.info("export one success") return True except subprocess.CalledProcessError as e: + # 捕获错误输出 + if e.stdout: + logging.error(f"FFmpeg stdout (error): {e.stdout}") + + logging.error(f"FFmpeg stderr (error): {e.stderr}") + logging.error("export one failed with error: {:?}", e) return False @@ -69,7 +91,7 @@ def build_command_header(ffmpeg_path: str) -> str: Returns: str: 构建后的ffmpeg命令头字符串 """ - return ffmpeg_path + " -y" + return ffmpeg_path + " -y -nostats" def build_command_header_without_executeable() -> str: @@ -78,7 +100,7 @@ def build_command_header_without_executeable() -> str: Returns: str: 构建后的不带执行文件路径的ffmpeg命令头字符串 """ - return " -y" + return " -y -nostats" def build_video_input(video_file: VideoFile) -> str: