brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ffmpeg -v error -f null – checks a video file for damage

Ffmpeg
~/tips/tip-ffmpeg-null-check-corrupt

ffmpeg -v error -i movie.mkv -f null -

Decodes a whole file without saving anything and prints only the errors it finds.

A file that opens fine can still be broken halfway through. Decoding the whole thing is the only way to know, and ffmpeg can do that without writing an output.

ffmpeg -v error -i movie.mkv -f null -

-f null - sends the decoded frames nowhere, and -v error hides everything except errors. A healthy file prints nothing at all. A damaged one prints lines about corrupt frames, missing references or, for a file that was cut off, something like “File ended prematurely”, which is what a file truncated on purpose shows.

To check a whole folder and keep a list of the bad ones, I’d loop over the files and save each error output to a log next to it:

for f in *.mkv; do
  ffmpeg -v error -i "$f" -f null - 2> "$f.errors.log"
done

Empty log, fine file. The downside is time: it decodes every frame, so a two-hour film takes as long as it takes your machine to decode it, which is usually a lot less than playing it but still minutes. Hardware decoding with -hwaccel can speed it up, though a hardware decoder may report problems differently from the software one.

Further reading: ffmpeg documentation

More Ffmpeg tips ffmpeg -stream_loop 2 -i in.mp4 -c copy out.mp4 ffmpeg -i in.mp4 \ ffmpeg -i video.mp4 -i video.en.srt -map 0 -map 1 -c copy -c:s mov_text -metadata:s:s:0 language=eng video-subs.mp4 ffmpeg -i film.mkv -map 0:v -map 0:a:0 -c:v copy -c:a aac -b:a 192k -ac 2 film-stereo.mkv ffmpeg -i talk.mp4 -vn -c:a copy talk.m4a All Ffmpeg tips (38) All topics

Link