27

I made a recording with

ffmpeg -f alsa -ac 2 -i plughw:0,0  /tmp/audio.mp4

I then moved /tmp/audio.mp4 to another directory (/root/audio.mp4) without stopping ffmpeg leading to a broken .mp4 file:

ffplay /root/audio.mp4
[...]
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f3524000b80] moov atom not found
audio.mp4: Invalid data found when processing input

How to recover and read my .mp4 file?

user123456
  • 4,758
  • 11
  • 52
  • 78

2 Answers2

28

You can try and use Untrunc to fix the file.

Restore a damaged (truncated) mp4, m4v, mov, 3gp video. Provided you have a similar not broken video.

you may need to compile it from source, but there is another option to use a Docker container and bind the folder with the file into the container and fix it that way.

You can use the included Dockerfile to build and execute the package as a container

git clone https://github.com/ponchio/untrunc.git
cd untrunc
docker build -t untrunc .
docker run -v ~/Desktop/:/files untrunc /files/filea /files/fileb
rubynorails
  • 2,223
  • 12
  • 24
Rabin
  • 3,818
  • 1
  • 21
  • 23
  • 2
    The Untrunc in the repository provided doesn't compile in Ubuntu 18.04 because of "track.cpp:57:11: fatal error: config.h: No such file or directory". But this fork do compile. https://github.com/anthwlock/untrunc – HD189733b Dec 20 '19 at 07:25
  • Since I found this via google (and I'm aware this is the Unix SE), I'd like to add a *Windows* program to do this: https://www.videohelp.com/software/recover-mp4-to-h264 – user136036 Feb 27 '20 at 17:36
  • Actually, the anthwlock fork linked by @HD189733b above is supposed to work in Windows as well, even includes a GUI. I don't use windows so I can't say more on the matter. It works amazing on Ubuntu 18.04 though. – EA304GT May 26 '21 at 14:50
  • To avoid the problem with the missing config.h you can use this fork https://github.com/anthwlock/untrunc which does not rely of private libav libraries. – user1447520 Oct 14 '22 at 12:50
9

Solution provided here (https://github.com/ponchio/untrunc) solved my problem! I run it as a Docker container. Here my steps:

  • Install Docker (in case you don't have it yet)

  • Clone the repository:

      git clone https://github.com/ponchio/untrunc
    
  • On the same directory of the Dockerfile, run:

      cd untrunc
      docker build -t untrunc .
    
  • That will build a local docker image - it takes time.

  • Now you have to provide a sample file from the same origin (in my case the same camera) and the corrupted file you wanna fix. E.g.:

      docker run -v /path/to/files/:/files untrunc /files/working_video /files/broken_video
    
  • Doesn't work. Maybe because my videos have different length? I created one video from the other but had to cancel the video generation because it took to long. I guess the canceling while creating the video was the problem. can untrunc fix that too? – mcExchange Oct 23 '20 at 08:31
  • Hi @mcExchange, If you stop the recovering process the same thing will happen to the fixed video.. let it run until the end. – Alexandre Andrade Dec 27 '20 at 10:46