Skip to content

Instantly share code, notes, and snippets.

@gargolito
Created January 13, 2020 15:24
Show Gist options
  • Save gargolito/814b3b093bb4449a5133bebabc10de26 to your computer and use it in GitHub Desktop.
Save gargolito/814b3b093bb4449a5133bebabc10de26 to your computer and use it in GitHub Desktop.
ffmpeg for video to gif
function vid2gif () {
vid="$1"
#start_time=00:00:01
#duration=5
height=-1 # input height halved , can replace with pixils .
width=480 # keeps aspect ratio . can replace with pixils .
fps=25 # frames per a second .
filters="fps=$fps,scale=$width:$height:flags=lanczos"
#ffmpeg -ss $start_time \
# -t $duration \
# -i "$vid" \
ffmpeg -i "$vid" \
-vf "$filters,palettegen" \
-y palette.png &&
ffmpeg -i "$vid" \
-i palette.png \
-lavfi "$filters [x]; [x][1:v] paletteuse" \
-y "${vid/.*}".gif && rm palette.png
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment