Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix a damaged MP4?

Tags:

ffmpeg

mp4

I have a video of just under an hour recorded but it appears to be damaged somehow. The file format is h264 MP4 and the file size is 2.3 GB, so I'm confident that the information is there, just that the file format is damaged. How could I approach fixing it?

So far, I've tried a simple ffmpeg copy operation:

>ffmpeg -i video_28_07_2015_15_16_05.mp4  -c copy out.mp4
ffmpeg version N-73895-g323ec6b Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libdcadec --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
  libavutil      54. 28.100 / 54. 28.100
  libavcodec     56. 50.101 / 56. 50.101
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 25.100 /  5. 25.100
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2a78e00] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
video_28_07_2015_15_16_05.mp4: could not find codec parameters
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video_28_07_2015_15_16_05.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    creation_time   : 2015-07-28 14:12:50
  Duration: 00:56:43.53, bitrate: 5345 kb/s
    Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), none, 1280x720, SAR 1:1 DAR 16:9, 30 fps, 90k tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2015-07-28 14:12:50
      handler_name    : VideoHandle
[mp4 @ 0x2a7b260] Codec for stream 0 does not use global headers but container format requires global headers
Output #0, mp4, to 'out.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: isom3gp4
    encoder         : Lavf56.40.101
    Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), none, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 90k tbr, 90k tbn, 90k tbc (default)
    Metadata:
      creation_time   : 2015-07-28 14:12:50
      handler_name    : VideoHandle
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=-1.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

I have no idea of what to try next and would appreciate suggestions and guidance.

like image 310
d3pd Avatar asked Jul 28 '15 22:07

d3pd


2 Answers

Ok, so untrunc by Federico Ponchio worked. The procedure (on Ubuntu 14.04 LTS) was as follows:

sudo apt-get -y install libavformat-dev libavcodec-dev libavutil-dev
wget https://github.com/ponchio/untrunc/archive/master.zip
unzip master.zip
cd untrunc-master
g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil
./untrunc video_12_02_2015_15_02_58.mp4 video_28_07_2015_15_16_05.mp4

The first argument is an example working video from the same device and the second argument is the broken video. The program ran for a short time and a new working file called video_28_07_2015_15_16_05.mp4_fixed.mp4 was created.

like image 146
d3pd Avatar answered Sep 28 '22 06:09

d3pd


Try to use my project: https://github.com/bookkojot/mp4fixer

Similar to untruc, it requires reference file.

like image 22
bukkojot Avatar answered Sep 28 '22 05:09

bukkojot