Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Latest commit

 

History

History
72 lines (58 loc) · 2.74 KB

README.md

File metadata and controls

72 lines (58 loc) · 2.74 KB

movrepair

Movrepair is a script that attempts to repair a broken .mov file. In my specific use-case, the video files appeared to be truncated in the middle of the Movie Data atom (mdat), rendering the size of the mdat atom header too large, and all following atoms were missing (e.g. the important Movie Atom moov with all metadata).

This script will take a working reference video file and copy all atoms except for the mdat atom, which will be used from the broken input file.

Usage

To show the atoms of a (here broken) file:

$ python movrepair.py 0A3C0B00.MOV
file size: 297.5MiB
* ftyp (24.0B)
* wide (0.0B)
* mdat (1.4GiB)

Attempt to repair the file:

$ python movrepair.py reference.MOV --repair 0A3C0B00.MOV
Output file: 0A3C0B00-fixed.MOV
Broken file's mdat size adjusted from 1.4GiB to 297.5MiB
Adjusting "mvhd" duration from 4.5045s to 13.540166666666666s.
Adjusting "mdhd" duration from 4.5045s to 13.540166666666666s.
Adjusting "mdhd" duration from 4.5045s to 13.540166666666666s.
Adjusting "mdhd" duration from 4.5045s to 13.540166666666666s.
Adjusting sample count from 216216 to 649928
Extending b'in24' chunk offset table
Adjusting sample count from 135 to 405
Extending b'AVdh' chunk offset table
Extending b'AVdh' sample size table
stsz count: 405
Removing tmcd track
Updated moov atoms: mvhd, tkhd, tkhd, tkhd, elst, elst, elst, mdhd, mdhd, mdhd, stts, stco, stts, stco, stsz

If the "repaired" file still does not work, try using a video file that is at least as long as the file you're trying to repair and pass the --no-fix-metadata option.

$ python movrepair.py reference.MOV --repair 0A3C0B00.MOV --no-fix-metadata
Output file: 0A3C0B00-fixed.MOV
Broken file's mdat size adjusted from 1.4GiB to 297.5MiB

Disclaimer: Use at your own risk.

Synopsis

usage: movrepair.py [-h] [-o OUTPUT] [-R REPAIR] [--no-fix-metadata]
                    [--dump-moov]
                    file

positional arguments:
  file                  A working video file. If no additional options are
                        specified, the to-level atoms of this file will be
                        displayed.

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        The repaired output filename.
  -R REPAIR, --repair REPAIR
                        A file to repair using the working input file.
  --no-fix-metadata     Don't try to fix the `moov` atom metadata duration and
                        sample counts. This will require the input FILE to be
                        the same length or longer than the REPAIR file.
  --dump-moov           Dump the input FILE's `moov` atom to stdout.