利用 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(video): preserve concat paths (#1594)
Rudy Mizrahi Celekli9887b459e754
diff --git a/app/services/video.py b/app/services/video.pyindex 6abf0960..9b4a5b05 100644--- a/app/services/video.py+++ b/app/services/video.py@@ -497,7 +497,9 @@ def _format_ffmpeg_concat_path(file_path: str) -> str:让 `C:\\Users\\...` 变成 `C:/Users/...`,再处理单引号,兼容 macOS/Linux。"""absolute_path = os.path.abspath(file_path)- return _escape_ffmpeg_concat_path(absolute_path.replace("\\", "/"))+ # Normalize the native separator only. A backslash can be a literal+ # component of a valid POSIX path and must still identify the same file.+ return _escape_ffmpeg_concat_path(absolute_path.replace(os.sep, "/"))def _describe_concat_output_progress(output_file: str) -> str:diff --git a/test/services/test_posix_concat_paths.py b/test/services/test_posix_concat_paths.pynew file mode 100644index 00000000..1277eff7--- /dev/null+++ b/test/services/test_posix_concat_paths.py@@ -0,0 +1,57 @@+import os+import random+import shutil+import subprocess++import pytest+from moviepy import VideoFileClip++from app.config import config+from app.models.schema import VideoAspect, VideoConcatMode+from app.services import video++[email protected]("directory", ["ordinary", "مرحبا-O'Brien", r"back\slash"])+def test_combination_preserves_native_output_directory(tmp_path, directory):+ if os.name == "nt" and "\\" in directory:+ pytest.skip("Windows does not permit a literal backslash in a path component")+ binary = video.utils.get_ffmpeg_binary()+ if not shutil.which(binary):+ pytest.skip("FFmpeg is required for native media rendering")++ source = tmp_path / "source.mp4"+ audio = tmp_path / "narration.wav"+ output_dir = tmp_path / directory+ output_dir.mkdir()+ output = output_dir / "combined.mp4"+ base = [binary, "-nostdin", "-v", "error", "-y", "-threads", "1"]+ subprocess.run(+ [*base, "-f", "lavfi", "-i", "color=c=white:s=64x64:r=30:d=0.4",+ "-c:v", "libx264", "-pix_fmt", "yuv420p", str(source)],+ check=True, capture_output=True,+ )+ subprocess.run(+ [*base, "-f", "lavfi", "-i", "sine=frequency=220:duration=0.3",+ "-ar", "44100", str(audio)],+ check=True, capture_output=True,+ )++ previous_config = config.app.copy()+ previous_random = random.getstate()+ config.app.update({"video_codec": "libx264", "video_clip_concurrency": 1})+ try:+ returned = video.combine_videos(+ str(output), [str(source)], str(audio),+ video_aspect=VideoAspect.square,+ video_concat_mode=VideoConcatMode.sequential,+ video_transition_mode=None, threads=1,+ )+ assert returned == str(output)+ with VideoFileClip(str(output), audio=False) as rendered:+ assert 0.25 <= rendered.duration <= 0.4+ assert rendered.get_frame(0.1).mean() > 200+ assert list(output_dir.iterdir()) == [output]+ finally:+ config.app.clear()+ config.app.update(previous_config)+ random.setstate(previous_random)diff --git a/test/services/test_video.py b/test/services/test_video.pyindex 9e099757..97c0d0d0 100644--- a/test/services/test_video.py+++ b/test/services/test_video.py@@ -857,7 +857,7 @@ class TestVideoService(unittest.TestCase):vd.os.path,"abspath",return_value=r"C:\Users\Test User's Videos\clip.mp4",- ):+ ), patch.object(vd.os, "sep", "\\"):self.assertEqual(vd._format_ffmpeg_concat_path(r"C:\Users\Test User's Videos\clip.mp4"