webm to mp4 conversion using ffmpeg

As your input file report a strange frame rate value 1k fps coming from the tbs and tbr value (look here for their definition)

the encoder generate a different result, 16k tbn, 1k tbc (default)

So by calling :

ffmpeg -fflags +genpts -i 1.webm -r 24 1.mp4

You configure ffmpeg to generate new pts (a.k.a Presentation TimeStamp) for each frame and you set the target frame-rate to 24.

So your output mp4 file info (ffmpeg -i ....) change from

Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 4327 kb/s, 1000.09 fps, 1k tbr, 16k tbn, 2k tbc

to

Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1670 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc

Re-mux WebM to MP4

If you want to stream copy (re-mux) and avoid re-encoding:

ffmpeg -i input.webm -c copy output.mp4

This will copy the VP9/VP8 video and Opus/Vorbis audio from WebM to MP4. This is like a "copy and paste". No re-encoding occurs, so no quality is lost and the process is very fast.

If you get error: "opus in MP4 support is experimental"

If you get this error:

opus in MP4 support is experimental, add '-strict -2' if you want to use it.
Could not write header for output file #0 (incorrect codec parameters ?): Experimental feature

Then either:

  • Use a newer ffmpeg as Opus in MP4 is no longer experimental in newer ffmpeg versions.
  • Or add -strict experimental (or the alias -strict -2) if you are stuck with outdated ffmpeg.

I was able to convert byffmpeg -i video.webm -strict experimental video.mp4.


I summarize here the results of converting from webm to mp4 using the many command line options suggested.

We assume here that if you're asking this question, then you're forced to use webm because the Android device emulator within Android Studio generated it for you, and you're on a Mac so you'd really like to use iMovie to edit the video.

1 ffmpeg -i vid.webm vid-1.mp4 Ref Takes 17.8 sec. Output file is 1.5 MB.

2 ffmpeg -i vid.webm -crf 1 -c:v libx264 vid-2.mp4 Takes 18 sec. Output file is 7.6 MB.

3 ffmpeg -i vid.webm -crf 0 -c:v libx264 vid-3.mp4 Ref Takes 21 sec. Output file is 11.9 MB.

4 ffmpeg -fflags +genpts -i vid.webm -r 24 vid-4.mp4 Ref Takes 0.16 sec. Output file is 1.5 MB.

5 ffmpeg -i vid.webm -c copy vid-5.mp4 Ref Takes 2.8 sec. Output file is 64.6 MB.

6 ffmpeg -i vid.webm -strict experimental vid-6.mp4 Ref Takes 18 sec. Output file is 1.5 MB.

7 ffmpeg -i vid.webm -c copy -strict experimental vid-7.mp4 Ref Takes 0.16 sec. Output file is 64.6 MB.

8 ffmpeg -i vid.webm -c:v copy -strict experimental vid-8.mp4 Also Ref Takes 0.69 sec. Output file is 64.5 MB.

Only numbers 1, 2, 3, 4, and 6 can be imported to iMovie (10.2).

The version of ffmpeg used is 4.3.

This is a first step. I am leaving out the more complicated quality comparison.

Perhaps the worst trap waiting for you is that iMovie really wants to produce a 1920x1080 movie, and so you may well get two large black bars on the side. If you're editing a demo of your app in portrait mode, you'll be wasting a lot of space. If you can, ideally you'll want to produce a video in that resolution.

The most immediate sequel question is: Assuming you truly have no need for the heavily pushed Final Cut Pro (because you're a programmer, not a video editor), will FCP allow you to set your own resolution?


After some hours of testing i was able to convert a matroska/webm (Input #0, matroska,webm, from 'testit1.webm') input to a mp4 output (Output #0, mp4, to 'testit1.mp4'). The video was recorded with the mediarecorder in chrome.

ffmpeg -i testit1.webm -c copy -strict experimental testit1.mp4

However by doing this we kept the small size of the webm video. But we did't have any audio. To get the audio working we used:

ffmpeg -i testit1.webm -c:v copy -strict experimental testit1.mp4

Hope this helps if you are in the same boat.