Skip to content

Instantly share code, notes, and snippets.

@7sDream
Created March 6, 2019 09:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7sDream/436a6040f3db523955960a1bcd1878fe to your computer and use it in GitHub Desktop.
Save 7sDream/436a6040f3db523955960a1bcd1878fe to your computer and use it in GitHub Desktop.
togif.sh
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "Usage: $0 videofile output fps width start duration"
exit 1
fi
VIDEO=$1
OUTPUT=$2
FPS=$3
WIDTH=$4
START=$5
DURATION=$6
: ${FPS:=film}
: ${WIDTH:=-1}
: ${START:=0}
: ${DURATION:=0}
if [ "$VIDEO" = "--help" ]; then
echo "$0 video output fps width start duration"
exit 0
fi
if [ "$DURATION" = "0" ]; then
DURATION=""
else
DURATION="-t $DURATION"
fi
ffmpeg -ss "$START" $DURATION -i "$VIDEO" -vf fps=$FPS,scale=$WIDTH:-1:flags=lanczos,palettegen palette.png
ffmpeg -ss "$START" $DURATION -i "$VIDEO" -i palette.png -filter_complex "fps=$FPS,scale=$WIDTH:-1:flags=lanczos[x];[x][1:v]paletteuse" $OUTPUT
rm palette.png
@7sDream
Copy link
Author

7sDream commented Mar 6, 2019

A small script help me convert video to gif use ffmpeg.


Argumemts:

  • Input video filename
  • Output gif filename
  • FPS
  • Width (Keep ratio)
  • Start time
  • Duration

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