python+deepseek实现ai一键成片生成故事片短视频代码
代码语言:python
所属分类:其他
代码描述:python+deepseek实现ai一键成片生成故事片短视频代码,使用阿里云的deepseek模型及通义瓦万相模型实现故事片生成,支持多种画面模式,3D卡通, 废土风, 点彩画, 超现实, 水彩, 粘土, 写实, 陶瓷, 3D, 水墨, 折纸, 工笔, 国风水墨
代码标签: python deepseek ai 一键 成 片生成 故事片 短视频 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
import argparse import requests import json import time import os from moviepy.editor import * import dashscope from dashscope.audio.tts import SpeechSynthesizer class StoryGenerator: def __init__(self, api_key): self.api_key = api_key dashscope.api_key = api_key self.output_dir = "output" self.style_choice="" self.music_choice="" self.juese=[] os.makedirs(self.output_dir, exist_ok=True) def create_video(self, shots): """生成并合成最终视频""" print("🎬 开始视频生成流程...") clips = [] for idx, shot in enumerate(shots, 1): print(f"\n🔧 正在处理第 {idx}/{len(shots)} 个分镜头...") # 生成图片提示词 print("🖼️ 生成画面提示词...") aiprompttext=self.generate_shotimgtext(shot['prompt'],shot['shotjuese']) print(aiprompttext) # 生成图片 print("🖼️ 生成画面...") img_task = self._generate_image(aiprompttext+",画面风格:"+self.style_choice) img_url = self._wait_for_task(img_task, "图片") img_path = os.path.join(self.output_dir, f"shot_{idx}.jpg") self._download_file(img_url, img_path) # 生成音频 print("🔊 生成配音...") audio_path = self._generate_audio(shot['sayword'], idx) audio_clip = AudioFileClip(audio_path) # 创建视频片段 clip = ImageClip(img_path).set_duration(audio_clip.duration).set_audio(audio_clip) clips.append(clip) # 合成最终视频 print("\n🎥 合成最终视频...") final_clip = concatenate_videoclips(clips) output_path = os.path.join(self.output_dir, "final_video.mp4") final_clip.write_videofile(output_path, fps=24, threads=1) print(f"\n✅ 视频生成完成!保存路径:{os.path.abspath(output_path)}") def _generate_image(self, prompt): """生成图片""" url = "https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis" headers = { "Authorization": f"Bearer {self.ap.........完整代码请登录后点击上方下载按钮下载查看
网友评论0