9

I was recording an MP4 file using PlaysTV, and my computer had a power fault half-way through the recording. I'm sure that the file contains valid data, it's just that no media player will recognize it.

To fix it I have tried Avidemux, I have tried numerous programs listed in other questions on stackexchange. And so far nothing has worked.

The ffmpeg -i output is as follows:

  libavutil      55. 24.100 / 55. 24.100
  libavcodec     57. 43.100 / 57. 43.100
  libavformat    57. 37.100 / 57. 37.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 46.100 /  6. 46.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000000000262d040] moov atom not found
2016_05_27_20_08_12-ses.mp4: Invalid data found when processing input

Mediainfo output:

General
Complete name                            : F:\vids\2016_05_27_20_08_12-ses.mp4
Format                                   : MPEG-4
Format profile                           : Base Media / Version 2
Codec ID                                 : mp42 (mp41/isom)
File size                                : 1.21 GiB

There are probably paid services that will fix this file for me, however since it is a (quite)large-ish file, they cost too much.

Can anyone help me here?

2

3 Answers 3

6

I recently encountered this exact problem and I was able to repair the file using Untrunc, a program created specifically to solve this problem, as suggested by sparrowt on SuperUser:

For this method you need:

  • another video file which isn't broken

  • a linux installation (I used Ubuntu 12.04) and basic ability to use a command line.

This is what to do:

  1. Install some pre-requisite libraries with this command:

    sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev

  2. Download the source code for Untrunc from the github repo:

    wget https://github.com/ponchio/untrunc/archive/master.zip

  3. Unzip the source code:

    unzip master.zip

  4. Go into the directory where it's been unzipped:

    cd untrunc-master

  5. 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)

  6. Then you can actually fix the video. You need both the broken video and an example working video.

    Ideally the video should be from the same camera & have the same resolution (mine was but it might work without). Also if it is at least as long as the broken one (preferably roughly the same) this may help.

    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.

2
  • 1
    I have this error when trying to build: track.cpp:60:32: fatal error: libavcodec/h264dec.h
    – unfa
    Feb 16, 2018 at 19:58
  • 2
    @unfa I have the same issue, so I've used the port of untrunc made by@anthwlock which is far easier to build and install. Oct 22, 2019 at 19:13
4

Updated: this tool can now recover files from more sources.

Try with recover_mp4_to_h264. It's a command line program, and will require a good reference file.

Usage as indicated:

recover_mp4 in_good_similar.mp4 --analyze
recover_mp4 in_corrupted.mp4 {out_video.h264 | out_video.hevc | --novideo} [out_audio.aac | out_audio.wav | out_audio.mp3 | out_audio.raw | --noaudio] [options]
2
  • I had a go with that before, it said the format wasn't supported. May 28, 2016 at 17:30
  • 1
    Restore.media, the company that makes recover_mp4, does not offer that download any more, and instead only repairs files online via their site (for a fee). You can still get an earlier version of that tool (legally so; Restore.media even provides the direct link for the download). Sadly, it's closed source, and available for Windows (32/64bits) only... Oct 22, 2019 at 19:22
1

You may also, to save yourself trouble, check to see the data is even there first. The file size being 1.21 GB, does that sound correct for the time until you lost power?

I bring this up because some programs write the data first to memory... sometimes very long large chunks of data, before actually committing it to disk.

With an MP4, the video should play, if it has valid headers, up until the last good packet containing the correct key/i frames.

What pops into my head, is the data may not be there, as in, it had been committed to memory, but not to disk-- I'd do a test record (factoring the time it "should be", and compare file sizes). Before you jump through hoops.

3
  • The MOOV atom, containing stream info and sample positions, is written at the time of finishing the file i.e. when all the media stream data has been committed to disk. You can have a MP4 with a MOOV atom upfront with just the stream info, which makes the file playable but not seekable. However, very few apps or devices write MP4s in this way.
    – Gyan
    May 29, 2016 at 15:12
  • Bandicam, a very popular screen capture application has an option as to how often it commits the data captured into ram to disk, which is why i mentioned it- just to check. Theres so many software applications out there. A non-seekable file can also be fixed using ffmpeg, and VLC can do it also by inserting in the proper key frames. Another example of larger cache rewrites are with AJA products, some of which wont write to disk until 60 seconds has passed. May 30, 2016 at 15:22
  • I tried using a piece of freemium software to see if it could be recovered, and yes the data is definitely there. The video data is at least. However like I said, I don't really want to go buying software for one video file I don't need that much. Jun 4, 2016 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.