Skip to content

Instantly share code, notes, and snippets.

@nuclearglow
Last active January 7, 2022 10:47
Show Gist options
  • Save nuclearglow/1b06777d7689913968299a56b884d38b to your computer and use it in GitHub Desktop.
Save nuclearglow/1b06777d7689913968299a56b884d38b to your computer and use it in GitHub Desktop.
MP4, WebM and Animated GIFs

Install Mac OS X

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aacc brew install gifify

Install Ubuntu

sudo apt-get install ffmpeg libavcodec-extra

Extract slice and convert to GIF

ffmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=25,scale=320:-1:flags=lanczos" -loop 0 output.gif

  • -ss 30 skip 30 seconds
  • -t 3 take 3 seconds
  • -i input file
  • -vf
    • "fps=25" set fps to 25
    • "scale=w='min(500, iw*3/2):h=-1':flags=lanczos" scale to min 500px but keep aspect ratio, use lanczos algorithm
  • -loop 0 loop indefinitely, 1 = do not loop

https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality

Cut MP4 into 120s slices

ffmpeg -i input.mp4 -map 0 -c copy -f segment -segment_time 120 -reset_timestamps 1 out%02d.mp4

Convert MP4 to WebM

ffmpeg -i webbluetooth_cut_120.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis webbluetooth_cut_120.webm

Convert to animated gif with 25 fps

gifify webbluetooth_cut_120.mp4 -o webbluetooth_cut_120.gif --fps 25

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