Code Monkey home page Code Monkey logo

movrepair's Introduction

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.

movrepair's People

Contributors

niklasrosenstein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

movrepair's Issues

AssertionError but don't know why

I tried to repair a file from Insta360 X2 but movrepair crashs. Python 3, Windows 11.

python movrepair.py VID_20220605_135052_00_024.insv --repair VID_20220605_134145_00_023.insv
Output file: VID_20220605_134145_00_023-fixed.insv
Traceback (most recent call last):
File "C:\Users\schmi\OneDrive\Desktop\Videoretten\movrepair.py", line 277, in
sys.exit(main())
File "C:\Users\schmi\OneDrive\Desktop\Videoretten\movrepair.py", line 267, in main
return repair_file(reference, broken, output, do_fix_metadata=not args.no_fix_metadata)
File "C:\Users\schmi\OneDrive\Desktop\Videoretten\movrepair.py", line 186, in repair_file
for atom in MovAtomR.make_root(reference).iter_atoms():
File "C:\Users\schmi\OneDrive\Desktop\Videoretten\movio.py", line 146, in iter_atoms
atom.skip()
File "C:\Users\schmi\OneDrive\Desktop\Videoretten\movio.py", line 129, in skip
assert nbytes >= 0
AssertionError

stsz.table: argument out of range

$ python3 movrepair.py ../working.mp4 --repair ../../file000083.mp4

Output file: ../../file000083-fixed.mp4
Broken file's mdat size adjusted from 828.4MiB to 828.4MiB
Adjusting "mvhd" duration from 4.664s to 316.65s.
Adjusting "mdhd" duration from 4.6572708333333335s to 316.19360416666666s.
Adjusting "mdhd" duration from 4.664022222222222s to 316.6519777777778s.
Adjusting sample count from 1 to 67
Adjusting sample count from 214 to 14528
Extending b'mp4a' chunk offset table
Extending b'mp4a' sample size table
stsz count: 14596
Adjusting sample count from 1 to 67
Adjusting sample count from 15 to 1018
Adjusting sample count from 1 to 67
Adjusting sample count from 14 to 950
Adjusting sample count from 1 to 67
Adjusting sample count from 15 to 1018
Adjusting sample count from 1 to 67
Adjusting sample count from 13 to 882
Adjusting sample count from 1 to 67
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 3 to 203
Adjusting sample count from 1 to 67
Adjusting sample count from 13 to 882
Adjusting sample count from 1 to 67
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 2 to 135
Adjusting sample count from 1 to 67
Adjusting sample count from 6 to 407
Adjusting sample count from 2 to 135
Adjusting sample count from 3 to 203
Adjusting sample count from 1 to 67
Adjusting sample count from 12 to 814
Adjusting sample count from 1 to 67
Adjusting sample count from 3 to 203
Extending b'avc1' chunk offset table
Extending b'avc1' sample size table
stsz count: 9437
Traceback (most recent call last):
  File "repair/movrepair/movutils.py", line 146, in pack_into_stream
    fp.write(self.fmt.pack(*value))
struct.error: argument out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "movrepair.py", line 279, in <module>
    sys.exit(main())
  File "movrepair.py", line 269, in main
    return repair_file(reference, broken, output, do_fix_metadata=not args.no_fix_metadata)
  File "movrepair.py", line 227, in repair_file
    fix_metadata(scale_factor, reference_atoms[b'moov'])
  File "movrepair.py", line 169, in fix_metadata
    stsz_atom.data = stsz.pack()
  File "repair/movrepair/movutils.py", line 346, in pack
    self.pack_into_stream(fp)
  File "repair/movrepair/movutils.py", line 342, in pack_into_stream
    field.pack_into_stream(type(self), fp, value)
  File "repair/movrepair/movutils.py", line 179, in pack_into_stream
    super(ListField, self).pack_into_stream(struct_type, fp, value)
  File "repair/movrepair/movutils.py", line 149, in pack_into_stream
    struct_type.__name__, self.name, e))
movutils.PackError: field stsz.table: argument out of range

I need help

Hi,

I have some mov file encrypted 150kb from header but moov atom still in file how can i repair this mov file via hexedit with reference file?

EOF while reading atom data

Hello, I'm trying to repair a mov video and I have got this error:

Traceback:

C:\Users\jaime\Downloads\movrepair-master>python movrepair.py RE.MOV --repair DA.MOV
Output file: DA-fixed.MOV
Traceback (most recent call last):
  File "C:\Users\jaime\Downloads\movrepair-master\movrepair.py", line 277, in <module>
    sys.exit(main())
  File "C:\Users\jaime\Downloads\movrepair-master\movrepair.py", line 267, in main
    return repair_file(reference, broken, output, do_fix_metadata=not args.no_fix_metadata)
  File "C:\Users\jaime\Downloads\movrepair-master\movrepair.py", line 194, in repair_file
    atom = atom.to_atomd()
  File "C:\Users\jaime\Downloads\movrepair-master\movio.py", line 165, in to_atomd
    return MovAtomD(self.tag, self.read_data(), parent=parent)
  File "C:\Users\jaime\Downloads\movrepair-master\movio.py", line 109, in read_data
    raise MovFileError('reached EOF while reading "{}" atom data'.format(
movio.MovFileError: reached EOF while reading "♣♠9" atom data

OS: Windows 11
Python: 3.9

What can I do? Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.