1 Star 0 Fork 0

hehuolong/AI-Auto-Video-Generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
video_creator.py 1.12 KB
一键复制 编辑 原始数据 按行查看 历史
BB31420 提交于 2023-05-05 04:31 +08:00 . Add files via upload
import moviepy.editor as mpy
from moviepy.editor import concatenate_videoclips
from PIL import Image, ImageDraw, ImageFont
import os
import textwrap
from datetime import datetime
def create_video(images, voiceover_content, story, timestamp):
# Save voiceover
voiceover_filename = f"voiceover_{timestamp}.mp3"
with open(voiceover_filename, "wb") as f:
f.write(voiceover_content)
# Generate image file names based on the timestamp and the index
image_filenames = [f"image_{timestamp}_{idx}.png" for idx, _ in enumerate(images)]
# Create video
image_clips = [mpy.ImageClip(img).set_duration(5) for img in image_filenames]
video_clip = concatenate_videoclips(image_clips, method="compose")
video_clip = video_clip.set_audio(mpy.AudioFileClip(voiceover_filename))
video_filename = f"output_video_{timestamp}.mp4" # The filename already includes a timestamp
video_clip.write_videofile(video_filename, codec="libx264", fps=24)
# Clean up files
#for image_filename in image_filenames:
#os.remove(image_filename)
#os.remove(voiceover_filename)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hehuolong_admin/AI-Auto-Video-Generator.git
git@gitee.com:hehuolong_admin/AI-Auto-Video-Generator.git
hehuolong_admin
AI-Auto-Video-Generator
AI-Auto-Video-Generator
main

搜索帮助