Por Lucas, fundador de FixMyVideos · Actualizado el
Repair a Corrupted MKV File
An MKV that no player will open has usually lost its beginning. A partial download, a copy that started too late, or a card recovery that only found the second half of a file all leave the same thing: no header, and the rest of the recording still sitting there, readable. Players give up at byte 0. The pictures and the sound behind that point can often be put back into a file that plays.
What is physically inside an MKV
Matroska (the format behind .mkv, and behind .webm too) is built from nested elements, each opening with an ID and a length. The front of the file carries everything a player needs to start:
EBML header "this is Matroska", the first four bytes are 1a 45 df a3
Segment the container for everything else
SeekHead a table of where the other parts sit
Info the timestamp scale and the title
Tracks one entry per stream: codec, picture size, sample rate, decoder settings
Cluster a few seconds of video and audio blocks, each with its own timestamp
Cluster ...
Cues an index of keyframes, usually at the end
Almost all of the file is clusters. Each one says when it starts and holds blocks tagged with a track number. So a cluster is self-describing in a way an MP4's media data is not: you can find it, measure it and step to the next one without any index. What a cluster does not carry is the meaning of its track numbers. That lives in Tracks, at the front, which is exactly the part that goes missing.
Checks to run before you upload anything
- Open it in VLC or mpv. Both play MKV natively. If either plays it start to finish, the file is not damaged; the player you tried first simply does not read MKV. QuickTime refuses MKV whatever its state, and on Windows a missing codec shows up as an error code; our QuickTime error 2048 and 0xc00d36c4 pages cover both.
- Look at the first bytes. On a Mac or Linux,
xxd yourfile.mkv | head -1. A healthy MKV starts with1a 45 df a3. If yours starts with anything else, the header is gone (or the file is not an MKV at all; our no valid MP4 found page has the signatures of the common formats). On Windows, the free hex editor HxD shows the same bytes. - Ask ffprobe.
ffprobe yourfile.mkvon a headerless file answers "Invalid data found when processing input" (what that error means). If it lists streams with a duration instead, the header is there and the damage is further in. - Get another copy if one exists. If the file came from a download, a transfer or a recovery tool, the original may still be whole. Fetching it again is free, and it is the only way to get back the part that is missing, as explained below.
How a file without its header is rebuilt
The engine searches the first 64 MB for a cluster whose chain holds: each cluster's length must land exactly on the next cluster, child by child, until the chain plus the trailing index covers at least 98 percent of the bytes behind it. A random four-byte match does not survive that test. From there, every fact the lost Tracks element held is read back out of the blocks themselves:
- Which codec each track is. H.264 blocks are a chain of length fields that ends exactly at the block's end, and AC-3, MPEG audio and DTS each open with their own sync word. A majority of 24 sampled blocks has to agree before a track is named.
- The timestamp scale. An audio track ticks at a known rate (one AC-3 frame is 1536 samples), so the step between its block timestamps gives the scale the header used to state.
- The frame rate. The span of the picture timestamps divided by the number of pictures. It is rounded to a standard rate only when it lands within 0.05 percent of one, because 23.976 and 24 frames per second sit just 0.1 percent apart.
- The H.264 decoder settings. When the stream repeats them in band, they are taken from there. When it does not, they are reconstructed from the slice headers and accepted only if the beginning, middle and end of the stream all decode without a single decoder complaint.
A new header is then written in front of the surviving clusters, and every cluster's timestamp is shifted so the recording starts at zero. The rebuilt MKV goes through the same conversion as any readable MKV and comes out as an MP4 that QuickTime, phones and editors open.
What came back on a test file
We check this on files we damage ourselves, so every picture can be compared to the original. A film-style encode with AC-3 sound was cut 777 bytes into its fourth cluster, which removes the header, the track table, the first three clusters and the start of the fourth. After the rebuild, every picture in the surviving clusters matched the decode of the undamaged original byte for byte, with none missing up to the last frame, and both the picture and the sound start at zero.
One decoder setting needs extra care. The chroma quantisation offset only changes how colour is reconstructed, so a wrong value decodes without a single complaint. The result is a picture that drifts towards orange and pink over each group of pictures and snaps back at the next keyframe. On grainy footage a check that compares individual pixels mostly measures the grain, so the engine also compares the average colour of each frame across 12 groups of pictures, which grain does not move. The test file was encoded with that offset set away from its default, the way film-tuned encodes often are, and it comes back with the right value and every picture identical.
When the header is intact
If ffprobe lists your streams, the file is read as it is: no rebuild needed. Its picture is converted to H.264 in an MP4, because the codecs MKV often carries (VP8, MPEG-4 Part 2, Motion JPEG) are not ones Apple players accept, and because a straight copy would carry damaged packets into the new file unchanged. An AAC soundtrack is copied as it is, untouched. Anything else (AC-3, MP3, Opus, FLAC) is converted to AAC: MP3 inside an MP4 is technically legal and plays silent in QuickTime, which we measured on a real delivery.
What cannot come back
- The part before the cut. The missing bytes held real pictures, and no rebuild invents them. What the engine can tell you is how much is gone: a recording's first cluster starts at zero, so the timestamp of the first surviving cluster is the length of what came before. The free analysis gives that figure and asks for a complete copy if you have one.
- Some tracks in a headerless file. AAC, Opus and Vorbis audio carry no sync word, so in a file that lost its header they cannot be identified from their blocks. The rebuild leaves such a track out and the analysis says so, rather than guessing. The same goes today for HEVC video and for tracks that only ever store several frames per block (laced blocks).
- A file of zeros. If the hex check shows nothing but
00 00 00 00, there is no recording in the file to rebuild, whatever its size.
Uploading your file
Upload the MKV, up to 150 GB. The analysis tells you whether the header survived, which tracks it found, and how much of the recording sits before the cut. If there are pictures to recover you get a free 5-second preview from your own file. Unlike our MP4 and MOV rebuilds, the picture here is re-encoded to H.264 at high quality, so the file plays everywhere. On a 1080p file the decoder reconstruction alone can take around a minute and a half of analysis. You pay only once the preview shows your footage: €6 under 2 GB, €18 from 2 to 20 GB, €35 from 20 to 50 GB and €59 above that, VAT included. Uploads are deleted automatically after 48 hours.
FAQ
My MKV download stopped halfway. Can it be repaired? If the download saved the beginning, the header is there and the file usually plays in VLC up to the point where it stops; the rest was never downloaded. If a tool saved only a later part of the file, that part can be rebuilt as described above, minus everything before it. Either way, downloading the file again is the only way to get the missing part.
Can I just remux it with ffmpeg? Not while the header is missing. ffmpeg needs the track table to know what the blocks are, so on a file that starts mid-cluster it stops at "Invalid data found when processing input". A remux helps when the header is intact and only the player is the problem.
Do I need a sample clip from the same source? Not for the files described here. The codec, the timing and the H.264 decoder settings were all read or reconstructed from the damaged file itself. If the reconstruction cannot be proven against the pictures, the analysis says so instead of delivering a guess.
The colours of my repaired video look wrong. Why? A decoder setting that only affects colour can be wrong and still decode without an error. That is the orange and pink drift described above. Our rebuild checks for it before delivering; if a file you repaired elsewhere shows it, the decoder settings used were not the ones the encoder wrote.
What happens to my file after upload? It is used only to analyse and repair your file, and it is deleted automatically after 48 hours. The details are on the privacy page.
Related
- Invalid data found when processing input
- Repair a corrupted MP4
- Repair a corrupted H.264 file
- QuickTime error 2048
- VLC cannot play the file
- How the recovery engine works
Vista previa gratuita · Sin compromiso
¿Todo listo para recuperar tu vídeo?
Sube tu archivo y obtén gratis una previsualización de 5 segundos en aproximadamente un minuto. Pague solo si la previsualización le parece correcta.
Sube tu archivo →