how to convert video to gif image using python and moviepy

Free Python Code - Aug 10 '23 - - Dev Community

Welcome to a new post πŸ™‚
in this post i will show you how to convert video to gif image using python and moviepy

the first step is installing moviepy if not installed

pip install moviepy

the second step is write this code


import moviepy.editor as mp

video = mp.VideoFileClip('test.mp4')
video = video.subclip(0, 5)
video.write_gif('out.gif')

Enter fullscreen mode Exit fullscreen mode

Note
I cut the first 5 seconds of the video
in line 3
This is not a requirement for video conversion. You can convert video without cutting

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .