Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix: decode subprocess output as UTF-8 instead of the system locale

britorja5b4a397c3bc
diff --git a/app/services/elevenlabs_music.py b/app/services/elevenlabs_music.py
index 5eae088b..a88a89df 100644
--- a/app/services/elevenlabs_music.py
+++ b/app/services/elevenlabs_music.py
@@ -237,6 +237,8 @@ def _create_video_proxy(video_path: str) -> str:
command,
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=600,
check=False,
)
diff --git a/app/services/llm.py b/app/services/llm.py
index d66b1b39..5888d1ed 100644
--- a/app/services/llm.py
+++ b/app/services/llm.py
@@ -530,6 +530,12 @@ def _generate_response(prompt: str, app_config=None) -> str:
command,
capture_output=True,
text=True,
+ # The CLI always emits UTF-8. Without an explicit encoding,
+ # text=True decodes with the system locale (e.g. cp1252 on
+ # non-English Windows), so every non-ASCII character reaches
+ # the script as mojibake.
+ encoding="utf-8",
+ errors="replace",
timeout=timeout_seconds,
cwd=work_dir,
env=cli_env,
diff --git a/app/services/sonilo.py b/app/services/sonilo.py
index b2bb9df9..0fe9d3ca 100644
--- a/app/services/sonilo.py
+++ b/app/services/sonilo.py
@@ -177,6 +177,8 @@ def _create_video_proxy(video_path: str) -> str:
command,
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
timeout=600,
check=False,
)
diff --git a/app/services/video.py b/app/services/video.py
index 7689c1f3..7b9dea41 100644
--- a/app/services/video.py
+++ b/app/services/video.py
@@ -312,6 +312,8 @@ def _ffmpeg_encoder_exists(ffmpeg_binary: str, codec: str) -> bool:
[ffmpeg_binary, "-hide_banner", "-encoders"],
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
check=False,
timeout=10,
)
@@ -472,7 +474,7 @@ def _run_concat_with_heartbeat(command: list[str], output_file: str):
reporter = threading.Thread(target=log_heartbeat, daemon=True)
reporter.start()
try:
- return subprocess.run(command, capture_output=True, text=True, check=False)
+ return subprocess.run(command, capture_output=True, text=True, encoding="utf-8", errors="replace", check=False)
finally:
stop_event.set()
diff --git a/app/services/voice.py b/app/services/voice.py
index 95770747..09373a63 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -570,6 +570,8 @@ def generate_silent_audio(duration_seconds: float, output_file: str) -> bool:
command,
capture_output=True,
text=True,
+ encoding="utf-8",
+ errors="replace",
check=False,
)
if result.returncode != 0:
@@ -764,7 +766,7 @@ def _concat_audio_files(audio_files: list[str], output_file: str) -> bool:
"pcm_s16le",
pcm_wav,
]
- res = subprocess.run(cmd, capture_output=True, text=True, check=False)
+ res = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace", check=False)
if res.returncode == 0 and os.path.exists(pcm_wav):
try:
with wave.open(pcm_wav, "rb") as wf:
@@ -800,7 +802,7 @@ def _concat_audio_files(audio_files: list[str], output_file: str) -> bool:
"4",
output_file,
]
- result = subprocess.run(command, capture_output=True, text=True, check=False)
+ result = subprocess.run(command, capture_output=True, text=True, encoding="utf-8", errors="replace", check=False)
if result.returncode != 0:
logger.error(
"failed to encode concatenated audio to mp3: "
@@ -912,7 +914,7 @@ def _tts_with_pauses(
"pcm_s16le",
chunk_wav,
]
- res = subprocess.run(cmd, capture_output=True, text=True, check=False)
+ res = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace", check=False)
if res.returncode != 0 or not os.path.exists(chunk_wav) or os.path.getsize(chunk_wav) == 0:
logger.error(
f"failed to decode speech chunk audio to PCM WAV: {speech_text[:50]}, "
diff --git a/test/services/test_video.py b/test/services/test_video.py
index 195e2177..b16e0706 100644
--- a/test/services/test_video.py
+++ b/test/services/test_video.py
@@ -634,7 +634,7 @@ class TestVideoService(unittest.TestCase):
"""
config.app["video_codec"] = "h264_nvenc"
- def fake_run(command, capture_output, text, check):
+ def fake_run(command, capture_output, text, check, **kwargs):
codec_index = command.index("-c:v") + 1
codec = command[codec_index]
if codec == "h264_nvenc":
@@ -673,7 +673,7 @@ class TestVideoService(unittest.TestCase):
"""
config.app["video_codec"] = "h264_nvenc"
- def fake_run(command, capture_output, text, check):
+ def fake_run(command, capture_output, text, check, **kwargs):
codec_index = command.index("-c:v") + 1
codec = command[codec_index]
return types.SimpleNamespace(
@@ -964,7 +964,7 @@ class TestVideoService(unittest.TestCase):
def test_concat_video_clips_limits_output_to_audio_duration(self):
"""最终拼接时应裁到音频时长,避免安全余量带来明显静音尾巴。"""
- def fake_run(command, capture_output, text, check):
+ def fake_run(command, capture_output, text, check, **kwargs):
return types.SimpleNamespace(returncode=0, stdout="", stderr="")
with tempfile.TemporaryDirectory() as temp_dir:
@@ -991,7 +991,7 @@ class TestVideoService(unittest.TestCase):
无法区分仍在编码与已经卡死(issue #1342)。等待期间必须记录存活信息。
"""
- def slow_run(command, capture_output, text, check):
+ def slow_run(command, capture_output, text, check, **kwargs):
# 模拟一次耗时拼接:这段窗口内心跳线程应至少记录一次存活日志。
time.sleep(0.2)
return types.SimpleNamespace(returncode=0, stdout="", stderr="")
diff --git a/test/services/test_voice.py b/test/services/test_voice.py
index ca543fb7..631dc18c 100644
--- a/test/services/test_voice.py
+++ b/test/services/test_voice.py
@@ -102,7 +102,7 @@ class TestVoiceService(unittest.TestCase):
视频合成链路的预期。
"""
- def fake_run(command, capture_output, text, check):
+ def fake_run(command, capture_output, text, check, **kwargs):
self.assertEqual(command[0], "/tmp/fake-ffmpeg")
self.assertIn("anullsrc=r=44100:cl=mono", command)
Path(command[-1]).write_bytes(b"fake-silent-mp3")