0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WSL2(Ubuntu20.04LTS) で untrunc を使いMP4動画を復元する

Last updated at Posted at 2021-09-23

MP4ファイルが壊れてしまったので untrunc(WSL2/Ubuntu20.04LTS) を使って修復した。
untrunc は GitHub で公開されているMP4修復ツールだ。
破損したMP4とソースを同じくする正常なMP4ファイルさえあれば、それを元にMP4を修復してくれる。

 インストールしたてのWSL2上のUbuntuではコンパイラや前提となるライブラリが存在しないのでそれらのインストールから行う。またLibavが必要なため公式サイトから拾ってくる。

cd
sudo apt install make git gcc g++ yasm nasm zlib1g-dev
git clone https://github.com/ponchio/untrunc
wget https://libav.org/releases/libav-12.3.tar.gz
tar xvzf libav-12.3.tar.gz -C untrunc

 この時 untranc ディレクトリ内に libav-12.3 として解凍されるのだが、これだと上手くいかないので元々あったlibavディレクトリ(中身は空)を削除してからディレクトリをリネームする。

cd untrunc/
rm -r libav/
mv libav-12.3/ libav/
cd libav/
./configure
make

Libav がコンパイルされるので上位ディレクトリに戻って untranc をビルドする。

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

これで untrunc ディレクトリ内に untranc が生成された。

./untrunc <正常なMP4>.mp4 <破損したMP4>.mp4

untrunc にMP4を食わせるだけで修復され、MP4が無事再生できるようになった。めでたしめでたし。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?