Programster's Blog

Tutorials focusing on Linux, programming, and open-source

FFMPEG - Create WebP Animated Images

I wanted to find an animated image format that would allow me to have a larger, better quality image, than what I can achieve with GIF.

This is how one can use ffmpeg to convert a short video into a WebP animated image.

Steps

Copy, paste, and execute the script below after having tweaked the variables at the top to match your needs.

#!/bin/bash

# Specify the path to the video you wish to convert to an animated webp.
INPUT_VIDEO=input.mp4

# Set framerate of animated image.
FRAMERATE=30

# Set output width/height
WIDTH=800
HEIGHT=450

# Set compression of webp images between 1-100 with 100 being perfect.
QUALITY=60

ffmpeg \
  -i $INPUT_VIDEO \
  -vcodec libwebp \
  -preset default \
  -loop 0 \
  -an -vsync 0 \
  -vf "fps=$FRAMERATE, scale=$WIDTH:$HEIGHT" \
  -qscale $QUALITY \
  output.webp

Below is an animated WebP image I managed to create that would fit within Discord's 8 MB file limit:

Unfortunately, it appears that Discord does not currently support WebP images, but they did in the past.

Gif Comparison

I converted the video to a GIF as well for comparison (below), which resulted in a larger file and a much poorer quality.

References

Last updated: 28th February 2021
First published: 28th February 2021