Add a script to create a gif from a video
This commit is contained in:
45
dotfiles/bin/create-gif-from-video
Normal file
45
dotfiles/bin/create-gif-from-video
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
|
||||
RED="$(tput setaf 1)"
|
||||
GREEN="$(tput setaf 2)"
|
||||
YELLOW="$(tput setaf 3)"
|
||||
BLUE="$(tput setaf 4)"
|
||||
MAGENTA="$(tput setaf 5)"
|
||||
CYAN="$(tput setaf 6)"
|
||||
BOLD="$(tput bold)"
|
||||
NORMAL="$(tput sgr0)"
|
||||
else
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
MAGENTA=""
|
||||
CYAN=""
|
||||
BOLD=""
|
||||
NORMAL=""
|
||||
fi
|
||||
|
||||
filename=$(basename -- "$1")
|
||||
output_name="$2"
|
||||
width="$3"
|
||||
|
||||
if [[ $filename == "" || $output_name == "" ]]; then
|
||||
printf "${BOLD}${RED}Usage: create-gif-from-video <filename> <output name> <optional width, defaults to 240>${NORMAL}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
output="${output_name}.gif"
|
||||
if [[ $width == "" ]]; then
|
||||
width=240
|
||||
fi
|
||||
|
||||
printf "\n${YELLOW}${BOLD}Creating a gif from '$filename' | output: $output | width: $width${NORMAL}\n"
|
||||
|
||||
ffmpeg -y -stats -loglevel level+error -i "$filename" -vf "fps=24,scale=$width:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 "$output"
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished!${NORMAL}\n\n"
|
||||
|
||||
Reference in New Issue
Block a user