Skip to content

Instantly share code, notes, and snippets.

@tobiaspc
Created July 1, 2023 20:36
Show Gist options
  • Save tobiaspc/a98cee081b6b86b5510b0fec912b0f98 to your computer and use it in GitHub Desktop.
Save tobiaspc/a98cee081b6b86b5510b0fec912b0f98 to your computer and use it in GitHub Desktop.
Parallel video corruption check for a whole folder with csv output
#!/bin/bash
folder="$1"
parallelism="$2" # No parallelism, i.e. set to 1, works best so far
results_file="${folder}/results.csv"
# Function to check if a video file is corrupt using ffmpeg
check_video_corruption() {
renice -n 19 $$ > /dev/null 2>&1
ionice -c 3 -p $$ > /dev/null 2>&1
file="$1"
output=$(ffmpeg -v error -i "$file" -f null - 2>&1)
if [[ $output == "" ]]; then
echo "\"${file}\",OK"
else
echo "\"${file}\",BROKEN"
fi
}
# Exporting the function to be used by parallel command
export -f check_video_corruption
# Loop over video files in the folder and check for corruption in parallel
find "$folder" -type f -name "*.mp4" -o -name "*.mkv" -o -name "*.avi" | parallel -t -j "$parallelism" check_video_corruption {} >>"$results_file"
echo "Video corruption check completed. Results written to $results_file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment