MKV a MP4: Convert MKV to MP4 Without Losing Quality

Remux or re-encode: the choice that decides quality · Prerequisites and versions · Steps 1 and 2: Install FFmpeg and inspect the MKV · Step 3: Run the basic lossless remux · Step 4: Keep every audio track, subtitle and chapter · Step 5: Fix audio that MP4 cannot hold · Step 6: Convert subtitles, or burn them in · Steps 7 and 8: Tag HEVC for Apple and add faststart · Steps 9 and 10: Fix timestamps, then prove nothing changed · Steps 11 and 12: Batch a folder, and re-encode only when forced · Complete project: a remux script with safe fallbacks · Common pitfalls · Troubleshooting · Advanced tips · Common questions
Most MKV files can become MP4 without touching a single pixel. The method is called remuxing: you copy the encoded video and audio out of the Matroska container and place them in an MP4 container, with no re-encode in between. People type the job as “mkv a mp4” (the Spanish phrasing) or “convert MKV to MP4”, and the lossless route works only when every stream inside the file is something MP4 can carry.
FFmpeg does the remux in one command. HandBrake normally re-encodes instead, so this tutorial treats it as the fallback and not the default. Its documentation has a page on web-optimised MP4 output, which is the same moov-first file layout FFmpeg writes with the faststart flag you will meet in step 8.
The workflow below has 12 steps, a troubleshooting list and a finished script that decides for you what to copy, what to convert and what to drop. If your source is a phone clip and not an MKV, our guide to converting iPhone video to MP4 without losing quality covers the HEVC and MOV side of the same container question.
Remux or re-encode: the choice that decides quality
Start with the table. Every MKV to MP4 method falls into one of two families, and only one of them keeps the picture bit-for-bit identical.
| Method | What happens to video | Quality loss | Speed | Use it when |
|---|---|---|---|---|
FFmpeg stream copy (-c copy) | Copied untouched | None | Disk-bound, usually seconds to minutes | Video is H.264, HEVC or AV1 and audio is AAC or AC-3 |
| FFmpeg copy video, convert audio | Copied untouched | None on video, audio re-encoded | Fast | DTS, TrueHD or Opus audio blocks a clean copy |
FFmpeg re-encode (libx264 or similar) | Decoded and encoded again | Small but real | Slow, CPU or GPU bound | Video codec is not MP4-safe, or you must burn in subtitles |
| HandBrake 1.11.2 | Re-encoded | Small but real | Slow | You want a GUI and a preset, and accept a new encode |
| VLC Convert/Save | Re-encoded by the chosen profile | Small but real | Slow | You already have VLC and need a one-off file |
| MKVToolNix 104.0 | Not applicable (writes MKV, not MP4) | None | Fast | Inspecting, splitting or cleaning the MKV before conversion |
| Browser converters | Usually re-encoded | Depends on the site | Upload-bound | Small files you are happy to upload |
A container is a box. MKV and MP4 are both boxes, and the codecs inside (H.264 for video, AAC for audio) are the actual compressed picture and sound. Moving a box’s contents from one box to another changes nothing about the contents. That is a remux. Compression degrades the picture only when you decode the video and compress it again, which is a re-encode.
The decision rule is short. If the video codec is H.264, HEVC (H.265) or AV1, copy it. If the audio is AAC, AC-3 or E-AC-3, copy that too. Anything else gets converted on its own, and the video stays untouched unless the video codec itself is the problem. Our reference on what an MP4 file is and how to open, edit and convert one goes deeper on the container structure if you want the background.
One caveat shapes the whole tutorial. A remux guarantees the picture is identical to the source, but it does not guarantee the file plays everywhere. MP4 can store AV1 or HEVC, yet an older TV may still refuse to decode them. Lossless and compatible are two separate goals, and the steps below handle each one on purpose.
It is also fair to ask if a search for “mkv a mp4” should end in a conversion at all. MKV holds more track types than MP4, plays fine in VLC and most media servers, and makes a good archive format. Convert when a device, an editor or an upload form demands MP4. If nothing does, keep the MKV and skip the work. Many people end up keeping both, with the MKV as the master and the MP4 as the portable copy.
Prerequisites and versions
You need a computer, a terminal and one test MKV. Everything else is free. The table lists what the vendors’ own pages showed on November 29, 2026.

| Tool | Version checked | Price | Role in this tutorial |
|---|---|---|---|
FFmpeg (includes ffprobe) | Current stable build from ffmpeg.org (see text) | Free, open source | Remux, audio conversion, subtitle conversion, verification |
| HandBrake | 1.11.2 | $0, no account | GUI re-encode fallback |
| MKVToolNix | 104.0, released November 22, 2026 | Free download, no paid tier listed | Inspect, extract and clean MKV files |
| VLC media player | Latest from videolan.org | Free | Playback test and a one-off Convert/Save |
| Terminal | Bash, zsh, PowerShell or Command Prompt | Built in | Runs every command below |
| Test file | Any MKV, ideally with 2 audio tracks and subtitles | Your own | Exercises the stream-mapping steps |
The FFmpeg news list on ffmpeg.org shows FFmpeg 9.1 “Gauss” dated November 20, 2026. The commands in this tutorial use options that FFmpeg has carried for many releases, so a slightly older build works too. What matters is which branch your package manager ships. The FFmpeg web commit log shows the project still adds point releases to older branches, such as FFmpeg 5.1.7 in August 2025, so a distribution package can sit several majors behind the download page.
HandBrake 1.11.2 was a maintenance release, and it bundles FFmpeg 8.0.2 and SVT-AV1 4.1.0 inside the app. That bundled FFmpeg is separate from the one you install for the command line. Both can exist on your machine and neither affects the other.
Plan for disk space equal to the size of the source file. A stream copy produces an MP4 almost exactly as large as the MKV, because the compressed data is the same. The faststart pass in step 8 briefly needs room for a second copy while it rewrites the file. On a laptop with a nearly full drive, that temporary copy is the step most likely to fail halfway.
Scripting steps assume Bash. That means Linux, macOS, Windows Subsystem for Linux or Git Bash. Windows Command Prompt and PowerShell equivalents appear in step 11. Decide up front where the finished file has to play, whether that is a phone, a web page, an editor or a television, because the answer settles the HEVC, AV1 and audio choices later on.
Steps 1 and 2: Install FFmpeg and inspect the MKV
Step 1: install FFmpeg. Use the package manager for your system, then confirm both programs are on your path. The Windows package name below is the one the winget catalogue uses for the Gyan build.
# Windows (PowerShell)
winget install Gyan.FFmpeg
# macOS (Homebrew)
brew install ffmpeg
# Debian / Ubuntu
sudo apt install ffmpeg
# Check that both tools run
ffmpeg -version
ffprobe -version
The first line of output prints a version string such as ffmpeg version 9.x. If the command is not found on Windows, close the terminal and open a new one so the path refreshes.
Step 2: inspect before you convert. Never guess what is inside an MKV. A one-line probe tells you every stream, its type and its codec, and that list decides every later command.
ffprobe -v error -show_entries stream=index,codec_name,codec_type -of compact input.mkv
Example output for a typical movie rip (yours will differ):
stream|index=0|codec_name=hevc|codec_type=video
stream|index=1|codec_name=eac3|codec_type=audio
stream|index=2|codec_name=aac|codec_type=audio
stream|index=3|codec_name=subrip|codec_type=subtitle
stream|index=4|codec_name=hdmv_pgs_subtitle|codec_type=subtitle
stream|index=5|codec_name=ttf|codec_type=attachment
Read it top to bottom. Stream 0 is HEVC video, which MP4 accepts. Streams 1 and 2 are E-AC-3 and AAC audio, both fine. Stream 3 is a text subtitle that needs converting. Stream 4 is an image-based subtitle that MP4 cannot hold as text. Stream 5 is an embedded font attachment, which MP4 has no slot for at all. This single file contains one example of each problem you will meet.
Use this table to turn each codec name from the probe into an action. Playback support varies by device, so treat “test first” as a real instruction.
| ffprobe codec name | What it is | MP4 verdict | Action |
|---|---|---|---|
h264 | H.264 / AVC video | Safest choice | Copy |
hevc | H.265 video | Stored fine, playback depends on device | Copy and add the hvc1 tag |
av1 | AV1 video | Stored fine, less universal playback | Copy, test on target device |
vp9 | VP9 video | Conditional support | Test first, re-encode if it fails |
aac | AAC audio | Preferred | Copy |
ac3, eac3 | Dolby Digital, Dolby Digital Plus | Supported, varies by player | Copy, convert to AAC if a player stays silent |
dts, truehd, flac, opus | Surround and lossless audio | Weak or inconsistent playback | Convert to AAC |
subrip, ass | Text subtitles | Needs mov_text | Convert (ASS loses styling) |
hdmv_pgs_subtitle | Image subtitles from Blu-ray | No text equivalent | Drop, OCR or burn in |
ttf, otf | Font attachments | Not supported | Leave out of the map |
Step 3: Run the basic lossless remux
The simplest mkv a mp4 conversion is one line. It tells FFmpeg to read the MKV, copy every selected stream as it is and write an MP4.
ffmpeg -i input.mkv -c copy output.mp4
-c copy applies the copy codec to every stream, which means no decoding and no encoding takes place. By default FFmpeg picks the best video stream, the best audio stream and the first subtitle stream, so a file with several audio tracks loses all but one. The next step fixes that.
FFmpeg’s own documentation shows a second form that keeps every stream:
ffmpeg -i input.mkv -map 0 -c copy output.mp4
That command succeeds only when every stream in the file is supported by MP4 and by the player you intend to use. Run it against the example file from step 2 and FFmpeg stops with an error, because the font attachment and the image subtitles break the rule. For a file with only H.264 video and AAC audio, it is the cleanest option.
When the copy works, the last lines of the console report look like this (sizes are placeholders):
frame=172800 fps=2900 q=-1.0 Lsize= 4812034kB time=02:00:00.00 bitrate=5466.0kbits/s speed= 121x
video:4731200kB audio:68512kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.2%
Two details prove it was a copy. The speed figure is high because nothing is being encoded. The muxing overhead is a fraction of a percent, which is the cost of the MP4 index. A re-encode would show far lower speed and a changed video size.
Do not rename movie.mkv to movie.mp4 and call it done. The extension is a label and the bytes inside are still Matroska. Some players sniff the real format and cope, many do not, and editors reject the file. Only a remux rewrites the container.
Step 4: Keep every audio track, subtitle and chapter
Explicit mapping puts you in control of which streams survive. The command below keeps the first video stream, every audio stream, any subtitle streams that exist, and the chapter list.

ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a -map "0:s?" \
-c:v copy -c:a copy -c:s mov_text \
-map_chapters 0 -map_metadata 0 \
output.mp4
Each option has one job. -map 0:v:0 selects the first video stream from input 0. -map 0:a selects all audio streams, so a file with English, Spanish and commentary tracks keeps all three. -map "0:s?" selects every subtitle stream, and the question mark means “do not fail if there are none”. Quote it so your shell does not treat the question mark as a wildcard.
-c:s mov_text converts text subtitles to the format MP4 understands. -map_chapters 0 requests the chapter list from the source, and -map_metadata 0 carries over the title and language tags. Without the metadata option, a multi-language file may arrive with every track labelled “und” (undetermined) in the player menu.
The mapping leaves out attachments on purpose. MKV files often embed fonts for styled subtitles and a cover image, and MP4 has no standard place for either. If you used -map 0 here, FFmpeg would try to place the font in the MP4 and fail with a “codec not currently supported in container” error on the ttf stream. Selecting streams by type avoids the failure.
Players pick a default track from the disposition flags. If your MKV marked a commentary track as default, the MP4 inherits that and the film opens with the director talking. Override it per stream:
ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a -map "0:s?" \
-c:v copy -c:a copy -c:s mov_text \
-disposition:a:0 default -disposition:a:1 0 \
-disposition:s 0 \
output.mp4
That marks the first audio track as default, clears the flag on the second, and switches subtitles off by default so they appear only when the viewer chooses them. Adjust the indexes to match your own probe output. Indexes here count within each type, so a:1 means the second audio stream, not stream number 1 of the whole file.
Step 5: Fix audio that MP4 cannot hold
Audio is the most common reason a clean copy fails. AAC always works. AC-3 and E-AC-3 are supported by MP4, but behaviour varies by player, and they are likelier to play on modern devices than DTS, FLAC or TrueHD. MP4 can accept some of those three in particular implementations, yet playback support is much weaker than for AAC.
When a file mixes codecs, convert only the awkward track and copy the rest. Stream-specific codec options make that possible:
ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a \
-c:v copy \
-c:a:0 aac -b:a:0 384k \
-c:a:1 copy \
output.mp4
Here the first audio track (say, a DTS 5.1 mix) becomes AAC at 384 kb/s while the second track (already AAC) is copied. Surround channel layout is preserved because the command does not set -ac. Add -ac 2 only if you want a stereo downmix for phones.
Bitrate defaults that hold up in practice are 256 kb/s for stereo and 384 kb/s for 5.1. These are working preferences, not specifications. Raise them if you can hear artefacts on music-heavy content. Lossless sources such as FLAC or TrueHD lose their lossless status once converted to AAC. If that matters, keep the MKV as your archive copy and make the MP4 purely for playback.
Here is the kind of message FFmpeg prints when you try to copy an unsupported audio codec into MP4:
[mp4 @ 0x...] Could not find tag for codec truehd in stream #1, codec not currently supported in container
[out#0/mp4 @ 0x...] Could not write header (incorrect codec parameters ?): Invalid argument
The fix is always the same: read the codec name in the message, then add a per-stream -c:a:N aac option for that stream. Opus and FLAC are the two where FFmpeg may succeed in writing the file, yet the result can still fail on a television or an older phone. Converting to AAC removes the doubt.
Consider the cost side. Audio conversion takes seconds, even on a long film, because audio is a small share of the data. Video is where the time and the quality risk sit, and your video stream stays untouched throughout this step. That asymmetry is the reason “copy video, convert audio” deserves a place in every conversion script you write.
Step 6: Convert subtitles, or burn them in
MP4 stores subtitles as timed text in a format called mov_text (also written tx3g). That means three families of MKV subtitle behave three different ways.
SRT subtitles convert cleanly
SubRip (subrip in the probe) is plain text with timestamps. It converts to mov_text with no loss that matters, because SRT has little styling to lose. Add -c:s mov_text and map the stream, and you are finished. If the timing is off or the file needs editing first, fix the SRT before the remux, since changing it afterwards means unpacking the MP4 again.
ASS and SSA keep the words, lose the styling
Advanced SubStation Alpha files carry fonts, colours, positions and animated effects. Conversion to mov_text keeps the dialogue and drops most of the styling, so karaoke effects, sign translations placed on screen and custom fonts all flatten into plain bottom-centre text. If the styling matters, burn the subtitles into the picture. That forces a video re-encode, so it is a trade you make on purpose:
ffmpeg -i input.mkv \
-vf "subtitles=input.mkv:si=0" \
-c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a copy \
-movflags +faststart \
output_burned.mp4
si=0 picks the first subtitle stream inside the same file. Burned-in subtitles cannot be switched off afterwards, so keep an un-burned copy if you share the file widely. Another route is to extract the ASS file beside the MP4 (-map 0:s:0 subs.ass) and load it in a player that supports it, such as VLC.
PGS subtitles need a decision
PGS (hdmv_pgs_subtitle) comes from Blu-ray discs. These are pictures of text, not text, so MP4 cannot store them as ordinary subtitles. You have three practical choices. Drop them and accept no subtitles. Run OCR with a tool such as Subtitle Edit to turn them into an SRT, then convert that. Or burn them into the video, which re-encodes the picture:
ffmpeg -i input.mkv \
-filter_complex "[0:v][0:s:0]overlay[v]" \
-map "[v]" -map 0:a \
-c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a copy \
output_pgs_burned.mp4
Forced subtitles, the ones that translate only the foreign-language lines, are the case where burning in is most defensible. Without them a viewer misses a few lines of dialogue and has no menu to turn anything on.
Steps 7 and 8: Tag HEVC for Apple and add faststart
Step 7: tag HEVC as hvc1. Video from MKV files often arrives with an hev1 sample tag. Apple’s QuickTime, Safari and iOS expect hvc1 and may show a black frame or refuse the file when they meet the other tag. The tag is a label in the container, so changing it does not re-encode anything.
ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a -c:v copy -tag:v hvc1 -c:a copy \
output.mp4
Skip this option for H.264 files. It matters only for HEVC. AV1 gets the right tag automatically.
Step 8: move the index to the front with faststart. An MP4 file stores its index, called the moov atom, so players know where every frame lives. FFmpeg normally writes it at the end, because it cannot know the final layout until it finishes. A web player then has to download the whole file, or seek to the end, before playback starts. The +faststart flag makes FFmpeg rewrite the file once more so the index sits at the start.
ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a -c:v copy -tag:v hvc1 -c:a copy \
-movflags +faststart \
output.mp4
The rewrite pass reads and writes the whole file again, which costs a little time and temporary disk space but no quality. Local playback does not need faststart. Anything you upload, embed on a page or stream over HTTP does. HandBrake exposes the same idea as its web-optimised setting, as linked earlier.
The two flags are cheap, so a sensible default is to use both on every HEVC remux and faststart on every remux headed anywhere online. Codec choice interacts with all of this. If you are deciding between H.264 and HEVC for new exports, the export and codecs section of this blog collects the comparisons on file size and device support.
Steps 9 and 10: Fix timestamps, then prove nothing changed
Step 9: repair timestamps when sync drifts. MKV and MP4 handle timestamps differently. MKV tolerates files with missing or negative timestamps, often produced by a cut or a screen capture, while MP4 players are stricter. Symptoms are audio that starts late, a few seconds of frozen picture, or warnings about non-monotonic timestamps. Two flags fix most cases:
ffmpeg -fflags +genpts -i input.mkv \
-map 0:v:0 -map 0:a -c:v copy -c:a copy \
-avoid_negative_ts make_zero \
-movflags +faststart \
output.mp4
-fflags +genpts generates presentation timestamps where the source lacks them. -avoid_negative_ts make_zero shifts the timeline so nothing starts below zero. Both are container-level fixes and the picture is not re-encoded. If sync still drifts after these, the source was probably recorded with a variable frame rate that a stream copy cannot flatten, and you will need the re-encode path in step 12.
Step 10: verify the result. A converted file that plays is not proof of a lossless copy. Three checks, from quickest to strictest, give you evidence. First, compare duration and stream lists:
ffprobe -v error -show_entries format=duration -of csv=p=0 input.mkv
ffprobe -v error -show_entries format=duration -of csv=p=0 output.mp4
ffprobe -v error -show_entries stream=index,codec_name,codec_type -of compact output.mp4
The two durations should match to within a fraction of a second. The stream list should show your video codec unchanged, with audio and subtitles as you mapped them. Second, hash the compressed video packets in both files. A stream copy should produce identical hashes:
ffmpeg -v error -i input.mkv -map 0:v:0 -c copy -f md5 -
ffmpeg -v error -i output.mp4 -map 0:v:0 -c copy -f md5 -
Each command prints one line in the form MD5= followed by 32 hexadecimal characters. Matching lines mean the video data is byte-identical. A mismatch does not always signal a problem, since container-level rewrites can alter packet framing for some codecs, so move on to the third check before you worry. That check decodes both files and hashes the actual pixels, the strictest test there is, though it takes as long as playing the whole film:
ffmpeg -v error -i input.mkv -map 0:v:0 -f hash -hash sha256 -
ffmpeg -v error -i output.mp4 -map 0:v:0 -f hash -hash sha256 -
Identical SHA256 lines prove that every decoded frame matches, which is the real meaning of “without losing quality”. If you used a burn-in or a CRF re-encode, these hashes will differ, and that is expected.
Steps 11 and 12: Batch a folder, and re-encode only when forced
Step 11: batch convert. A loop runs the same remux over every MKV in a folder. Quote the variables so file names with spaces survive. Each pattern below writes the MP4 beside the original and leaves the source alone.
# Bash, zsh, WSL, Git Bash
for f in *.mkv; do
ffmpeg -nostdin -i "$f" -map 0:v:0 -map 0:a -map "0:s?" \
-c:v copy -c:a copy -c:s mov_text -map_chapters 0 \
-movflags +faststart "${f%.mkv}.mp4"
done
# PowerShell
Get-ChildItem *.mkv | ForEach-Object {
ffmpeg -nostdin -i $_.FullName -map 0:v:0 -map 0:a -c:v copy -c:a copy `
-movflags +faststart ($_.BaseName + ".mp4")
}
:: Command Prompt (type at the prompt, use %%f inside a .bat file)
for %f in (*.mkv) do ffmpeg -nostdin -i "%f" -c copy "%~nf.mp4"
-nostdin stops FFmpeg from reading keystrokes, which otherwise can swallow the rest of a loop’s input. The same loop pattern works for other containers. Our guide to converting MOV to MP4 covers the MOV side, including the one method it marks as lossless.
Step 12: re-encode when copy is not possible. Re-encode only when the video codec is unsuitable (an older MPEG-4 Part 2 stream or an unusual 10-bit H.264 profile), when you burn in subtitles, or when a device refuses HEVC or AV1. The FFmpeg recipe uses constant quality:
ffmpeg -i input.mkv \
-map 0:v:0 -map 0:a -map "0:s?" \
-c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p \
-c:a aac -b:a 256k -c:s mov_text \
-movflags +faststart \
output_reencoded.mp4
A CRF of 18 is a common near-transparent setting for H.264. It is not lossless, and the file can come out larger or smaller than the source depending on what the source used. Lower numbers mean higher quality and bigger files. -pix_fmt yuv420p forces 8-bit colour that every player decodes. Note that HDR metadata does not survive this recipe, so HDR sources need a different workflow.
HandBrake 1.11.2 is the graphical route to a similar result. Open the MKV, choose a preset that matches the source resolution, set Format to MP4, tick Web Optimized, and set the audio tracks to pass through where the codec allows it. HandBrake normally re-encodes the video, so use it when you want a preset-driven GUI, not when you want zero loss. The project lists it at $0 with no account.
VLC does a comparable job through Media, then Convert/Save, with a profile such as “Video – H.264 + MP3 (MP4)”. It also re-encodes. MKVToolNix 104.0 plays a different role. It works inside Matroska, so it cannot write the MP4 itself, but it is useful for identifying tracks, extracting subtitles and stripping unwanted audio before the FFmpeg pass.
Complete project: a remux script with safe fallbacks
The script below combines every step. It probes the file, refuses unsafe video codecs, copies audio that MP4 handles and converts the rest to AAC, keeps text subtitles as mov_text, skips image subtitles with a message, tags HEVC, adds faststart and verifies the video hash. Save it as mkv2mp4.sh.
#!/usr/bin/env bash
# mkv2mp4.sh - lossless-first MKV to MP4
set -eo pipefail
IN="$1"
OUT="${2:-${IN%.*}.mp4}"
if [ ! -f "$IN" ]; then
echo "usage: $0 input.mkv [output.mp4]"
exit 1
fi
for tool in ffmpeg ffprobe; do
command -v "$tool" >/dev/null || { echo "$tool not found"; exit 1; }
done
# 1. Video: copy only codecs MP4 can carry
vcodec=$(ffprobe -v error -select_streams v:0 \
-show_entries stream=codec_name -of csv=p=0 "$IN")
case "$vcodec" in
h264|hevc|av1|vp9) ;;
*) echo "Video codec '$vcodec' is not a safe MP4 copy. Re-encode instead."; exit 2 ;;
esac
vtag=()
if [ "$vcodec" = "hevc" ]; then
vtag=(-tag:v hvc1)
fi
# 2. Audio: copy AAC, AC-3, E-AC-3 and MP3, convert everything else to AAC
amap=()
n=0
while read -r codec; do
case "$codec" in
aac|ac3|eac3|mp3) amap+=("-c:a:$n" copy) ;;
*) echo "Audio $n ($codec) -> AAC 384k"
amap+=("-c:a:$n" aac "-b:a:$n" 384k) ;;
esac
n=$((n+1))
done < <(ffprobe -v error -select_streams a \
-show_entries stream=codec_name -of csv=p=0 "$IN")
# 3. Subtitles: keep text, skip images
smap=()
n=0
while read -r codec; do
case "$codec" in
subrip|ass|ssa|webvtt|mov_text) smap+=(-map "0:s:$n") ;;
*) echo "Subtitle $n ($codec) skipped: image-based, MP4 has no text form" ;;
esac
n=$((n+1))
done < <(ffprobe -v error -select_streams s \
-show_entries stream=codec_name -of csv=p=0 "$IN")
# 4. Remux
ffmpeg -hide_banner -nostdin -y -fflags +genpts -i "$IN" \
-map 0:v:0 -map "0:a?" "${smap[@]}" \
-c:v copy "${vtag[@]}" "${amap[@]}" -c:s mov_text \
-map_chapters 0 -map_metadata 0 \
-avoid_negative_ts make_zero \
-movflags +faststart "$OUT"
# 5. Verify the video packets
src=$(ffmpeg -v error -nostdin -i "$IN" -map 0:v:0 -c copy -f md5 -)
dst=$(ffmpeg -v error -nostdin -i "$OUT" -map 0:v:0 -c copy -f md5 -)
if [ "$src" = "$dst" ]; then
echo "OK video identical ($dst)"
else
echo "WARNING video hash differs, run the decoded-frame check"
fi
ls -lh "$IN" "$OUT"
That is the whole mkv a mp4 workflow in one file. Run it with chmod +x mkv2mp4.sh, then ./mkv2mp4.sh movie.mkv. For a whole folder, wrap it: for f in *.mkv; do ./mkv2mp4.sh "$f"; done. The script writes the MP4 next to the source unless you pass a second argument.
Here is how each block earns its place. Block 1 reads the codec of the first video stream and stops early on anything outside the four MP4-safe names, so you learn about a problem in a second and not after a long encode. Block 2 builds one codec option per audio stream, which is why a file with a DTS commentary and an AAC main track gets a different treatment for each. Block 3 does the same for subtitles, keeping the four text types and printing a note for anything else.
Block 4 is the single FFmpeg call. The arrays expand into the right per-stream options, and the timestamp flags guard against the sync problems from step 9. Block 5 reruns the packet hash from step 10 on both files. The script never deletes the source, and that is deliberate. Add a delete line only after you have trusted the checks on a dozen files.
Example console output for a file with a DTS track and a PGS subtitle track (yours will differ):
Audio 0 (dts) -> AAC 384k
Subtitle 1 (hdmv_pgs_subtitle) skipped: image-based, MP4 has no text form
frame=172800 fps=2900 q=-1.0 Lsize= 4790112kB time=02:00:00.00 speed= 118x
OK video identical (MD5=9f1c...e2a7)
-rw-r--r-- 1 user user 4.6G movie.mkv
-rw-r--r-- 1 user user 4.6G movie.mp4
Render settings. The table summarises what the script writes, so you can adjust it for a different target.
| Setting | Value the script uses | Why |
|---|---|---|
| Container | MP4 | Widest playback and upload support |
| Video | Copy source (H.264, HEVC, AV1 or VP9) | No generation loss |
| Resolution and frame rate | Unchanged from source | Nothing is rescaled in a copy |
| Audio | Copy AAC, AC-3, E-AC-3 and MP3, else AAC at 384 kb/s | Keeps compatible tracks, fixes the rest |
| Subtitles | mov_text for text, image types skipped | MP4 has no image subtitle slot |
| Tag | hvc1 for HEVC | QuickTime and iOS compatibility |
| Flags | +faststart | Index at the front for web playback |
From the Vipid archive. If you want a branded opener in front of the remuxed file, the Vipid intro themes list the resolution, length and frame rate of each template, which tells you whether an intro will match your MP4 before you try to join the two.
Common pitfalls
- Using
-map 0on every file. It keeps everything, including fonts, cover images and image subtitles, and FFmpeg fails the moment it meets one that MP4 cannot hold. Select streams by type, as in step 4. - Treating HandBrake as a lossless converter. It is a transcoder, and a typical MKV to MP4 job through it creates a new encode. Use it for presets, not for preservation.
- Renaming the extension. A renamed file is still Matroska. Players that sniff content may cope, while editors and phones often do not.
- Copying DTS or TrueHD and assuming it will play. The remux can succeed or fail, and playback may be silent either way. Convert that track to AAC and keep the original MKV as the master.
- Forgetting the
hvc1tag on HEVC. The file looks fine on a PC and shows a black frame in QuickTime or on an iPhone. - Skipping faststart for web uploads. Playback works locally, then the embedded player buffers for ages because the index sits at the end of the file.
- Trusting online converters with large files. Many re-encode, many cap file size, and all of them need your video uploaded. A local remux is faster and does none of those things.
- Deleting the MKV before verifying. Run step 10 first. Subtitle or chapter loss is easy to miss until you scrub through the finished file.
Troubleshooting
- “Could not find tag for codec … codec not currently supported in container”. One stream has a codec MP4 will not take. Read the codec name in the message. Audio codecs get converted with
-c:a:N aac, subtitle codecs get-c:s mov_textor get left out of the map, and fonts must not be mapped at all. - The MP4 plays with no sound on a TV or phone. The audio track is probably DTS, TrueHD, FLAC or Opus, or an E-AC-3 stream the device cannot decode. Convert that track to AAC (step 5).
- Black screen or “cannot play” for HEVC on a Mac or iPhone. Add
-tag:v hvc1to the copy command. If it still fails, the device may lack a decoder for that profile, and a re-encode to H.264 is the safe route. - Subtitles are missing in the player. The map probably did not include them, the source had only PGS images, or the player hides
mov_textby default. Probe the output, check the disposition flags, and turn the subtitle menu on manually. - Chapters disappeared. Add
-map_chapters 0. Some MKV files store chapters in an external XML, which you can pull out with MKVToolNix and load into another tool. - Audio drifts out of sync or starts late. Add
-fflags +genptsbefore the input and-avoid_negative_ts make_zerobefore the output (step 9). Persistent drift points to a variable-frame-rate source, which needs a re-encode with a constant frame rate. - The video plays but stutters on an older PC or TV. A 10-bit H.264 stream remuxes without trouble, yet many hardware decoders only handle 8-bit. Re-encode with
-pix_fmt yuv420p. - The file will not import in your editor. The container changed but the codec did not, so an editor that cannot decode HEVC, AV1 or VP9 still cannot read it. Check the editor’s supported codecs, or re-encode to H.264 for editing.
- “Invalid data found when processing input”. The MKV is damaged or truncated. Re-download or re-rip it. Adding
-err_detect ignore_errbefore the input sometimes recovers a usable file with a few bad frames. - The MP4 is a few megabytes bigger or smaller than the MKV. That is container overhead, since the two formats index data differently. It is not a sign of quality change. Step 10 gives you proof either way.
- The shell reports “no matches found” for the subtitle map. Quote it as
"0:s?"so zsh does not expand the question mark as a glob.
Advanced tips
Once the basic mkv a mp4 workflow is routine, a few extras save time on difficult sources. The first is to identify and extract with MKVToolNix before you convert. These two commands list every track with its ID and flags, then pull a subtitle track and the chapters out into separate files:
mkvmerge --identify input.mkv
mkvextract tracks input.mkv 3:english.srt
mkvextract chapters input.mkv > chapters.xml
- Mind the MP4 reader in MKVToolNix. If you read MP4 sources with mkvmerge, use v103.0 or newer, because that release fixed a possible loss of frames at the end of files in some circumstances.
- Cut without re-encoding.
ffmpeg -ss 00:10:00 -to 00:20:00 -i input.mkv -c copy clip.mp4trims a segment. A stream copy can only cut on keyframes, so the start may land a second or two early. - Copy now, decide later. Keep every MKV after conversion until you have watched the MP4 on the device you care about. Storage is cheaper than re-ripping.
- Re-encode to a smaller file on purpose. If the goal is size and not preservation, convert to HEVC or AV1 with an encoder that suits your hardware. Our guide to turning a GIF into MP4 with FFmpeg or in a browser applies the same FFmpeg container and codec logic to a very different source.
- Keep HDR in mind. A stream copy keeps HDR metadata intact. A re-encode through
libx264withyuv420pdoes not, and the result looks washed out on an HDR display. - Script the check, not just the convert. The verification block in the project takes seconds and catches silent problems that playback tests miss.
Common questions
What does “mkv a mp4” mean?
It is the Spanish way to search for “MKV to MP4”. The job is identical in any language: take the video inside an MKV container and place it in an MP4 container. The commands in this tutorial work the same on any system, whatever language the interface is in.
Can you convert MKV to MP4 without losing quality?
Yes, when the streams are compatible with MP4. FFmpeg’s -c copy moves the compressed video and audio into the new container without re-encoding, so no quality is lost. The condition is that every stream you keep is something MP4 can store and your player can decode.
Is HandBrake lossless for MKV to MP4?
No. HandBrake converts MKV to MP4 by re-encoding, so each run produces a new compressed video. Quality-based settings keep the loss small, but it is not a lossless remux tool. When the codecs already fit MP4, FFmpeg is the better route.
Why does my MP4 have no subtitles after converting?
The default FFmpeg mapping may have skipped them, or the source used image-based PGS subtitles, which MP4 cannot store as text. Map text subtitles with -map "0:s?" and -c:s mov_text. For PGS, drop them, OCR them to SRT, or burn them into the picture.
Will VLC convert MKV to MP4 without quality loss?
Not reliably. VLC’s Convert/Save feature applies an encoding profile, which re-encodes the video. VLC is excellent for playback and checking the finished file, but FFmpeg is the right tool for a stream-copy conversion.
Does MKVToolNix convert MKV to MP4?
No. MKVToolNix is a Matroska toolkit, so it writes MKV files. It is useful for inspecting tracks, extracting subtitles and removing unwanted streams before you run the conversion in FFmpeg.
Why does an iPhone or Mac show a black screen for my converted HEVC file?
Apple’s players expect the hvc1 sample tag, and MKV-sourced HEVC often carries a different one. Rerun the copy with -tag:v hvc1. This is a label change in the container and does not re-encode the video.
More from the Vipid blog
- MP4 vs MOV [2026]: 2 Containers, 1 Real Difference
- Animated GIF Cropper: Crop Every Frame, Keep the Loop
- HandBrake Video Compressor: Settings That Shrink Files
- Example Subtitle Files You Can Copy: SRT, VTT and ASS
- YouTube End Screen Template [2026]: 12 Steps, 25 Min
- Vipid intro themes resolution, length and frame rate per theme
- Promo themes product and channel promos
- Sample videos finished Vipid intros
- Vipid intro maker make a custom intro in the browser
Jonah Reyes
Jonah Reyes is the Editing & Export Editor at Vipid. He covers editing software, export settings and codecs, and the video specs of YouTube, Shorts, TikTok and Reels, plus OBS and screen recording. He builds Vipid’s spec tables from the platforms’ own documentation and re-checks them every 60 to 90 days, so the numbers in a guide match what the upload dialog actually accepts.


