Convert your Video Files to WebM using FFMpeg

10/01/2026

The WebM file format is a royalty-free, open media container designed for the web. Unlike proprietary formats that may require paid licensing, WebM is native to the open web and aligns perfectly with the philosophy of Linux distributions. On an Ubuntu system, support for viewing these files is generally robust, but creating them requires understanding the underlying structure. WebM typically relies on video streams encoded with VP8, VP9, or the newer AV1 codec, paired with Vorbis or Opus audio.

Basic Conversion Strategies

The simplest method to convert a video involves mapping the input streams directly to the libvpx-vp9 video encoder and the libopus audio encoder. This combination is currently the industry standard for high-quality WebM files. The following command takes an input file and converts it using default settings, which automatically selects a variable bitrate suitable for the resolution:

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

In this command, the -c:v flag specifies the video codec and -c:a handles the audio. While effective, the defaults may not yield the best file size to quality ratio.

Controlling Quality with Constant Rate Factor

For a more refined control over the visual fidelity, one should utilize the Constant Rate Factor (CRF) mode. This setting allows the encoder to maintain a consistent quality level throughout the video, allocating more data to complex scenes and less to static ones. For VP9, the CRF scale ranges from 0 to 63, where lower numbers result in higher quality and larger file sizes. A value between 30 and 40 is typically recommended for 1080p content.


Pass 1: This step does not generate a usable video file. It writes statistics to a log file. On Linux systems, these logs are typically written to the current working directory.

ffmpeg -i input_video.mp4 -c:v libvpx-vp9 -b:v 2M -pass 1 -an -f null /dev/null

Pass 2: This step reads the log file and generates the final video.

ffmpeg -i input_video.mp4 -c:v libvpx-vp9 -b:v 2M -pass 2 -c:a libopus output.webm

In these commands, -b:v 2M sets a target average bitrate of 2 Megabits per second. The -an flag in the first pass disables audio processing to speed up the analysis, as audio does not affect video compression statistics. The -f null /dev/null segment tells the system to discard the video output stream for the first pass, as only the log file is needed.

Processor Usage and Speed Settings

Encoding video into VP9 is computationally expensive. On an Ubuntu machine, you can manage the trade-off between encoding speed and compression efficiency using the -deadline option. The available values are good, best, and realtime. For archiving or web publishing where encoding time is less critical than file size, best is ideal.

Additionally, to utilize multi-core processors effectively (a standard feature in most modern Ubuntu hardware configurations), you should set the -row-mt 1 flag. This enables row-based multithreading, significantly speeding up the process on the libvpx encoder.

If your Ubuntu system is configured with high-quality audio hardware or you are processing music videos, you may wish to force a specific audio bitrate using the -b:a flag. Furthermore, if the source audio is 5.1 surround sound but the target is a web browser that stereo downmixing, you can specify channels with -ac.

ffmpeg -i input_video.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -c:a libopus -b:a 128k -ac 2 output_stereo.webm

Transparency and Alpha Channels

One of the unique features of WebM is its support for transparency (alpha channels), which is highly valuable for web overlays.10 If your input file (such as a ProRes 4444 MOV file) contains transparency, it can be preserved. You must specify the pixel format explicitly.

ffmpeg -i transparent_input.mov -c:v libvpx-vp9 -pix_fmt yuva420p -metadata:s:v:0 alpha_mode=1 -c:a libopus output_with_alpha.webm

Next Generation: AV1 Encoding

For users seeking the absolute cutting edge, the AV1 codec offers significantly better compression than VP9. However, it requires substantial CPU power. On Ubuntu, ensure you are using a recent build that includes libaom-av1 or libsvtav1. The command structure is similar but relies on the libaom-av1 encoder.

ffmpeg -i input_video.mp4 -c:v libaom-av1 -crf 30 -b:v 0 -strict experimental -c:a libopus output_av1.webm

Note that -strict experimental may be required depending on the version of the libraries installed on your distribution.

Handling Subtitles and Fonts

When dealing with subtitles in WebM for Ubuntu environments, there are two approaches: hard-coding (burning) them into the video or using WebVTT sidecar files. WebM does not support embedding soft subtitles in the same way MP4/MKV containers do for all players.

If you choose to burn subtitles into the video, the operating system's font configuration becomes relevant. The software looks for fonts in the standard Linux directories such as /usr/share/fonts or ~/.local/share/fonts. Ensure the font used in your subtitle file exists in these directories to avoid rendering errors or fallbacks to the default system monospace font.

ffmpeg -i input_video.mp4 -vf subtitles=subs.srt -c:v libvpx-vp9 -b:v 0 -crf 30 -c:a libopus output_subbed.webm

Online Tools

You can use all of these commands for vp9 online at https://webmconverter.app using one to the video converters located at https://webmconverter.app/video-converters simply select your video file on the appropriate video converter page to get started.


Create your website for free! This website was made with Webnode. Create your own for free today! Get started