How to Encode VP8 Video with FFmpeg and libvpx
This guide provides a straightforward tutorial on how to encode video
files to the VP8 format using FFmpeg and the libvpx encoder
library. You will learn the essential command-line syntax, recommended
settings for bitrate and quality control, and how to perform both
constant quality and two-pass encoding for optimal WebM delivery.
Basic VP8 Encoding Command
To encode a video to VP8, you need to output to a container that
supports it, typically WebM (.webm). VP8 video is usually
paired with either Vorbis or Opus audio.
Here is the basic command to convert a video using standard settings:
ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -c:a libvorbis -b:a 128k output.webm-i input.mp4: Specifies the input video.-c:v libvpx: Uses thelibvpxencoder for VP8 video.-b:v 1M: Sets the video bitrate to 1 Megabit per second.-c:a libvorbis: Uses the Vorbis encoder for audio (Opus can be used with-c:a libopus).-b:a 128k: Sets the audio bitrate to 128 kbps.
Recommended: Constant Quality (CRF) Encoding
For the best balance of quality and file size, use Constant Rate
Factor (CRF) mode. Unlike other encoders, libvpx requires
both the -crf limit and the -b:v limit to be
enabled together. Setting -b:v 0 tells FFmpeg to use pure
CRF mode.
The CRF scale for VP8 ranges from 4 (best quality) to
63 (worst quality). Recommended values are usually between
10 and 35.
ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 0 -c:a libopus -b:a 128k output.webm-crf 10: Sets the video quality level (lower values mean higher quality).-b:v 0: Instructs the encoder to prioritize the CRF value without a bitrate ceiling.
Two-Pass Encoding for Target File Sizes
If you need your output file to be an exact size or fit within strict bandwidth limits, two-pass encoding is highly recommended. This process analyzes the video on the first pass and performs the actual encoding on the second pass.
Pass 1:
ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -quality good -cpu-used 4 -an -pass 1 -f webm /dev/nullPass 2:
ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -quality good -cpu-used 1 -c:a libvorbis -b:a 128k -pass 2 output.webm(Note: Windows users should replace /dev/null in the
first pass with NUL.)
Key Parameters Explained:
-quality: Can be set tobest,good, orrealtime.goodis recommended for most use cases as it balances speed and compression efficiency.-cpu-used: Controls encoding speed versus quality. It accepts values from0to5for VP8. Lower numbers yield better quality but slower encode times. For Pass 1, a faster setting like4or5is typically used to save time.