Skip to content

Instantly share code, notes, and snippets.

@hancush
Created January 7, 2016 17:33
Show Gist options
  • Select an option

  • Save hancush/88ab796d0936c637f53a to your computer and use it in GitHub Desktop.

Select an option

Save hancush/88ab796d0936c637f53a to your computer and use it in GitHub Desktop.
#!/bin/sh
youtube-dl -o "_%(id)s.%(ext)s" $1
infile=$(ls | head -n1)
palette="/tmp/palette.png"
filters="fps=12,scale=500:-1:flags=lanczos"
ffmpeg -v warning -ss $2 -t $3 -i $infile -vf "$filters,palettegen=stats_mode=diff" -y $palette
ffmpeg -v warning -ss $2 -t $3 -i $infile -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse=dither=none" -y anim.gif
rm $infile
@hancush
Copy link
Copy Markdown
Author

hancush commented Jan 7, 2016

to run:
save vidgif.sh
from directory containing vidgif.sh:
bash vidgif.sh youtube_url start_time gif_length
where start time is MM:SS, gif length is time in whole seconds

script downloads youtube video, creates color palette then gif with that palette to ensure highest quality via ffmpeg, writes output to anim.gif, deletes video file

@hancush
Copy link
Copy Markdown
Author

hancush commented Jan 7, 2016

bastardized version of script here: http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

@hancush
Copy link
Copy Markdown
Author

hancush commented Nov 22, 2016

other adjustable params (hard-coded, sry):

  • fps: frames per second, value directly correlated with gif quality
  • scale: width, in pixels, will scale gif proportionally

@hancush
Copy link
Copy Markdown
Author

hancush commented Nov 22, 2016

you gotta pip install youtube-dl also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment