Need to intall

A couple options for viewing your gifs:


In [ ]:
from moviepy.editor import *
import pafy

Imbed video in notebook to make it easy to find and adjust the time range you want to use for the gif.


In [ ]:
#the video id is the string that comes after the "https://www.youtube.com/watch?v="

from IPython.display import YouTubeVideo
YouTubeVideo(#put your video id here)

Access the video through the YouTube API and download it.


In [ ]:
#this find the youtube video and downloads it.

#add the video url here
url = 'https://www.youtube.com/watch?v=your_video_id'
video = pafy.new(url)

#get the best download option
best = video.getbest(preftype="mp4")

#create a filename for the video
myfilename = 'Your_Video_Name.' + best.extension
title = best.download(filepath=myfilename ,quiet=False)
print title

In [ ]:
#subclip = start and stop time
#resize = downsample
#name your gif file
#fps = frames per second
VideoFileClip(title).\
              subclip((4,02.40),(4,08.00)).\
              resize(0.25).\
              to_gif("Your_Gif_Name.gif", fps=7)

In [ ]: