rogerxavier
commited on
Commit
•
25d96aa
1
Parent(s):
e1d783a
Update moviepyTest.py
Browse files- moviepyTest.py +32 -37
moviepyTest.py
CHANGED
@@ -4,42 +4,37 @@ import numpy as np
|
|
4 |
import subprocess
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
def test():
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
clip = ImageClip(img).set_duration(1).resize((width, height))
|
36 |
-
|
37 |
-
txt_clip = TextClip(subtitles[i], fontsize=70, color='white', bg_color='black')
|
38 |
-
txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(1)
|
39 |
-
|
40 |
-
clip = CompositeVideoClip([clip, txt_clip])
|
41 |
-
video = concatenate_videoclips([video, clip])
|
42 |
-
|
43 |
-
# 保存视频
|
44 |
-
video.write_videofile('output_video.mp4', fps=fps)
|
45 |
return "保存成功"
|
|
|
4 |
import subprocess
|
5 |
|
6 |
|
7 |
+
# 函数用于获取图片的持续时间
|
8 |
+
def get_duration(image_name) ->str:
|
9 |
+
return '0:00:02.875000'
|
10 |
+
|
11 |
+
|
12 |
def test():
|
13 |
+
# 执行命令
|
14 |
+
subprocess.run(["apt", "install", "imagemagick"])
|
15 |
+
# 图片素材和字幕
|
16 |
+
image_files = ['6.jpg', '7.jpg']
|
17 |
+
subtitles = ['我我我,我帝者战神呀!', '嘻嘻!不要笑,不可以笑啦!']
|
18 |
+
|
19 |
+
# 视频分辨率和帧率
|
20 |
+
width, height = 1280, 720
|
21 |
+
fps = 30
|
22 |
+
font_path = '1.ttf'#设置字体以防默认字体无法同时处理中英文
|
23 |
+
# 创建视频编辑器
|
24 |
+
video_clips = []
|
25 |
+
for idx, image_file in enumerate(image_files):
|
26 |
+
img = cv2.imread(image_file)
|
27 |
+
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
28 |
+
clip = ImageClip(img).set_duration(get_duration(image_file)).resize((width, height))
|
29 |
+
|
30 |
+
txt_clip = TextClip(subtitles[idx], fontsize=70, color='white', bg_color='black',font = font_path)
|
31 |
+
txt_clip = txt_clip.set_pos(('center', 'bottom')).set_duration(get_duration(image_file))
|
32 |
+
|
33 |
+
clip = CompositeVideoClip([clip, txt_clip])
|
34 |
+
video_clips.append(clip)
|
35 |
+
|
36 |
+
video = concatenate_videoclips(video_clips)
|
37 |
+
|
38 |
+
# 保存视频
|
39 |
+
video.write_videofile('output_video.mp4', fps=fps)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
return "保存成功"
|