1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

壊れた動画ファイルの修復

Posted at

目的

デジカメで動画撮影中にバッテリ不調などが起きて撮影が中断したときに、その動画ファイルが壊れてしまって動画再生ツールで再生できなくなったファイルを修復するツールがあったので試してみた。

使用するツール

Untrunc
WSL on Windows

壊れた動画ファイルの状態

ffmpegで壊れたファイルの解像度変換をしようとすると下記のエラーとなる

% ffmpeg -i MAH05717.MP4 -c:v libx264 -b:v 3000k -s 1920x1080 -c:a aac -b:a 48k -ac 2 -y "MAH05717_s.mp4"
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001e683123cc0] Format mov,mp4,m4a,3gp,3g2,mj2 detected only with low score of 1, misdetection possible!
[mov,mp4,m4a,3gp,3g2,mj2 @ 000001e683123cc0] moov atom not found
[in#0 @ 000001e683123a40] Error opening input: Invalid data found when processing input
Error opening input file MAH05717.MP4.
Error opening input files: Invalid data found when processing input

事前の準備

WSLに下記のパッケージをインストールしておく

% sudo apt install build-essential autoconf automake gcc make yasm pkg-config g++ zlib1g-dev

Untrunc のインストール

作業ディレクトリを作ってgitでソースをダウンロードしてmakeする

% git clone --recurse-submodules https://github.com/ponchio/untrunc
% cd untrunc/libav
% ./configure
% make
% cd ..
% g++ -o untrunc -I./libav file.cpp main.cpp track.cpp atom.cpp codec_*.cpp codecstats.cpp codec.cpp mp4.cpp log.cpp -L./libav/libavformat -lavformat -L./libav/libavcodec -lavcodec -L./libav/libavresample -lavresample -L./libav/libavutil -lavutil -lpthread -lz -std=c++11

これで実行ファイル untrunc が作成される。

実行方法

untrunc 壊れていないファイル 壊れたファイル
と実行することで、壊れたファイル_fixed というファイルができる。
下記では
MAH05716.MP4 が壊れていないファイル
MAH05717.MP4 が壊れたファイル

% ./untrunc MAH05716.MP4 MAH05717.MP4
Reading: MAH05716.MP4
Repair: MAH05717.MP4
Mdat not found!

Trying a different approach to locate mdat start
Repair: MAH05717.MP4
Processed: 1%
Processed: 2%
(中略)
Processed: 98%
Processed: 99%
Found 84279 packets.
Found 32874 chunks for avc1
Found 51405 chunks for mp4a
Saving to: MAH05717_fixed.mp4

修復された MAH05717_fixed.mp4 ファイルが作成されて、再生できるようになった。

1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?