Table of contents
Pillow is mainly used to use pictures to generate gif files
import PIL
import numpy as np
image=[]
for i in range(n):
# 此处为图片位置路径
new=PIL.Image.open('E:/data/view/img-1/'+str(i)+'.png')
image.append(new)
# 此处为gif文件存储位置路径
image[0].save('E:/data/view/video_1/test_0.gif',format='GIF',
append_images=image[1: n],save_all=True,duration=20,loop=0) #duration是间隔速率
print('gif绘制完成')
Use the moviepy library to convert gif files to mp4 files and mp4 files to gif files
import moviepy.editor as mp
def convert_gif_to_mp4():
clip = mp.VideoFileClip('E:/data/view/video_1/test_1.gif')
clip.write_videofile('E:/data/view/video_1/true.mp4')
convert_gif_to_mp4()
import moviepy.editor as mp
def convert_mp4_to_gif():
clip = mp.VideoFileClip('E:/data/view/video_1/true.mp4')
clip.write_gif('E:/data/view/video_1/test_1.gif')
convert_mp4_to_gif()
The above is not finished and needs to be updated, it is only for personal study, the infringement contact is deleted, if there are any mistakes or deficiencies, please point out for improvement.