Re-indexing is among the most used repair techniques.
It consists in identifying each video frame inside the file, by finding the exact location where it begins and where it ends, and copying it into a new file, while it is registered inside a QuickTime movie structure as a new frame. Once all the frames have been added, we close the movie and write the index: It's now a valid QuickTime movie file.
The main difficulty is the step of identifying frames, also called parsing. The beginning of video frames is usually easy to find, due to the presence of a certain data pattern. The end of the frame is easy to find if it's a fixed length frame, or if the next data block is again a video frame with the same, predictable data pattern. Things become more difficult if there is an audio track in the movie, as audio and video data are often interleaved, and audio blocks quite difficult to parse accurately.
- Parsing of frames (most common approaches: deterministic, pattern matching, probabilistic, Decode-Validate)
- Some codec are only available as decoder. Reindexing has to be done with a dummy encoder, then the file is patched
- Codec settings need fine tuning. It's when a sample of a good file can help a lot.
- Some codecs have keyframes. It's important to identify them and configure them as keyframe in the movie index.
- Some codec use frame reordering: The order of display is different from the order of decoding.
- Incomplete, damaged frames, alien data, ... reindexing has to be strict but tolerant.
Writing a reindexing program
It's a hard task. Not because the program is very long (a few hundreds of line of code can do it), but because it requires deep understanding of a few technologies that are hard to learn:
- Image compression
- Bitstream parsing
If you have a few hundreds of hours to waste, you can try. Otherwise, it's certainly better to ask our Movie Repair Service to do it for you.