Skip to content

Instantly share code, notes, and snippets.

@yoosefi
Created May 3, 2016 00:46
Show Gist options
  • Save yoosefi/2c1dea90ea4c534ac32796b2ca2cd3ef to your computer and use it in GitHub Desktop.
Save yoosefi/2c1dea90ea4c534ac32796b2ca2cd3ef to your computer and use it in GitHub Desktop.
nemo script to convert a video to a gif, scaling to a variable width.
#!/bin/sh
# nemo script to convert a video to a gif, scaling to a variable width.
# put this in ~/.local/share/nemo/scripts/
# requires zenity, ffmpeg, and gifsicle
set -eu
WIDTH=$(zenity --entry --title="Enter GIF Width" --text="Enter the desired GIF width. -1 means the same width as the source video:\n${1}" --entry-text="-1")
SCALE="scale=${WIDTH}:-1:flags=lanczos"
ffmpeg -i "${1}" -vf "${SCALE},palettegen=stats_mode=diff" -y /tmp/palette.png
ffmpeg -i "${1}" -i /tmp/palette.png -lavfi "${SCALE} [x]; [x][1:v] paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle" -y /tmp/tmp.gif
BASENAME=$(basename "${1}")
NAME=${BASENAME%.*}
gifsicle -O3 /tmp/tmp.gif > "${NAME}.gif"
zenity --notification --text="${BASENAME} was converted to GIF" --timeout 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment