Short answer: to convert a WebM file to a widely playable MP4 with FFmpeg, re-encode the video to H.264 and the audio to AAC, then measure the output codecs and the compatible_brands tag. On FFmpeg 9.0.2, ffmpeg -i input.webm -c copy output.mp4 exited 0 on a VP9 + Opus fixture and produced a real MP4 container, but ffprobe still reported vp9 (vp09) and opus (Opus). The first-frame RGB24 md5 matched the source WebM. The brands were isomiso2mp41 — no avc1. Copying the video and re-encoding only the audio to AAC left the video as VP9. Re-encoding with libx264 and AAC produced h264 (avc1) and aac (mp4a), brands isomiso2avc1mp41, and a different first-frame md5. Exit code 0 is not the same as an H.264 + AAC file.
This write-up is a developer checklist, not a product tutorial. The commands and numbers below were measured with pytest on grey-hoodie-v2.webm (md5 4d09713d6bde6286cc5f02a150af05c7), which was transcoded from grey-hoodie-v2.mp4 (md5 a50e13313b71a76dbd179dcdc2c2b6bf). The WebM is VP9 Profile 0, 720×1280, 24 fps, Opus stereo at 48 kHz, container duration 12.072 seconds. Five tests passed via uv run --with pytest. If your build, container, or input differs — for example a VP8 + Vorbis WebM, or an older FFmpeg that rejects Opus in MP4 — measure again before you ship the file.
Stream-copy can succeed and still leave the WebM codecs in place
A common autocomplete suggestion is "ffmpeg convert webm to mp4 without losing quality" or a lossless remux. I ran the obvious copy on this fixture:
ffmpeg -i input.webm -c copy output.mp4 FFmpeg 9.0.2 exited 0. The only muxer note was track 1: codec frame size is not set. The file that landed on disk probed as an MP4 (isom / iso2 / mp41) with video still vp9 (vp09) and audio still opus (Opus). Duration stayed near 12.065 seconds. The first-frame RGB24 md5 matched the source WebM exactly, which is what you want from a remux and not what you want if the downstream player only accepts H.264 and AAC. The copy also omitted avc1 from compatible_brands. FFmpeg itself could decode the file (ffmpeg -i copy-all.mp4 -f null - exited 0). That proves the container is readable, not that Safari, iOS, or a CMS uploader that expects avc1 will play it.
If you need a lossless remux, -c copy is the right family of command, and on this build it can write those streams into an .mp4 name. If you need a widely playable MP4, plan for a video and audio re-encode. Do not treat the .mp4 suffix as a codec conversion.
Re-encoding only one stream is still only a partial conversion
These two commands also exited 0 on the fixture:
ffmpeg -i input.webm -c:v copy -c:a aac -b:a 128k copy-v-aac.mp4 ffmpeg -i input.webm -c:v libx264 -crf 18 -pix_fmt yuv420p -c:a copy x264-copy-a.mp4 On FFmpeg 9.0.2 they measured:
-
-c:v copy -c:a aac: video stayedvp9(vp09), audio becameaac(mp4a), brands stillisomiso2mp41with noavc1, first-frame md5 still matched the WebM. -
libx264with-c:a copy: video becameh264(avc1), audio stayedopus(Opus), brands includedavc1, first-frame md5 changed.
Either output can be a valid file. Neither is a complete H.264 + AAC conversion. If a player or uploader rejects Opus in MP4, the second command will still fail even though the video looks right. If a player rejects VP9 in MP4, the first command will still fail even though the audio is AAC.
A widely playable MP4 on this fixture is libx264 plus AAC
This is the conversion that produced H.264 and AAC together:
ffmpeg -i input.webm -c:v libx264 -crf 18 -pix_fmt yuv420p -c:a aac -b:a 128k -movflags +faststart x264-aac.mp4 On this fixture, FFmpeg 9.0.2 measured: video h264 (avc1) High profile, 720×1280, 24 fps; audio aac (mp4a) LC, 48 kHz stereo; container duration 12.064 seconds; brands isomiso2avc1mp41. The file was larger than the VP9 remux (5,980,365 bytes versus 2,888,501 bytes at CRF 18), which is expected. The first-frame RGB24 md5 no longer matched the source, because a lossy re-encode is not a remux. CRF 18 is a quality choice used for this measurement, not a universal setting. If you need a smaller file, lower the bitrate or raise CRF and measure again.
Prove the output before you publish it
The pytest file in this run checks five facts on the fixture: the source identity and FFmpeg 9.0.2, that -c copy writes an MP4 whose codecs are still VP9 and Opus and whose brands omit avc1, that copying video and re-encoding audio still leaves VP9, that libx264 with copied Opus is not AAC, and that libx264 plus AAC is h264/aac with an avc1 brand and a changed first frame. Run the same measurements on your file:
uv run --with pytest pytest -q test_webm_to_mp4.py Then probe the file you actually intend to ship:
ffprobe -hide_banner output.mp4 Check codec_name, codec_tag_string, duration, and compatible_brands. If you needed H.264 and AAC and you still see vp9 or opus, the conversion is not finished, even if the command exited 0 and the filename ends in .mp4.
If you also generate short clips in a browser or a batch workflow, Voor's Bulk Video Generator is one place to queue multiple text-to-video prompts. That is optional context, not part of the FFmpeg measurements above. When you export those clips, probe the container the same way, and use the same generator only if you actually need a batch of short clips — then convert the ones that still arrive as WebM before you hand them to a tool that expects H.264 and AAC.



