Convert Video to Animated WebP Using FFmpeg
This article provides a straightforward, step-by-step guide on how to convert high-resolution videos into optimized, lightweight animated WebP files using the powerful command-line utility FFmpeg. You will learn the specific command-line arguments needed to scale down high-resolution source files, adjust frame rates, control image quality, and set looping options to ensure your output files are perfectly balanced between visual quality and file size.
The Basic Conversion Command
For a simple conversion without any specific optimizations, you can use the default FFmpeg command. However, because WebP is designed for short, web-friendly animations, converting a raw high-resolution video this way will likely result in an excessively large file size.
ffmpeg -i input.mp4 output.webpOptimizing High-Resolution Video for WebP
To make a high-resolution video suitable for web delivery as an animation, you must scale the resolution down, lower the frame rate, and adjust the compression settings.
Here is the recommended command for a balanced, high-quality, and highly compressed animated WebP:
ffmpeg -i input.mp4 -vf "fps=15,scale=800:-1:flags=lanczos" -vcodec libwebp -lossless 0 -q:v 75 -loop 0 -an output.webpBreakdown of the Command Parameters
-i input.mp4: Specifies the path to your source video file.-vf "fps=15,scale=800:-1:flags=lanczos": Applies video filters to optimize the file size:fps=15: Reduces the frame rate to 15 frames per second (standard for web animations).scale=800:-1: Resizes the width to 800 pixels and automatically calculates the height to maintain the original aspect ratio.flags=lanczos: Uses the high-quality Lanczos scaling algorithm to keep the scaled-down image sharp.
-vcodec libwebp: Forces FFmpeg to use the WebP encoder.-lossless 0: Enables lossy compression. Setting this to0(lossy) is highly recommended for converting video content, as it produces significantly smaller files than1(lossless) with almost no noticeable drop in visual quality.-q:v 75: Sets the compression quality factor. This scale ranges from 0 to 100. A value of 75 offers an excellent sweet spot between file size and image clarity.-loop 0: Sets the animation to loop infinitely. If you want the animation to play only once, set this value to1.-an: Disables the audio stream, as WebP animations do not support audio playback.output.webp: The name and format of your final output file.
Advanced Quality Tuning
If the resulting file size is still too large, or if you need higher visual fidelity, you can adjust the following parameters:
- Lower Quality for Smaller Size: Reduce
-q:v 75to-q:v 50. This will aggressively reduce the file size at the cost of some compression artifacts. - Control Encoding Effort: Add the
-compression_levelflag (ranging from 0 to 6). For example, adding-compression_level 6instructs FFmpeg to spend more CPU time compressing the file, resulting in the smallest possible file size for your chosen quality level.