By Lucas, founder of FixMyVideos · Updated

untrunc or FixMyVideos: repairing a truncated MP4 or MOV

untrunc is a free, open-source command-line program that repairs truncated MP4 and MOV files. You give it two files: the broken recording and a healthy clip shot on the same camera with the same settings. If you have that healthy clip, run untrunc before you pay anyone, us included. It runs on your own computer and the footage never leaves it.

We build the FixMyVideos recovery engine. Below is what untrunc borrows from your reference clip, why our engine needs the same thing, and how to check a repaired file whichever tool made it.

What is missing from a truncated file

An MP4 or MOV holds two things. The mdat box is the media itself: compressed pictures and sound, written one after another while the camera records. The moov box is the index. It lists where every sample starts, how big it is and when it plays, and it carries the decoder configuration. For H.264 that configuration is the SPS and PPS, stored in an avcC box inside the moov; HEVC keeps its equivalent in hvcC.

Most cameras write the moov last, when you press stop. If the battery dies or the app crashes first, the media is on the card but the index never arrives, and players report "moov atom not found", show a duration of 0:00, or refuse the file.

The sample table can be rebuilt: a program walks the media and finds where each picture starts. The decoder configuration is the real problem, because without the SPS and PPS a decoder cannot turn a single macroblock into pixels. The stock Android recorder (MediaRecorder), used by many Android phones, makes this worse, because it writes the SPS and PPS only into the avcC box and never into the stream itself. We confirmed it on a 55 MB Android clip whose moov was gone. All 778 pictures the carver found were intact, and a scan of the whole file found no real parameter set anywhere.

What untrunc does with your reference clip

In broad terms, untrunc reads the healthy file's moov, takes its track layout and decoder configuration, walks the broken file's media to find where each sample begins, and writes a new index for it. That is why the reference has to match. The SPS states the picture size, the profile and the width of several fields in every slice header. A clip recorded at 4K describes a different stream from your 1080p one, even off the same body.

Matching also matters for a less obvious reason. Some fields in a borrowed configuration are never checked by the decoder at all. We delivered a 720p H.264 file whose borrowed PPS was six quantiser steps away from what the encoder had used. It decoded with zero errors and the right frame count, and the picture came out blocky and clipped at both ends of the brightness scale. Any reference-based repair carries that risk when settings differ. Our engine now checks that field on borrowed H.264 configurations and corrects it when the picture clips at both ends.

How our engine gets the same configuration without a reference

First it looks in the file: some cameras repeat the SPS and PPS inside the stream, and some damaged files keep part of their old moov. Failing that, it tries a library of configurations taken from healthy recordings. Each candidate is tested by decoding real pictures from your file, and it is accepted only if they decode silently, with no decoder error or warning. That 55 MB Android clip failed every stored profile at first. We then added 30 configurations from original, unedited Android recordings by Motorola, LG, HONOR, Xiaomi, and phones whose files did not record a make. After that, all 778 pictures decoded cleanly at 1920x1080 with no reference clip.

For H.264 there is a third way, rebuilding the configuration from the stream itself. frame_num steps by one after every reference picture, so only one field width makes it count correctly. If the decode canvas is wider than the real picture, each row wraps late and the decoder reports an error, which tells the engine where to start searching for the true width. A 3.35 GB Windows screen recording arrived with no SPS or PPS anywhere in it. The engine rebuilt them in about 3 seconds and recovered a 1530x854 picture. Three windows of 300 pictures, taken from the start, middle and end, decoded cleanly. The frame rate came out at 30 fps, and the on-screen taskbar clock, whose minute changed about every 1,800 frames, agreed.

Rebuilding from the stream has limits. It works for H.264 only, never for HEVC. Streams with B-frames are covered: a 1920x1080 recording at about 60 fps that had lost its beginning came back with all 413 of its pictures. Some other H.264 streams use slice layouts it cannot rebuild, so it finds no configuration that decodes cleanly. In those cases the file needs a match in the library or a reference clip.

When we ask for a reference clip too

If the file holds no configuration, the library has no match and synthesis cannot apply, the repair page asks for a clip from the same device. From there we are doing what untrunc does. The clip must use the same codec: an H.265 clip cannot describe an H.264 recording, and the upload is refused with both codecs named.

One Android phone clip shows what a reference can and cannot give back. The file was 31 MB, but only its first 8 MiB held data. The rest was 0xFF, which is what erased flash reads as, and the moov had gone with it. A reference clip from the same phone supplied the configuration. To measure the method, we cut a healthy clip from that phone the same way and ran it through the engine: 106 of 106 pictures and 190 of 190 AAC audio packets came back byte-identical to the original.

