利用 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): render decoded images regardless of filename suffix
RudyCelekli8acde2d07ac1
diff --git a/app/services/video.py b/app/services/video.pyindex 38b6ca91..e249a6ce 100644--- a/app/services/video.py+++ b/app/services/video.py@@ -1761,9 +1761,10 @@ def preprocess_video(materials: List[MaterialInfo], clip_duration=4):continueext = utils.parse_extension(material_source_path)+ is_image = ext in const.FILE_TYPE_IMAGEStry:# 图片素材直接按图片方式读取,避免先走 VideoFileClip 误判后触发不稳定的回退分支。- if ext in const.FILE_TYPE_IMAGES:+ if is_image:clip, material_source_path = _open_image_clip_with_fallback(material_source_path)@@ -1775,6 +1776,9 @@ def preprocess_video(materials: List[MaterialInfo], clip_duration=4):clip, material_source_path = _open_image_clip_with_fallback(material_source_path)+ # The successful decoder determines the material kind, even+ # when the uploaded filename has a video or unknown suffix.+ is_image = Trueexcept Exception as exc:logger.warning(f"skip unreadable local material: {material.url}, error: {str(exc)}"@@ -1793,7 +1797,7 @@ def preprocess_video(materials: List[MaterialInfo], clip_duration=4):close_clip(clip)continue- if ext in const.FILE_TYPE_IMAGES:+ if is_image:logger.info(f"processing image: {material_source_path}")# 探测尺寸时已经打开过一次素材,这里先释放探测句柄,再渲染# 用于导出的图片片段。diff --git a/test/services/test_media_image_fallback.py b/test/services/test_media_image_fallback.pynew file mode 100644index 00000000..940a5a00--- /dev/null+++ b/test/services/test_media_image_fallback.py@@ -0,0 +1,23 @@+from PIL import Image+from moviepy import VideoFileClip+import pytest++from app.models.schema import MaterialInfo+from app.services import video++[email protected]("suffix", [".bin", ".mp4"])+def test_detected_image_is_rendered_even_with_nonimage_suffix(tmp_path, monkeypatch, suffix):+ source = tmp_path / ("picture" + suffix)+ Image.new("RGB", (720, 720), "green").save(source, format="PNG")+ monkeypatch.setattr(video.utils, "storage_dir", lambda *args, **kwargs: str(tmp_path))+ material = MaterialInfo(provider="local", url=str(source))++ result = video.preprocess_video([material], clip_duration=0.2)++ assert result == [material]+ assert material.url != str(source)+ assert material.url.endswith(".mp4")+ with VideoFileClip(material.url, audio=False) as clip:+ assert clip.duration >= 0.19+ assert clip.size == [720, 720]