Convert MP4 to webm with ffmpeg

There is no need for extra software for converting video files as long as you’re not afraid of using the shell of your Linux or MacOS. ffpmeg can do a lot for you.

For streaming and uploading videos, WebM is the better option because it’s highly compatible with modern browsers and popular for HTML5. For higher-quality playback and compatibility with more devices, MP4 might be more appropriate.

Here a simple way to convert an existing mp4 video to webm:

ffmpeg -i in.mp4 -c:v libvpx-vp9 -crf 25 -b:v 0 -b:a 192k -c:a libopus out.webm

Parameters explained:

  • -i in.mp4: Input file named in.mp4
  • -c:v libvpx-vp9: The target codec libvpx-vp9 which is the VP9 video encoder for ​WebM.
  • -crf 25: For libvpx, there is no default, and CRF can range between 0 and 63. 31 is recommended for 1080p HD video. Lower means better quality. If you’re unsure about what CRF to use, begin with the default and change it according to your subjective impression of the output. Is the quality good enough? No? Then set a lower CRF. Is the file size too high? Choose a higher CRF. A change of ±6 should result in about half/double the file size, although your results might vary.
  • -b:v 0: Specifies the target video bitrate for the output file. However, setting it to 0 has a specific meaning: it effectively disables the use of constant bitrate (CBR) encoding for the video stream. Instead, it implies that the video should be encoded using variable bitrate (VBR) mode.
  • -b:a 192k: Sets the target audio bitrate to 192 kbps.
  • -c:a libopus: Chooses the Opus audio codec for encoding.
  • out.webm: Output file.

The same command can also convert a .mkv file to webm. Absolutely no need to remux anything.

ffmpeg -i in.mkv -c:v libvpx-vp9 -crf 25 -b:v 0 -b:a 192k -c:a libopus out.webm