How to Create an MKV File
Create an MKV file by remuxing, combining tracks, converting or recording directly, using MKVToolNix, FFmpeg, HandBrake or OBS Studio, then check the result.
MKV (Matroska) is a container format. It holds video, audio, subtitle tracks and chapters in one file, and it works with many different codecs. You can make an MKV in three ways. You can record straight to it. You can remux existing files, which copies the streams into a new container without re-encoding. Or you can convert, which re-encodes the video when you need a different codec or a smaller file.
Before you start
First decide whether you need a remux or a conversion. Remuxing is fast and keeps the original quality because the streams are copied as they are. Re-encoding takes longer and loses some quality, but it lets you change the codec, resolution or file size.
- Source material: a video file, or separate video, audio and subtitle files you want to combine.
- A local tool: MKVToolNix for combining and remuxing tracks, FFmpeg for command-line remuxing or conversion, HandBrake for re-encoding, or OBS Studio for recording directly to MKV. All four run on your own computer and do not need to upload your files.
- Free disk space: a remuxed file is roughly the combined size of the tracks you keep.
- Your originals: keep them until you have checked the new file.
Online converters upload your files to someone else's server. Before you use one for private recordings, read the provider's stated rules on storage and deletion, and treat those rules as claims you cannot check yourself.
Step-by-step instructions
Combine or remux files with MKVToolNix
- 1. Install MKVToolNix and open MKVToolNix GUI.
- 2. In the multiplexer, add your source files. You can also drag them into the window. Each file's tracks appear in the track list.
- 3. Untick any tracks you do not want, such as extra audio languages.
- 4. Select a track to set its language, its name and whether it is the default. Players use these settings to choose audio and subtitles automatically.
- 5. Set the destination file name and make sure it ends in .mkv.
- 6. Start multiplexing. The streams are copied without re-encoding.
The command-line tool mkvmerge does the same job. For example, mkvmerge -o output.mkv input.mp4 subtitles.srt combines a video file and a subtitle file into one MKV.
Remux with FFmpeg
To copy every stream from an existing file into MKV, run: ffmpeg -i input.mp4 -map 0 -c copy output.mkv. The -c copy option copies the streams without re-encoding them. The -map 0 option keeps every track. Without it, FFmpeg keeps only one video, one audio and one subtitle stream. To add an external subtitle file, run: ffmpeg -i input.mp4 -i subtitles.srt -map 0 -map 1 -c copy output.mkv.
Convert with re-encoding in HandBrake
Use this method when you want a different codec or a smaller file. Open the source file in HandBrake and choose a preset. Set the output format to MKV; recent versions show this option with the summary settings, and older versions place it elsewhere. Set the destination name and start the encode. The result will not be identical to the source, so compare quality before you delete the original.
Record directly to MKV in OBS Studio
In OBS Studio, open Settings, go to Output and find the recording section. Set the recording format to MKV. Depending on your version, it may be labelled mkv or Matroska Video. If OBS or your computer crashes mid-recording, the MKV file usually stays playable, while an interrupted MP4 often does not. If your editor needs MP4, use Remux Recordings in the File menu to copy the recording into MP4 without re-encoding it.
Check the output
- Play the file in a player that supports MKV, such as VLC or mpv. Check the beginning, the middle and the end, and try seeking.
- Switch between audio and subtitle tracks to confirm that the languages, names and default choices are correct.
- Check that audio stays in sync with the video throughout, especially if you added a separate audio track.
- Inspect the file's details with mkvinfo, MediaInfo or ffprobe output.mkv. Confirm that every expected track is present, the codecs are what you intended and the duration matches the source.
An MKV container does not improve quality: a remuxed file looks and sounds exactly like its source. Some devices and apps cannot play MKV files, including certain TVs, phones, video editors and upload forms. Test the file on the device or service where you will use it. If it is not supported, MP4 may work better, as long as the codecs are compatible with MP4.
Common problems and next steps
Tracks are missing after an FFmpeg remux: add -map 0 so that FFmpeg keeps every stream instead of choosing one of each type.
FFmpeg reports that only audio, video and subtitles are supported for Matroska: the source contains a data stream, such as a timecode track. Exclude it with -map 0 -map -0:d.
FFmpeg fails on subtitles from an MP4 file: MP4 subtitles often use the mov_text format, which FFmpeg cannot copy into MKV. Convert them while copying everything else: ffmpeg -i input.mp4 -map 0 -c copy -c:s srt output.mkv.
Added audio is out of sync: in MKVToolNix, set a delay in milliseconds in the track's timestamp settings, then multiplex again. In FFmpeg, place -itsoffset followed by the delay in seconds before the input that needs shifting.
The player picks the wrong language or subtitle: change the track language and default flags. You can edit an existing MKV without remuxing it by using the MKVToolNix header editor or mkvpropedit.
An editor or device rejects the MKV: remux it to MP4 with FFmpeg or OBS Studio if its codecs are compatible with MP4. If they are not, re-encode it to a format the target supports.