How to open and repair an m4v or mp4 video file?
It is possible to repair the broken mp4 or m4v file using Untrunc.
For this method you need another video file from the same device which isn't broken.
How to install untrunc
For compilation you need a Linux installation (ideally Ubuntu) and basic ability to use a command line. You can also skip this part and run untrunc
via Docker (see the answer below), if you have that.
This is what to do:
Install some pre-requisite libraries with this command:
sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev
Get the source code for Untrunc from the GitHub repo (choose one method):
wget https://github.com/ponchio/untrunc/archive/master.zip && unzip master.zip && cd untrunc-master
- or
git clone https://github.com/ponchio/untrunc.git && cd untrunc
Compile the source code using this command (all one line):
g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil
(you can try skipping this step and using the ready-provided executable, but it didn't work for me)
Then you can actually fix the video. You need both the broken video & an example working video.
How to fix the video
Find another working video, ideally from the same camera and preferably at least as long as the broken one; also the same resolution if possible (I believe this may help though is not essential).
Run this command in the folder where you have unzipped and compiled Untrunc but replace the /path/to/...
bits with your 2 video files:
./untrunc /path/to/working-video.m4v /path/to/broken-video.m4v
Then it should churn away and hopefully produce a playable file called broken-video_fixed.m4v
That's it you're done!
VLC Media Player should now be able to play the file. However it may be reporting the wrong length information (Untrunc tries to guess/work this out, but doesn't always get it right). To fix this try re-encoding the video through another program.
[Thanks to slhck's comment for the suggestion to try Untrunc.]
[Many thanks to Federico Ponchio for coding Untrunc in the first place, to solve this exact problem.]
If someone else stumbles on this, I also tried the app sparrowt was talking about, but it didn't work for me (see some bug-reports I created in the developers repository). Maybe this was because it wasn't a mp4 file but a MOV file ...
What helped for me was this post: http://muzso.hu/2012/11/14/how-to-fix-a-broken-mp4-mov-video-ffmpeg-reports-moov-atom-not-found
They link to a program called "HD Video Repair Utility" (http://grauonline.de/cmsimple2_6/en/?Solutions:HD_Video_Repair_Utility), which is far cheaper than Treasured (http://aeroquartet.com/movierepair/repair). They even pointed out, that there was an earlier version of it (version 1.5) that didn't cost anything (http://nagasoft.cn/download/videorepair1.5.zip)!
I tried repairing the file using the version 1.5 and got it partly working. After re-encoding with ffmpeg (got some errors there), I realized, that a part of the audio was gone. In the logs (gladly the Video Repair Utility has some), there was no further mentioning of audio after a given time. I'll take it as-is ...
You can install docker
(available for all major operating systems) and run:
docker run -v $(pwd):/vol -it synctree/untrunc /vol/GOOD-reference-file.MP4 /vol/BAD-corrupt-file.mdt
The syntax is for Bash under Linux or macOS. Here, GOOD-reference-file.MP4
and BAD-corrupt-file.md5
must both be in your current directory, and the directory will be mounted to /vol
in the Docker container.
Read the other comments around for more in-depth explanation.
This was the quickest for me!