ffmprovisr/scripts/check_audio_framemd5.sh

75 lines
2.2 KiB
Bash
Raw Normal View History

2017-04-15 23:02:23 +02:00
#!/usr/bin/env bash
SCRIPT=$(basename "${0}")
2018-02-10 06:50:06 +01:00
VERSION="2018-02-10"
AUTHOR="ffmprovisr"
RED="\033[1;31m"
BLUE="\033[1;34m"
NC="\033[0m"
2017-04-15 23:02:23 +02:00
2018-02-10 06:50:06 +01:00
if [[ "${OSTYPE}" = "cygwin" ]] || [[ ! "$(which diff)" ]]; then
2017-04-15 23:02:23 +02:00
echo -e "${RED}Error: 'diff' is not installed by default. Please install 'diffutils' from Cygwin.${NC}"
exit 1
fi
_output_prompt(){
cat <<EOF
2017-07-08 12:48:02 +02:00
Usage: ${SCRIPT} -i <av_file> -m <md5_file> | -h
2017-04-15 23:02:23 +02:00
EOF
exit 1
}
_output_help(){
cat <<EOF
Syntax:
${SCRIPT} -i <av_file> -m <md5_file>
Pass to the script the audio-visual file and the corresponding MD5
file to check.
2017-07-08 12:48:02 +02:00
${SCRIPT} -h
This help.
2017-04-15 23:02:23 +02:00
Dependency:
ffmpeg
About:
Version: ${VERSION}
2017-04-17 07:57:49 +02:00
Website: https://github.com/amiaopensource/ffmprovisr/blob/gh-pages/scripts/check_audio_framemd5.sh
2017-04-15 23:02:23 +02:00
EOF
exit 0
}
unset input_file
unset input_hash
2017-07-08 12:48:02 +02:00
while getopts ":i:m:h" opt; do
2017-04-15 23:02:23 +02:00
case "${opt}" in
2017-07-08 12:48:02 +02:00
i) input_file=${OPTARG} ;;
m) input_hash=${OPTARG} ;;
2017-04-15 23:02:23 +02:00
h) _output_help ;;
:) echo -e "${RED}Error: option -${OPTARG} requires an argument${NC}" ; _output_prompt ;;
*) echo -e "${RED}Error: bad option -${OPTARG}${NC}" ; _output_prompt ;;
esac
done
[[ -z "${#}" || ! ${input_file} || ! ${input_hash} ]] && _output_prompt
echo -e "${BLUE}Please wait...${NC}"
unset md5_tmp
if [[ $OSTYPE = "cygwin" ]]; then
2017-04-16 16:01:40 +02:00
md5_tmp="${USERPROFILE}/$(basename "${input_hash}").tmp"
2017-04-15 23:02:23 +02:00
else
2017-04-16 16:01:40 +02:00
md5_tmp="${HOME}/$(basename "${input_hash}").tmp"
2017-04-15 23:02:23 +02:00
fi
# Find audio frame size for hash calculation
2017-07-08 12:48:02 +02:00
unset sample_rate
2017-04-16 16:01:40 +02:00
sample_rate=$(grep -v '^#' "${input_hash}" | head -n 1 | tr -d ' ' | cut -d',' -f4)
ffmpeg -i "${input_file}" -loglevel 0 -af "asetnsamples=n='$sample_rate'" -f framemd5 -vn "${md5_tmp}"
2017-04-15 23:02:23 +02:00
[[ ! -f ${md5_tmp} ]] && { echo -e "${RED}Error: '${input_file}' is not a valid audio-visual file.${NC}" ; _output_prompt ; }
unset old_file
unset tmp_file
2017-04-16 16:01:40 +02:00
old_file=$(grep -v '^#' "${input_hash}")
tmp_file=$(grep -v '^#' "${md5_tmp}")
2017-04-15 23:02:23 +02:00
if [[ "${old_file}" = "${tmp_file}" ]]; then
2017-04-16 16:01:40 +02:00
echo -e "${BLUE}'$(basename "${input_file}")' matches '$(basename "${input_hash}")'${NC}"
2017-04-15 23:02:23 +02:00
else
2017-04-16 16:01:40 +02:00
echo -e "${RED}The following differences were detected between '$(basename "${input_file}")' and '$(basename "${input_hash}")':${NC}"
2017-04-15 23:02:23 +02:00
diff "${input_hash}" "${md5_tmp}"
fi
2018-02-09 21:22:31 +01:00
rm "${md5_tmp}"