Home > python > extract an animated gif from a video

extract an animated gif from a video

You have a video and you want to create an animated gif from a part of it.

You can use MoviePy for that. Here you can find a blog post from the author of MoviePy, where the process is explained through several examples. Here I copy three simple examples:

Example 1:

from moviepy.editor import *

clip = (VideoFileClip("frozen_trailer.mp4")  # input video
        .subclip((1,22.65),(1,23.2))         # part to extract, where 1’22.65 means 1 minute 22.65 seconds
        .resize(0.3))                        # resize to 30% of the original
clip.write_gif("use_your_head.gif")          # output animated gif

Example 2 (cropping):

kris_sven = (VideoFileClip("frozen_trailer.mp4")
             .crop(x1=145,x2=400))  # cropping: remove left-right borders

Example 3 (play forward and backward):

def time_symetrize(clip):
    return concatenate([clip, clip.fx( vfx.time_mirror )])

clip = (VideoFileClip("frozen_trailer.mp4", audio=False)
        .crop(x1=189, x2=433)
        .fx( time_symetrize ))  # the effect is added here

For more advanced usage, see the original blog post.

Categories: python Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: