Convert Video to Animated WebP with FFmpeg
This guide explains how to convert high-resolution video files into lightweight, animated WebP images using FFmpeg. You will learn the essential FFmpeg commands to downscale resolution, adjust frame rates, balance compression and visual fidelity, and configure infinite looping to produce optimized animated WebP files suitable for web use.
Basic Conversion Command
Animated WebP requires the libwebp encoder. Run the
following command in your terminal to perform a standard conversion:
ffmpeg -i input.mp4 -vcodec libwebp -loop 0 output.webp-i input.mp4: Specifies the input video file.-vcodec libwebp: Enables the WebP video encoder.-loop 0: Sets the animation to loop indefinitely (1plays once,2plays twice, etc.).
Handling High-Resolution Video
High-resolution videos (1080p, 4K) generate excessively large WebP
files if converted directly. To optimize file size and playback
performance, you should scale the resolution and reduce the frame rate
using the video filter (-vf) argument.
ffmpeg -i input.mp4 -vf "fps=24,scale=800:-1:flags=lanczos" -vcodec libwebp -lossless 0 -q:v 75 -compression_level 6 -loop 0 output.webpParameter Breakdown
fps=24: Reduces the frame rate to 24 frames per second. Most animations do not require 60 fps, and lowering this value dramatically reduces the final file size.scale=800:-1: Resizes the image to a width of 800 pixels while automatically calculating the height (-1) to preserve the original aspect ratio.flags=lanczos: Uses the Lanczos scaling algorithm, which delivers sharp downscaling for high-resolution sources.-lossless 0: Enables lossy compression. Set to1for lossless quality, though lossless results in significantly larger files.-q:v 75: Sets the quality factor on a scale from 0 to 100. A value between 70 and 80 offers an optimal balance between visual clarity and file size.-compression_level 6: Controls the encoding effort from 0 (fastest, worst compression) to 6 (slowest, best compression). Using6minimizes output size.
Trimming the Video Segment
Because animated WebP is designed for short clips, converting long
videos is not recommended. You can extract a specific segment of the
video directly during conversion using -ss (start time) and
-t (duration):
ffmpeg -ss 00:00:02 -i input.mp4 -t 4 -vf "fps=20,scale=720:-1:flags=lanczos" -vcodec libwebp -lossless 0 -q:v 70 -compression_level 6 -loop 0 output.webpThis command starts at the 2-second mark, processes 4 seconds of video, limits the frame rate to 20 fps, downscales the width to 720 pixels, and writes an optimized animated WebP file.