Thursday, November 17, 2022

Fixing bad video files with ffmpeg

FFmpeg is an open-source collection of tools for processing video and audio files. It allows to convert video and audio files from one format into another, resize videos, stream audio and video, and perform various other actions with media files.

FFmpeg is quite easy to interact with Python via bindings but it's also a CLI which what I used to fixed bad video. 

The simplest command we can do:

ffmpeg -err_detect ignore_err -i video.mkv -c copy video_fixed.mkv

A more involved command:

ffmpeg -vcodec mpeg4 -b:v 7561k -qscale:v 2 -acodec aac -ac 2 -async 1 -strict experimental ./video_fixed.mp4 -threads 0 -i damage_file.mp4

This one re-encodes while trying to fix the video. This one also take longer to run.