Detect corrupt video files with ffmpeg
me@grafxflow

Written by me@grafxflow

20 May, 2025

0

17

Detect corrupt video files with ffmpeg

Just incase you have a folder full of video files and want to know if any of them are corrupt you can do it using ffmpeg the following bash script. The script will list all the video files in the folder and loop through them all.

Anybody who edits videos will at some point in their career need to do this!

Bash script for mp4's and usage

So for mp4's use the following script and save it as checkVideoErrorsMp4.sh:

#!/bin/bash
for name in *.mp4; do
    ffmpeg -v error -i "$name" -f null - > "error $name.log" 2>&1

    # Detect if there is and error file and if it's empty
    if [ -e "error $name.log" ] && [ ! -s "error $name.log" ]; then
        echo "The file 'error $name.log' exists and there are no errors."
    elif [ ! -e "error $name.log" ]; then
        echo "The file 'error $name.log' does not exist."
    else
        echo "The file 'error $name.log' exists and there are errors."
    fi
done

And in the terminal choose the folder containing the videos then run the script via bash:

cd /videos-folder


bash checkVideoErrorsMp4.sh

Bash script for mkv's and usage

And for mkv's use the following script and save it as checkVideoErrorsMkv.sh:

#!/bin/bash
for name in *.mkv; do
    ffmpeg -v error -i "$name" -f null - > "error $name.log" 2>&1

    # Detect if there is and error file and if it's empty
    if [ -e "error $name.log" ] && [ ! -s "error $name.log" ]; then
        echo "The file 'error $name.log' exists and there are no errors."
    elif [ ! -e "error $name.log" ]; then
        echo "The file 'error $name.log' does not exist."
    else
        echo "The file 'error $name.log' exists and there are errors."
    fi
done

And in the terminal choose the folder containing the videos then run the script via bash:

cd /videos-folder

bash checkVideoErrorsMkv.sh

Hope this helps.

Add comment

Smart Search

133 Following
50 Followers

me@grafxflow

Hull, United Kingdom

I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Follow