Converting WebM to MP4 is a common task for developers, especially when building video pipelines, handling browser-recorded media, or ensuring universal playback compatibility across devices. This guide provides practical, production-ready examples using FFmpeg.
WebM is optimized for web streaming but has limited compatibility, especially with platforms like Safari and iOS. MP4 (particularly with H.264 video and AAC audio) ensures universal playback across browsers, devices, and editing tools, making it the preferred choice for developers and content creators.
Format | Container | Video Codecs | Audio Codecs | Compatibility |
---|---|---|---|---|
WebM | Matroska-based | VP8, VP9, AV1 | Vorbis, Opus | Chrome, Firefox, Opera; limited Safari/iOS support |
MP4 | MPEG-4 Part 14 | H.264/AVC, H.265/HEVC | AAC, MP3 | Nearly universal across devices, browsers, and tools |
Bottom line: MP4 ensures broader compatibility and reliable playback due to its use of widely-supported codecs like H.264 and AAC. In contrast, WebM's codecs—VP8, VP9, and AV1—are optimized for streaming but have limited support, particularly in Safari and on iOS devices.
Before converting video formats, you'll need FFmpeg installed.
macOS:
brew install ffmpeg
Ubuntu/Debian:
sudo apt update && sudo apt install ffmpeg
Windows: Download from FFmpeg's official site, or use Chocolatey:
choco install ffmpeg
Check out our guide on How to Use FFmpeg.
Simple conversion command:
ffmpeg -i input.webm output.mp4
This converts video from WebM codecs (VP8/VP9) and audio codecs (Opus/Vorbis) to MP4-compatible H.264 video and AAC audio.
For explicit codec control:
ffmpeg -i input.webm -c:v libx264 -c:a aac output.mp4
Command breakdown:
-i input.webm
specifies the input file.-c:v libx264
encodes video in H.264.-c:a aac
encodes audio in AAC.Use faststart
for streaming or downloads, ensuring quick playback:
ffmpeg -i input.webm -c:v libx264 -c:a aac -movflags faststart output.mp4
The -movflags faststart
option optimizes MP4 files for quicker playback by moving the 'moov atom' (metadata required for playback) to the start of the file. Without faststart, playback may only begin after the entire file is downloaded, resulting in delayed streaming or longer waiting times for users.
Control quality using CRF (Constant Rate Factor); lower CRF numbers yield higher quality:
Example:
ffmpeg -i input.webm -c:v libx264 -crf 23 -preset faster -c:a aac -b:a 128k output.mp4
-crf 18–28
: Adjust quality (18 is higher quality, 28 is lower).-preset
: Adjust encoding speed and compression (veryfast
, medium
, slow
).-b:a 128k
: Set audio bitrate.For more, see: Compress Video with FFmpeg
macOS/Linux:
for f in *.webm; do
ffmpeg -i "$f" -c:v libx264 -c:a aac "${f%.webm}.mp4"
done
Windows PowerShell:
Get-ChildItem *.webm | ForEach-Object {
ffmpeg -i $_.Name -c:v libx264 -c:a aac ($_.Name -replace ".webm$", ".mp4")
}
Batch process multiple files efficiently. For more details: Batch Conversion with FFmpeg
Occasionally, a WebM file may already contain MP4-compatible codecs (H.264/AAC). In these rare cases, you can avoid transcoding:
ffmpeg -i input.webm -c copy output.mp4
This is faster and preserves original quality, but it only works if the original codecs match MP4 standards. Check codecs with:
ffmpeg -i input.webm
WebM is ideal for streaming and browser capture but lacks universal compatibility. MP4 ensures seamless playback everywhere.
Task | Recommended Command |
---|---|
Basic conversion | ffmpeg -i input.webm output.mp4 |
Set codecs explicitly | ffmpeg -i input.webm -c:v libx264 -c:a aac output.mp4 |
Fast start playback | -movflags faststart |
Control quality | -crf 20 -preset slow |
Batch conversion | Shell script or PowerShell loop |
curl --request POST 'https://api.shotstack.io/v1/render' \
--header 'x-api-key: YOUR_API_KEY' \
--data-raw '{
"timeline": {
"tracks": [
{
"clips": [
{
"asset": {
"type": "video",
"src": "https://shotstack-assets.s3.amazonaws.com/footage/beach-overhead.mp4"
},
"start": 0,
"length": "auto"
}
]
}
]
},
"output": {
"format": "mp4",
"size": {
"width": 1280,
"height": 720
}
}
}'