Skip to content

Instantly share code, notes, and snippets.

@averissimo
Last active November 29, 2016 16:54
Show Gist options
  • Save averissimo/3f40deac1ca22cc6658e2b2b56131ccc to your computer and use it in GitHub Desktop.
Save averissimo/3f40deac1ca22cc6658e2b2b56131ccc to your computer and use it in GitHub Desktop.
Creating GIFs easily with ffcast
#!/bin/bash
#
# my_ffcast takes the same options as ffcast
# -s: part of screen
# -w: window
# ...
if [ -z $1 ]
then
option=-s
else
option=$@
fi
TMP_AVI=$(mktemp /tmp/outXXXXXXXXXX.avi)
DEST_FOLDER=~/Pictures/gif-casts/
echo ""
echo ""
echo "There is a 03 second delay after the window is set to "
echo " remove any window glitches, check the output to see "
echo " when the recording actually starts"
echo "------------------------------------------------------"
ffcast -vv $option lag 3 ~/work/apps/ffmpeg/ffmpeg -f x11grab -s %s -i %D+%c -r 15 -vcodec huffyuv -y $TMP_AVI
v2gif $TMP_AVI
mv ${TMP_AVI%.*}.gif $DEST_FOLDER
echo ""
echo "File generated at ${TMP_AVI%.*}.gif and moved to $DEST_FOLDER"
#!/bin/bash
# credit to @lolilolicon for improving this script!!
(($#)) || { printf 'usage: %s <video>\n' "${0##*/}" >&2; exit; }
[[ ${1,,} == *.gif ]] && exit
ffmpeg() {
command ffmpeg -hide_banner -loglevel error -nostdin "$@"
}
video_to_gif() {
ffmpeg -i "$1" -vf palettegen -f image2 -c:v png - |
ffmpeg -i "$1" -i - -filter_complex paletteuse "$2"
}
set -- "$1" "${1%.*}.gif"
printf 'converting: %s ...' "$1" >&2
video_to_gif "$@" &&
printf '\r\e[Kwritten to: %s\n' "$2" >&2
# vim:et:sw=4:ts=4:
@averissimo
Copy link
Author

averissimo commented Sep 28, 2016

Run by selecting region on screen with mouse :) (it's the same as using the -s parameter):

$ my_ffcast

Select window (remove -f if you don't want borders)

$ my_ffcast -f -w

more options with man ffcast

@averissimo
Copy link
Author

averissimo commented Oct 4, 2016

Requires: https://github.com/lolilolicon/FFcast

and uses subcmd lag

@ropery
Copy link

ropery commented Oct 11, 2016

This pointed me to the palettegen/paletteuse filters, so thank you!

I wrote a simplified version of convert_to_gif: v2gif
I also put together a wiki page "GIF Howto". Feel free to improve it :)

@averissimo
Copy link
Author

@lolilolicon you're very welcome!!

your bash skills are awesome!! going to update my scripts :)

ps. just saw you comment now and the wiki page seems simple and awesome, I'd love to improve but can't see on what :p

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