How can I fix a damaged MP4?

时间:2015-07-28 22:43:48

标签: 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.

3 个答案:

答案 0 :(得分:1)

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

 .controller('HomeCtrl', function($scope, $state, $ionicHistory) {
$scope.takePhoto = function(){
  navigator.customCamera.getPicture(filename, function success(fileUri) {
      alert("File location: " + fileUri);
  }, function failure(error) {
      alert(error);
  }, {
      quality: 80,
      targetWidth: 120,
      targetHeight: 120
  });
};

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 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 was created.

答案 1 :(得分:1)

尝试使用我的项目:https://github.com/bookkojot/mp4fixer

与untruc类似,它需要参考文件。

答案 2 :(得分:0)

似乎 Federico Ponchio 将他的 untrunc 提供给所有人(非 Linux 用户也可以使用 ;-) ):untrunc.it