|
from moviepy.editor import * |
|
import cv2 |
|
import numpy as np |
|
import subprocess |
|
from moviepy import config_defaults |
|
|
|
|
|
|
|
|
|
def get_duration(image_name) ->str: |
|
return '0:00:02.875000' |
|
|
|
|
|
def test(): |
|
|
|
print(config_defaults.IMAGEMAGICK_BINARY,config_defaults.FFMPEG_BINARY) |
|
|
|
image_files = ['6.jpg', '7.jpg'] |
|
subtitles = ['我我我,我帝者战神呀!', '嘻嘻!不要笑,不可以笑啦!'] |
|
|
|
|
|
width, height = 1280, 720 |
|
fps = 30 |
|
font_path = '1.ttf' |
|
|
|
video_clips = [] |
|
for idx, image_file in enumerate(image_files): |
|
img = cv2.imread(image_file) |
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) |
|
clip = ImageClip(img).set_duration(get_duration(image_file)).resize((width, height)) |
|
|
|
txt_clip = TextClip(subtitles[idx], fontsize=70, color='white', bg_color='black',font = font_path) |
|
txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(get_duration(image_file)) |
|
|
|
clip = CompositeVideoClip([clip, txt_clip]) |
|
video_clips.append(clip) |
|
|
|
video = concatenate_videoclips(video_clips) |
|
|
|
|
|
video.write_videofile('output_video.mp4', fps=fps) |
|
return "保存成功" |
|
|