利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix: resolve bundled ffmpeg binary for video concat
Harrycd0d1b1a87fd
diff --git a/app/services/video.py b/app/services/video.pyindex 094daaf9..c4c78c0c 100644--- a/app/services/video.py+++ b/app/services/video.py@@ -56,8 +56,26 @@ fps = 30def get_ffmpeg_binary():- # 优先复用配置里显式指定的 ffmpeg,可避免不同环境下 PATH 不一致。- return os.environ.get("IMAGEIO_FFMPEG_EXE") or "ffmpeg"+ # 优先复用用户在 config.toml / 环境变量里显式指定的 ffmpeg,可避免+ # Windows 便携包、Docker、自定义安装目录等场景下 PATH 不一致。+ configured_ffmpeg = os.environ.get("IMAGEIO_FFMPEG_EXE")+ if configured_ffmpeg:+ return configured_ffmpeg++ system_ffmpeg = shutil.which("ffmpeg")+ if system_ffmpeg:+ return system_ffmpeg++ try:+ import imageio_ffmpeg++ bundled_ffmpeg = imageio_ffmpeg.get_ffmpeg_exe()+ if bundled_ffmpeg:+ return bundled_ffmpeg+ except Exception as exc:+ logger.warning(f"failed to resolve bundled ffmpeg binary: {str(exc)}")++ return "ffmpeg"def _escape_ffmpeg_concat_path(file_path: str) -> str:diff --git a/test/services/test_video.py b/test/services/test_video.pyindex d204acc5..17cf464a 100644--- a/test/services/test_video.py+++ b/test/services/test_video.py@@ -2,7 +2,9 @@import unittestimport osimport sys+import typesfrom pathlib import Path+from unittest.mock import patchfrom moviepy import (VideoFileClip,)@@ -46,6 +48,25 @@ class TestVideoService(unittest.TestCase):# clean generated test video fileif os.path.exists(materials[0].url):os.remove(materials[0].url)++ def test_get_ffmpeg_binary_uses_configured_env_path(self):+ """配置中显式指定 ffmpeg 时,应优先使用该路径。"""+ with patch.dict(os.environ, {"IMAGEIO_FFMPEG_EXE": "/tmp/custom-ffmpeg"}, clear=True):+ self.assertEqual(vd.get_ffmpeg_binary(), "/tmp/custom-ffmpeg")++ def test_get_ffmpeg_binary_falls_back_to_imageio_ffmpeg(self):+ """+ Windows 便携包里系统 PATH 可能没有 ffmpeg,但 moviepy 依赖的+ imageio-ffmpeg 通常会提供可执行文件。这里验证该兜底路径可用。+ """+ fake_imageio_ffmpeg = types.SimpleNamespace(+ get_ffmpeg_exe=lambda: "/tmp/bundled-ffmpeg"+ )++ with patch.dict(os.environ, {}, clear=True), patch.object(+ vd.shutil, "which", return_value=None+ ), patch.dict(sys.modules, {"imageio_ffmpeg": fake_imageio_ffmpeg}):+ self.assertEqual(vd.get_ffmpeg_binary(), "/tmp/bundled-ffmpeg")def test_wrap_text(self):"""test text wrapping function"""@@ -82,4 +103,4 @@ class TestVideoService(unittest.TestCase):self.fail(f"test wrap_text failed: {str(e)}")if __name__ == "__main__":- unittest.main()\ No newline at end of file+ unittest.main()