Monday, October 24, 2022

[SOLVED] Check video files for integrity

Issue

I have a library of video files. They get moved around, zipped, unzipped and stuff.

It happened, that some of the files get e.g., transferred/ extracted only partially. This problem usually shows up only when actually watching that video (i.e., the video stops prematurely, which is then really annoying).

Is there a way to batch-verify the integrity of a video library?

I came up with the following, inspired by this question:

find . -regex ".*\.\(avi\|mkv\)" -exec ffmpeg -v error -i {} -f null - \;

The problem here is, that ffmpeg does not include the file name when printing the error messages which means I do not know which file in the batch is erroneous.

To make a long story short:

Is there a way to include the file name in the ffmpeg error messages?


Solution

Simply capture the output of ffmpeg and print it out with a proper header if not empty:

find . -regex ".*\.\(avi\|mkv\)" | while read f; do
  ffmpeg_out=$(ffmpeg -hide_banner -nostdin -v error -i "$f" -f null - 2>&1)
  [[ $ffmpeg_out ]] && echo -e "==> ERROR in $f\n${ffmpeg_out}"
done

I've added a couple of ffmpeg options to ensure proper operations:

  • -hide_banner turns off the normal FFmpeg preamble, which is just unnecessary noise
  • -nostdin tells FFmpeg to ignore any (accidental) keyboard interaction


Answered By - Adrian
Answer Checked By - Marie Seifert (WPSolving Admin)