webmmp4

Converting WebM to MP4 with ffmpeg

The command you want, what each part of it means, and the errors worth knowing about before you hit them.

If you are converting one file, a browser tool is faster than opening a terminal. If you are converting two hundred files, or working on a server, or need precise control over the encode, ffmpeg is the right tool. Here is what to run.

The command

ffmpeg -i input.webm -c:v libx264 -preset veryfast -crf 23 \
       -c:a aac -b:a 192k -movflags +faststart output.mp4

What each flag does

FlagPurpose
-i input.webmThe source file.
-c:v libx264Encode video with the x264 encoder, producing H.264 — the codec with the widest playback support in existence.
-preset veryfastHow much effort the encoder spends looking for savings. Slower presets give smaller files at the same quality. Options run from ultrafast to veryslow.
-crf 23Constant Rate Factor: the quality target. Lower is better and larger. 18 is near-lossless, 23 is the default, 28 is visibly compressed.
-c:a aacRe-encode the Opus or Vorbis audio as AAC, which MP4 supports properly.
-b:a 192kAudio bitrate. 128k is fine for speech, 192k is a safe general default.
-movflags +faststartMoves the file index to the beginning so the video can start playing before it has fully downloaded. Essential for web playback.

Variations worth knowing

Maximum compatibility, including older devices

ffmpeg -i input.webm -c:v libx264 -profile:v baseline -level 3.0 \
       -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart output.mp4

The baseline profile drops features that older hardware decoders cannot handle. Files are larger, but they play on almost anything.

Higher quality for editing

ffmpeg -i input.webm -c:v libx264 -preset slow -crf 18 \
       -c:a aac -b:a 256k output.mp4

Convert every WebM in a folder

On macOS or Linux:

for f in *.webm; do
  ffmpeg -i "$f" -c:v libx264 -crf 23 -preset veryfast \
         -c:a aac -b:a 192k -movflags +faststart "${f%.webm}.mp4"
done

On Windows PowerShell:

Get-ChildItem *.webm | ForEach-Object {
  ffmpeg -i $_.Name -c:v libx264 -crf 23 -preset veryfast `
         -c:a aac -b:a 192k -movflags +faststart "$($_.BaseName).mp4"
}

Audio only

This is what the WebM to MP3 converter runs:

ffmpeg -i input.webm -vn -c:a libmp3lame -b:a 192k output.mp3

Errors you are likely to hit

Unknown encoder 'libx264'

Your ffmpeg build was compiled without x264. The static builds from ffmpeg.org include it; the ones in some minimal package repositories do not. Install a full build.

height not divisible by 2

H.264 requires even dimensions. Add a scale filter that rounds down:

-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2"

The video plays but there is no sound

The audio stream was probably copied rather than re-encoded. Make sure -c:a aac is present rather than -c:a copy, since MP4 cannot reliably carry Opus.

It is extremely slow

Use a faster preset. Moving from slow to veryfast can cut encoding time by more than half for a barely perceptible quality difference at the same CRF.

Why not just copy the stream?

You cannot. -c:v copy works when moving between containers that support the same codec — MKV to MP4, for instance, where both hold H.264. WebM holds VP9 or VP8, which MP4 has no meaningful support for, so the video genuinely has to be re-encoded. That is why WebM to MP4 always takes real time, while MKV to MP4 is often instant.

Questions

What CRF value should I use?

23 is the default and works for most purposes. Use 18 to 20 if the file is going into an edit and you want headroom. Use 26 to 30 when file size matters more than fine detail. Every increase of about 6 roughly halves the file size.

Does preset affect quality?

Not directly — CRF controls quality. The preset controls how hard the encoder works to hit that quality efficiently, so a slower preset gives you a smaller file at the same visual quality, at the cost of encoding time.

Can I convert without re-encoding?

Not from WebM to MP4. The codecs are incompatible between the two containers, so re-encoding is unavoidable.

How do I install ffmpeg?

On macOS, use Homebrew with brew install ffmpeg. On Windows, use winget install ffmpeg or download a static build from ffmpeg.org. On Debian or Ubuntu, apt install ffmpeg.

Convert a file now