Convert Video to WebM with Opus Using FFmpeg

This article provides a straightforward guide on how to convert any video file into the WebM format using the highly efficient Opus audio codec with FFmpeg. You will learn the exact command-line syntax required, the recommended video codecs to pair with Opus, and how to adjust quality settings for optimal web playback.

To convert a video to WebM with Opus audio, you should pair the Opus audio codec (libopus) with a compatible video codec, such as VP9 (libvpx-vp9) or VP8 (libvpx). VP9 is highly recommended as it offers superior compression and quality.

The Basic Conversion Command

To perform a standard conversion using default quality settings, run the following command in your terminal:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -c:a libopus output.webm

In this command:

  • -i input.mp4 specifies your source video file.
  • -c:v libvpx-vp9 selects the VP9 video codec.
  • -c:a libopus selects the Opus audio codec.
  • output.webm is the name of your final output file.

For the best balance of file size and visual quality, it is recommended to use Constant Rate Factor (CRF) mode. Use the following command:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus -b:a 128k output.webm

Parameter Breakdown

  • -crf 30: Controls the video quality. The CRF scale for VP9 ranges from 0 to 63. Lower values mean better quality but larger file sizes. A value between 15 and 35 is recommended for web video.
  • -b:v 0: This is required when using CRF mode with VP9; it forces FFmpeg to rely entirely on the CRF value for quality control rather than a target bitrate.
  • -b:a 128k: Sets the audio bitrate for the Opus codec to 128 kbps, which provides excellent, near-transparent stereo audio quality. You can lower this to 64k for voice-only content to save extra space.