Skip to content

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

fix: resolve local material path before passing to combine_videos

kevin.zhangfb7923503454
diff --git a/app/services/video.py b/app/services/video.py
index eeece3d0..6f1e827d 100644
--- a/app/services/video.py
+++ b/app/services/video.py
@@ -1078,6 +1078,9 @@ def preprocess_video(materials: List[MaterialInfo], clip_duration=4):
else:
# 普通视频素材只需要读取尺寸做校验,校验完成后立即释放句柄即可。
close_clip(clip)
+ # Update url to the resolved absolute path so that downstream
+ # stages (combine_videos) can open the file without re-resolving.
+ material.url = material_source_path
except Exception:
close_clip(clip)
raise
diff --git a/test/services/test_cli.py b/test/services/test_cli.py
index d5187d8c..81fcb0a1 100644
--- a/test/services/test_cli.py
+++ b/test/services/test_cli.py
@@ -70,6 +70,40 @@ class TestCli(unittest.TestCase):
params = cli.build_video_params(args)
self.assertEqual(params.video_source, "coverr")
+ def test_local_material_filename_resolved_to_absolute_path(self):
+ """After preprocess_video, material.url should be an absolute path, not a bare filename."""
+ import os
+ import tempfile
+ from app.utils import utils
+ from app.services import video as vd
+ from app.models.schema import MaterialInfo
+
+ local_videos_dir = utils.storage_dir("local_videos", create=True)
+ # Create a minimal valid video file for testing
+ test_filename = "_cli_test_resolve.mp4"
+ test_filepath = os.path.join(local_videos_dir, test_filename)
+ # We need a real video file; use a tiny one via moviepy
+ try:
+ from moviepy import ColorClip
+ clip = ColorClip(size=(640, 640), color=(0, 0, 0), duration=1)
+ clip.write_videofile(test_filepath, fps=1, logger=None)
+ clip.close()
+ except Exception:
+ self.skipTest("moviepy not available for creating test video")
+
+ try:
+ materials = [MaterialInfo(provider="local", url=test_filename, duration=0)]
+ result = vd.preprocess_video(materials=materials, clip_duration=4)
+ self.assertTrue(len(result) > 0, "preprocess_video should return valid materials")
+ self.assertTrue(
+ os.path.isabs(result[0].url),
+ f"material url should be absolute path, got: {result[0].url}",
+ )
+ self.assertEqual(result[0].url, test_filepath)
+ finally:
+ if os.path.exists(test_filepath):
+ os.remove(test_filepath)
+
if __name__ == "__main__":
unittest.main()