Skip to content

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

added validation for video file using moviepy to ensure video file is valid before processing.

harrya8d208bdc34a
diff --git a/app/services/material.py b/app/services/material.py
index 0f16a2e7..e2a65cc6 100644
--- a/app/services/material.py
+++ b/app/services/material.py
@@ -5,6 +5,7 @@ from urllib.parse import urlencode
import requests
from typing import List
from loguru import logger
+from moviepy.video.io.VideoFileClip import VideoFileClip
from app.config import config
from app.models.schema import VideoAspect, VideoConcatMode, MaterialInfo
@@ -105,7 +106,19 @@ def save_video(video_url: str, save_dir: str = "") -> str:
f.write(requests.get(video_url, proxies=proxies, verify=False, timeout=(60, 240)).content)
if os.path.exists(video_path) and os.path.getsize(video_path) > 0:
- return video_path
+ try:
+ clip = VideoFileClip(video_path)
+ duration = clip.duration
+ fps = clip.fps
+ clip.close()
+ if duration > 0 and fps > 0:
+ return video_path
+ except Exception as e:
+ try:
+ os.remove(video_path)
+ except Exception as e:
+ pass
+ logger.warning(f"invalid video file: {video_path} => {str(e)}")
return ""