From 6a2273616025a98135203e5f00b7789031b4d167 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 11 Jul 2019 15:08:19 +0200 Subject: [PATCH] Adds video2gif --- bin/video2gif | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 bin/video2gif diff --git a/bin/video2gif b/bin/video2gif new file mode 100755 index 0000000..8e817ff --- /dev/null +++ b/bin/video2gif @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +if [ $# -ne 3 ]; then + echo -e "\033[31;1merror:\033[0m this script expects three arguments, the file, the starting time and the duration." + exit 1 +fi + +if [ ! -f $1 ]; then + echo -e "\033[31;1merror:\033[0m couldn't open $1: no such file." + exit +fi + +palette_dir=$(mktemp -d) + +ffmpeg -y -ss $2 -t $3 -i $1 \ + -vf fps=10,scale=320:-1:flags=lanczos,palettegen $palette_dir/palette.png > /dev/null 2>&1 + +ffmpeg -ss $2 -t $3 -i $1 -i $palette_dir/palette.png -filter_complex \ + "fps=10,scale=320:-1:flags=lanczos[x];[x][1:v]paletteuse" -y output.gif > /dev/null 2>&1 + +rm -rf $palette_dir