Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using youtube-dl and gifify from the command-line to make a cat gif

Using youtube-dl and gifify from the command-line

Turn this cute YouTube cat video into a briefer-but-still-cute GIF:

gif

Software to download

  • youtube-dl is a command-line tool for quickly downloading video files from a given YouTube URL
  • the gifify utility for converting video into GIFs, which is part of the gifsicle library.

Installing youtube-dl and gifify

Homebrew can be used to install both youtube-dl and gifify (via gifsicle):

brew install youtube-dl gifsicle

Commands to run

# downloads from the given YouTube URL to the file path of `catdrawer.mp4`
youtube-dl "https://youtu.be/sP1_rT0wyQo" -o catdrawer.mp4

# creates a copy of `catdrawer.mp4` and converts seconds 19 to 27 to a GIF file named `catdrawer.gif`
gifify catdrawer.mp4 -o catdrawer.gif  --from 19 --to 27 --resize 400:-1 --colors 128

Then upload to Imgur. You could probably write a curl command to do it via Imgur's API

Piping youtube-dl to stdout

As victorperin points out below, instead of downloading and saving a MP4 file with youtube-dl, we can pipe the MP4 file to stdout and directly into gifify. This means that the intermediary catdrawer.mp4 is never saved to disk:

youtube-dl "https://youtu.be/sP1_rT0wyQo" -o - \
   | gifify -o catdrawer.gif --from 19 --to 27 --resize 400:-1 --colors 128
@victorperin

This comment has been minimized.

Copy link

victorperin commented Jan 27, 2020

You can use pipes to run it faster, without need to write to disk when downloading the mp4 version:

youtube-dl "https://www.youtube.com/watch?v=kl1RwhATTzA" -o - | gifify -o catdrawer.gif --from 19 --to 27 --resize 600:-1 --colors 128
@dannguyen

This comment has been minimized.

Copy link
Owner Author

dannguyen commented Feb 6, 2020

good call! I frequently forget that - can be used to direct to stdout instead of a file path. I'll update my readme, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.