Convert MP4 to MKV — Free Online Tool

Convert MP4 files to MKV by remuxing the container while keeping the existing H.264 video and AAC audio streams intact — or re-encode with HEVC, VP9, FLAC, or other codecs that MKV uniquely supports. MKV's open-standard Matroska container offers broader codec flexibility and superior metadata handling compared to MP4, with no streaming-focused restrictions.

FFmpeg Command

Copy this command to run the same conversion locally with FFmpeg on your desktop. Download FFmpeg

Free — no uploads, no signups. Your files never leave your browser.

Estimated output:

Conversion Complete!

Download

How It Works

When converting MP4 to MKV, the video stream (encoded with H.264/libx264 by default) and audio stream (AAC by default) are re-encoded into the Matroska container. Because both MP4 and MKV support H.264 and AAC natively, the default command performs a full re-encode at CRF 23 and 128k audio bitrate — though if you want to avoid any quality loss, you could copy streams directly using -c copy. The key difference is that MKV drops MP4's -movflags +faststart web-streaming optimization, instead offering a more flexible container that supports additional codecs like FLAC lossless audio, VP9 video, and embedded subtitle formats that MP4 handles less cleanly.

What Each Flag Does

Flag What it does
ffmpeg Invokes the FFmpeg binary — the underlying engine that handles all media decoding, encoding, and container remuxing for this MP4-to-MKV conversion.
-i input.mp4 Specifies the source MP4 file as the input. FFmpeg reads the MPEG-4 container and demuxes its video and audio streams for processing.
-c:v libx264 Re-encodes the video stream using the H.264 codec via libx264. Since H.264 is supported by both MP4 and MKV, this maintains broad playback compatibility while producing the MKV output.
-c:a aac Re-encodes the audio stream using the AAC codec. Both MP4 and MKV support AAC, so this preserves audio compatibility with media players while fitting natively into the Matroska container.
-crf 23 Sets the Constant Rate Factor for H.264 video quality at 23, which is the libx264 default. Lower values increase quality and file size; higher values reduce both. For archival MP4-to-MKV conversions, CRF 18 is often preferred to minimize perceptible quality loss.
-b:a 128k Sets the AAC audio bitrate to 128 kilobits per second, a standard quality level suitable for most stereo content. If your source MP4 contains high-fidelity or multi-channel audio, consider increasing this to 192k or 256k, or switching to -c:a flac for lossless audio in the MKV output.
output.mkv Defines the output filename with the .mkv extension, which tells FFmpeg to wrap the encoded H.264 and AAC streams in a Matroska container rather than an MP4 container.

Common Use Cases

  • Archiving a video collection from MP4 to MKV to take advantage of MKV's superior support for multiple embedded subtitle tracks (e.g., SRT, ASS, PGS) without needing separate subtitle files.
  • Re-encoding an MP4 with AAC audio to MKV with FLAC lossless audio for preservation of a home movie or documentary where audio fidelity is critical.
  • Preparing video files for playback in media center software like Kodi or Plex, which natively favors MKV containers for their richer metadata and multi-track audio support.
  • Converting an MP4 with multiple audio language tracks to MKV to ensure all tracks are preserved and properly labeled, since MKV handles multi-track audio more reliably across players.
  • Switching from MP4 to MKV as a working format during video editing, since MKV's open standard is less patent-encumbered and more forgiving of incomplete writes during processing.
  • Converting MP4 files that contain chapter markers to MKV to ensure those chapter points are preserved and recognized by desktop media players like VLC and mpv.

Frequently Asked Questions

The default command re-encodes the video using H.264 at CRF 23, which is a high-quality lossy setting but does introduce a generation of re-encoding loss. If your source MP4 is already H.264, you can avoid any quality loss by using -c:v copy in the FFmpeg command to stream-copy the video directly into the MKV container without re-encoding. For most viewers, the difference at CRF 23 is imperceptible, but for archival purposes, stream copying is the safer choice.
File size differences come from the re-encoding process. At the default CRF 23 setting, H.264 targets a perceptually consistent quality level, so the output size depends on your video's complexity rather than matching the source bitrate. A highly compressed source MP4 may produce a larger MKV, while an over-bitrated source may produce a smaller one. If file size parity is important, consider using -c:v copy to avoid re-encoding entirely, or adjust the CRF value — lower values (e.g., 18) produce larger, higher-quality files while higher values (e.g., 28) produce smaller files with more compression.
MKV actually supports a broader range of subtitle formats than MP4, including ASS/SSA styled subtitles, PGS bitmap subtitles, and WebVTT, in addition to standard SRT. MP4 is largely limited to MOV_TEXT and CEA-608/708 subtitles. Both formats support chapter markers, and MKV preserves these reliably across media players like VLC, mpv, and Kodi. If your source MP4 contains embedded subtitle tracks, they will be included in the MKV output.
Yes — FLAC is one of MKV's key advantages over MP4, which does not support FLAC natively. Replace -c:a aac -b:a 128k in the command with -c:a flac to encode lossless audio. You can also drop the -b:a flag entirely since FLAC is lossless and does not use a bitrate target. The resulting MKV will have significantly larger audio streams but perfect fidelity, making it ideal for archival or audiophile use cases.
On Linux or macOS, you can loop over files in a directory with: for f in *.mp4; do ffmpeg -i "$f" -c:v libx264 -c:a aac -crf 23 -b:a 128k "${f%.mp4}.mkv"; done. On Windows Command Prompt, use: for %f in (*.mp4) do ffmpeg -i "%f" -c:v libx264 -c:a aac -crf 23 -b:a 128k "%~nf.mkv". This applies the same encoding settings to every MP4 in the current folder and outputs a matching MKV for each.
The -movflags +faststart flag is specific to the MP4/MOV container format. It relocates the MOOV atom to the beginning of the file so browsers and streaming players can begin playback before the full file downloads. MKV uses a fundamentally different container structure (EBML-based) that does not use this mechanism. MKV does support streaming through other means, but it is generally considered less optimal than MP4 for HTTP progressive download streaming in web browsers.

Technical Notes

MP4 and MKV share codec compatibility for H.264 and AAC, meaning the encoded data itself does not need to change — only the container wrapping it. However, the default command performs a full re-encode rather than a stream copy, so adjust the CRF value carefully if quality preservation is a priority. MKV's EBML-based structure is more resilient to file corruption than MP4's MOOV atom model, making partially written MKV files recoverable in ways that MP4 files often are not. Metadata such as title, language tags, and track names transfer well from MP4 to MKV. One notable limitation: MKV is not supported natively in Safari or iOS Safari, so MKV files converted for web distribution should remain as MP4. For desktop playback with VLC, mpv, Kodi, or Plex, MKV is broadly supported and often preferred. The MKV format also supports additional video codecs not available in MP4, including PNG and MJPEG for lossless frame storage, which can be useful in specialized video production workflows.

Related Tools