Two things did not come back. The phone had filmed in portrait, and that rotation flag lived in the lost moov, so the repaired file came out sideways and had to be rotated in an editor. The last picture was also partly concealed, because its bytes ran into the erased region and are physically gone. No reference clip, ours or untrunc's, can restore bytes the card no longer holds.

Check any repaired file before you trust it

Some damage only shows when you watch the file. Each failure below was measured on a real file, and every automatic decode check passed it. Run the checks on untrunc's output, on ours, or on anything else.

Frames dropped without a single error. On a DJI Osmo Pocket 3 test, made by cutting a healthy clip short, an earlier version of our carver silently skipped 216 of 722 picture slots. ffmpeg decoded the result without a complaint, because it hides missing reference pictures. The symptoms were washed-out colour, a seam across the middle of the frame, sound drifting out of sync, and QuickTime refusing to play the file. So compare the repaired duration against how long you actually recorded, and open the file in QuickTime or on an iPhone as well as in VLC. When we test a fix like that one, we cut a test copy from a healthy recording and check that every picture comes back byte for byte; on that Pocket 3 test, all 722 now do.

Motion that jerks back and forth. Streams with B-frames store pictures in a different order from the one they are shown in. A rebuilt index needs composition offsets (a ctts box) to put them back in display order. Without it, QuickTime plays them in storage order and motion shudders for the whole clip, while ffmpeg-based checks still pass. To check, run ffprobe -v error -select_streams v:0 -show_entries packet=pts_time,dts_time -of csv fixed.mp4. If the two time columns are identical on every line and the motion stutters, the file is missing that box.

Sound that is silent, shifted or garbage. Cameras interleave audio and video in chunks, and some write their sound ahead of or behind the pictures it belongs to. Find a moment with a clap or a hard consonant and watch the lips.

Colours or blockiness that look wrong. That is the mismatched configuration described earlier; try a reference recorded in exactly the same mode.

When no tool can bring it back

Some uploads contain no recording at all, and no software will change that. We have seen a 30 MB upload in which every byte was zero. Another was 24 bytes long: a container header with nothing after it. A 20 MB file held only 12,288 bytes of distinct data, 24 sectors repeated end to end, the shape a failing card or reader produces when every read returns the block it already returned.

Our engine labels these unrecoverable rather than offering a repair. For the repeated-sector case, copy the file again from the card through a different card reader or computer. For the other two, go back to the card itself, or to whatever recovery software produced the file, because the footage is not in the copy you have.

Which one to try

With a healthy clip from the same camera and settings, start with untrunc. For a plain truncation and a matching reference it is the right free tool.

If you have no such clip, if untrunc's output fails one of the checks above, or if the file came off a phone or screen recorder with no camera to shoot a reference on, upload it to FixMyVideos. Files up to 150 GB are accepted, and within a few minutes you see a free 5-second preview of the recovered picture and sound. You pay only if the preview shows your footage: €6 for a file 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

Is untrunc free and safe to use? Yes. It is open source and runs on your own machine, so the footage stays with you, which matters for confidential material.

Can untrunc repair a file without a reference video? It is designed around one. The reference supplies the decoder configuration that died with the moov, so without a healthy clip from the same camera and settings it has nothing to copy. Our engine can sometimes find or rebuild that configuration without a clip, and asks for one when it cannot.

untrunc finished, but the output plays wrong. What now? Suspect the reference first. A different resolution, frame rate or recording mode gives a configuration that does not describe your stream, so record a new one in exactly the same mode if you still have the camera. Then run the checks above.

Does FixMyVideos ever need a reference clip? Yes, when the file holds no decoder configuration, nothing in our library decodes it cleanly, and we cannot rebuild it from the stream. HEVC files can still be repaired from settings stored in the file or from our library, but the rebuild from the stream never applies to them. For H.264 it fails only on some slice layouts. The repair page then asks for a clip from the same device in the same codec.

Can I use a clip from a different camera as the reference? You can try, but look at the result carefully. Another encoder's configuration can decode without errors and still shift colours or block up the picture. Same model and same mode is the safe choice.

How long do you keep my file? Uploads are deleted automatically after 48 hours. Details are in the privacy policy.

Related

Free preview · No commitment

Ready to recover your video?

Upload your file and get a free 5-second preview in about a minute. Pay only if the preview looks right.

Upload your file →