Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexjyong/8f6457daa0ae02a0fe63b18681f748c6 to your computer and use it in GitHub Desktop.
Save alexjyong/8f6457daa0ae02a0fe63b18681f748c6 to your computer and use it in GitHub Desktop.
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

Homebrew can be used to install both youtube-dl:

brew install youtube-dl 

We will use docker for gifify. Please note that gifify is no longer maintained by the creator.

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`
docker run -it --rm -v $(pwd):/data maxogden/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 in the original version, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment