Created
January 24, 2023 15:24
-
-
Save wcmatthysen/debfc52456f16d9100f11568070008f6 to your computer and use it in GitHub Desktop.
Confirm all media in a path can be played back using ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Name: mediaCheck | |
# Purpose: Confirm all media in a path can be played back using ffmpeg | |
# Requires: | |
# * ffmpeg in $PATH | |
# * date in $PATH | |
# * find in $PATH | |
function checkReqs { | |
# checks requirements for the script | |
requires="ffmpeg date find" | |
re=0 | |
for i in $requires; do | |
if ! which $i > /dev/null; then | |
((re++)) | |
echo "$i is required in path for this script" | |
fi | |
done | |
if [ "$re" -gt 0 ]; then | |
echo "Requirements not met" | |
exit 1 | |
fi | |
} | |
function pathCheck { | |
# if there isn't a path, use pwd, otherwise clean up whatever is provided. | |
if [ -z "$1" ]; then | |
lPath=mediaCheck.log | |
cPath=$(pwd) | |
else | |
cPath=$(readlink -f $1) | |
lPath=$1 | |
fi | |
} | |
function pdate { | |
# my prefered date formatting | |
date +%FT%H:%M:%S | |
} | |
function checkMedia { | |
# the actual ffmpeg command | |
ffmpeg -v error -i $1 -f null - &> "$1.log" | |
} | |
function findItems { | |
# our main loops | |
# first a set of common file types | |
for mtype in flv avi m4v mkv mp4; do | |
c=0; e=0 | |
# Get a total per file type | |
ttotal=$(find $1 -type f -name \*.$mtype | wc -l) | |
# then the actual lookup and check | |
for i in $(find $1 -type f -name \*.$mtype); do | |
echo -ne "$(pdate) $c out of $ttotal $mtype files checked with $e errors.\r" | |
((c++)) | |
# check media, and if we fail, increment error counter. | |
if ! checkMedia "$i" ; then | |
((e++)) | |
echo "$i failed" >> $lPath.log | |
fi | |
done | |
echo "$(pdate) $c out of $ttotal $mtype files checked with $e errors." | |
unset c e | |
done | |
} | |
# set blank cpath | |
cPath='' | |
# uncomment the line below if this script isn't behaving as expected | |
# set -x | |
# Check requirements before anything else | |
checkReqs | |
# Then generate a path | |
pathCheck $1 | |
# Make sure we don't stumble on names with spaces | |
IFS=$'\n' | |
echo "$(pdate) scan started." | |
findItems $cPath | |
echo "$(pdate) scan complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment