Convert MOV, MKV, WebM or AVI to MP4 with FFmpeg

If the file already holds H.264 or H.265 video and AAC audio, run ffmpeg -i in.mov -c copy out.mp4. It moves the streams into MP4 without touching them. WebM holds VP9 and Opus, so re-encode it with -c:v libx264 -c:a aac. For an MKV, add -map 0 -c:s mov_text or the extra audio tracks and the subtitles get left behind.

Remux Stream copy

The codecs already fit MP4. Nothing is re-encoded, so nothing is lost.

ffmpeg -i in.mov -c copy out.mp4

H.264 and AAC moved into MP4 untouched. The video and audio packets hash the same as in the MOV.

Video and audio
Same packets, same MD5
Duration
30.000 s, as in the MOV
Run time
82 ms
Output
4.5 MB
Re-encode Re-encode

The source is VP9, Opus, MPEG-4 Part 2 or anything else you need as H.264 and AAC.

ffmpeg -i in.webm -c:v libx264 -crf 23 -c:a aac out.mp4

VP9 became H.264 and Opus became AAC at 128 kb/s. 3.2 MB out of a 2.0 MB WebM.

Video
VP9 to H.264, CRF 23
Audio
Opus to AAC, 128 kb/s
Run time
2.2 s
Output
3.2 MB

Proof

What survives an MKV to MP4 copy

The MKV holds video, two audio tracks and English subtitles. Both frames are 0:04.5 of the converted MP4, with the subtitles drawn from whatever track the MP4 carries.
-map 0 -c copy -c:s mov_text Every track kept
Frame of the converted MP4 with the subtitle 'You're lucky your blood's still flowing.' drawn from its mov_text track
4 of 4 Video, AAC, AC-3 and the subtitle track. The subtitle here is read back from the MP4 itself, cue 2 of 8.
-c copy AC-3 and subtitles dropped
The same frame of the MP4 made with -c copy alone, with no subtitle
2 of 4 FFmpeg kept one video and one audio stream and exited without an error. The MP4 has no subtitle track to draw.

Footage: Sintel, © Blender Foundation, CC BY 3.0. Cut to 30 s and written into each container by us.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.webm": "https://cdn.rendobar.com/examples/convert-to-mp4/in.webm",
},
params: {
command: "ffmpeg -i in.webm -c:v libx264 -crf 23 -c:a aac out.mp4",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.webm": "https://cdn.rendobar.com/examples/convert-to-mp4/in.webm"
},
"params": {
"command": "ffmpeg -i in.webm -c:v libx264 -crf 23 -c:a aac out.mp4"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Convert MKV to MP4 and keep every track

    Stream copy
    ffmpeg -i in.mkv -map 0 -c copy -c:s mov_text out.mp4

    All 4 streams: H.264, AAC, AC-3 and the subtitles as mov_text. All 8 cues read back from the MP4.

    84 ms run 5.2 MB 30.04 s long

  2. Convert MKV to MP4 without the subtitles

    Stream copy
    ffmpeg -i in.mkv -map 0 -c copy -sn out.mp4

    Video and both audio tracks copied, subtitles left out. -sn also works with -map 0.

    81 ms run 5.2 MB 30.04 s long

  3. Put WebM video into MP4 without re-encoding

    Stream copy
    ffmpeg -i in.webm -c copy out.mp4

    Works on FFmpeg 8.0 with no -strict flag. The MP4 holds VP9 (vp09) and Opus, not H.264 and AAC.

    74 ms run 2.0 MB 30.02 s long

  4. Convert AVI to MP4

    Re-encode
    ffmpeg -i in.avi -c:v libx264 -crf 23 -c:a aac out.mp4

    MPEG-4 Part 2 and MP3 became H.264 and AAC. 4.2 MB out of a 6.0 MB AVI.

    2.2 s run 4.2 MB 30.04 s long

  5. Convert AVI to MP4 without re-encoding

    Stream copy
    ffmpeg -i in.avi -c copy out.mp4

    Copied as MPEG-4 Part 2 (mp4v) and MP3. Valid MP4, but the video is still the old Xvid codec.

    80 ms run 5.9 MB 30.04 s long

Gotchas

Where it goes wrong

Why are my subtitles and second audio track gone after converting MKV to MP4?

Without -map, FFmpeg picks one video and one audio stream and ignores the rest. -c copy only says how to treat the streams it picked. On the test MKV:

ffmpeg -i in.mkv -c copy out.mp4

Exit code 0, no warning. The MP4 holds the video and the AAC track. The AC-3 track and the subtitles are gone.

-map 0 selects every stream. Add it and the copy fails instead, because MP4 cannot store SRT:

ffmpeg -i in.mkv -map 0 -c copy out.mp4

"Could not find tag for codec subrip in stream #3, codec not currently supported in container". FFmpeg left a 0-byte out.mp4 behind.

Convert only the subtitle track with -c:s mov_text, the text format MP4 supports, and copy the rest. Or drop subtitles with -sn. Both are in the table above.

Can I convert WebM to MP4 with -c copy?

FFmpeg 8.0 writes VP9 and Opus into MP4 without complaint. Older answers say Opus in MP4 needs -strict -2. It does not on 8.0.

Copying does not turn VP9 into H.264, though. The 2.0 MB output is the same VP9 video and Opus audio in a different box. When the point of the conversion is a file that H.264 players can open, re-encode with -c:v libx264 -c:a aac.

Does ffmpeg -i in.mov out.mp4 re-encode?

Yes. With no codec options FFmpeg picks its default MP4 encoders, libx264 and the native AAC encoder, even when the source codecs would fit as they are:

ffmpeg -i in.mov out.mp4

"h264 (native) -> h264 (libx264)" in the log. 3.5 MB instead of the 4.5 MB copy, from a second lossy encode at CRF 23.

Check the codecs first. If they already fit, -c copy is lossless:

ffprobe -v error -show_entries stream=codec_type,codec_name -of csv=p=0 in.mkv

h264,video, aac,audio, ac3,audio, subrip,subtitle. H.264, AAC and AC-3 copy into MP4. SubRip needs mov_text.

Related: Web-playable MP4, Encode H.264 and H.265, Add subtitles, Convert HLS to MP4, Batch convert a folder.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.