Merge pull request #173 from amiaopensource/weaver-branch

add script for comparing audio framemd5
This commit is contained in:
Reto Kromer 2017-04-16 16:56:05 +02:00 committed by GitHub
commit 9477bcfe0a
3 changed files with 91 additions and 13 deletions

77
check_audio_framemd5.sh Executable file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env bash
SCRIPT=$(basename "${0}")
VERSION='2017-04-15'
AUTHOR='ffmprovisr'
RED='\033[1;31m'
BLUE='\033[1;34m'
NC='\033[0m'
if [[ ${OSTYPE} = "cygwin" ]] || [ ! $(which diff) ]; then
echo -e "${RED}Error: 'diff' is not installed by default. Please install 'diffutils' from Cygwin.${NC}"
exit 1
fi
_output_prompt(){
cat <<EOF
Usage: ${SCRIPT} [-h] | [ -i <av_file> -m <md5_file> ]
EOF
exit 1
}
_output_help(){
cat <<EOF
Syntax:
${SCRIPT}
Prompts a short help message.
${SCRIPT} -h
This help.
${SCRIPT} -i <av_file> -m <md5_file>
Pass to the script the audio-visual file and the corresponding MD5
file to check.
Dependency:
ffmpeg
About:
Version: ${VERSION}
Website: https://github.com/amiaopensource/ffmprovisr/blob/gh-pages/check_audio_framemd5.sh
EOF
exit 0
}
unset input_file
unset input_hash
while getopts ":hi:m:" opt; do
case "${opt}" in
h) _output_help ;;
i) input_file=$OPTARG ;;
m) input_hash=$OPTARG ;;
:) 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
md5_tmp="${USERPROFILE}/$(basename "${input_hash}").tmp"
else
md5_tmp="${HOME}/$(basename "${input_hash}").tmp"
fi
# Find audio frame size for hash calculation
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}"
[[ ! -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
unset sample_rate
old_file=$(grep -v '^#' "${input_hash}")
tmp_file=$(grep -v '^#' "${md5_tmp}")
if [[ "${old_file}" = "${tmp_file}" ]]; then
echo -e "${BLUE}'$(basename "${input_file}")' matches '$(basename "${input_hash}")'${NC}"
rm "${md5_tmp}"
else
echo -e "${RED}The following differences were detected between '$(basename "${input_file}")' and '$(basename "${input_hash}")':${NC}"
diff "${input_hash}" "${md5_tmp}"
rm "${md5_tmp}"
fi

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
SCRIPT=$(basename "${0}")
VERSION='2016-12-31'
VERSION='2017-04-16'
AUTHOR='ffmprovisr'
RED='\033[1;31m'
BLUE='\033[1;34m'
@ -32,7 +32,7 @@ Dependency:
ffmpeg
About:
Version: ${VERSION}
Website: https://github.com/amiaopensource/ffmprovisr/blob/gh-pages/check_framemd5.sh
Website: https://github.com/amiaopensource/ffmprovisr/blob/gh-pages/check_video_framemd5.sh
EOF
exit 0
}
@ -54,21 +54,21 @@ done
echo -e "${BLUE}Please wait...${NC}"
unset md5_tmp
if [[ $OSTYPE = "cygwin" ]]; then
md5_tmp=""${USERPROFILE}/$(basename ${input_hash}).tmp""
md5_tmp="${USERPROFILE}/$(basename "${input_hash}").tmp"
else
md5_tmp="${HOME}/$(basename ${input_hash}).tmp"
md5_tmp="${HOME}/$(basename "${input_hash}").tmp"
fi
$(ffmpeg -i ${input_file} -loglevel 0 -f framemd5 -an ${md5_tmp})
[[ ! -f ${md5_tmp} ]] && { echo -e "${RED}Error: '${input_file}' is not a valid audio-visual file.${NC}" ; _output_prompt ; }
ffmpeg -i "${input_file}" -loglevel 0 -f framemd5 -an "${md5_tmp}"
[[ ! -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
old_file=$(grep -v '^#' ${input_hash})
tmp_file=$(grep -v '^#' ${md5_tmp})
old_file=$(grep -v '^#' "${input_hash}")
tmp_file=$(grep -v '^#' "${md5_tmp}")
if [[ "${old_file}" = "${tmp_file}" ]]; then
echo -e "${BLUE}'$(basename ${input_file})' matches '$(basename ${input_hash})'${NC}"
echo -e "${BLUE}'$(basename "${input_file}")' matches '$(basename "${input_hash}")'${NC}"
rm "${md5_tmp}"
else
echo -e "${RED}The following differences were detected between '$(basename ${input_file})' and '$(basename ${input_hash})':${NC}"
echo -e "${RED}The following differences were detected between '$(basename "${input_file}")' and '$(basename "${input_hash}")':${NC}"
diff "${input_hash}" "${md5_tmp}"
rm "${md5_tmp}"
fi

View File

@ -1172,7 +1172,7 @@ foreach ($file in $inputfiles) {
<dt>-an</dt><dd>ignores the audio stream (audio no)</dd>
<dt><i>output_file</i></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>You may verify an MD5 checksum file created this way by using a <a href="check_framemd5.sh" target="_blank">Bash script</a>.</p>
<p>You may verify an MD5 checksum file created this way by using a <a href="check_video_framemd5.sh" target="_blank">Bash script</a>.</p>
<p class="link"></p>
</div>
</div>
@ -1187,13 +1187,14 @@ foreach ($file in $inputfiles) {
<div class="modal-content">
<div class="well">
<h3>Create MD5 checksums (audio samples)</h3>
<p><code>ffmpeg -i <i>input_file</i> -filter_complex "asetnsamples=<i>n=48000</i>" -f framemd5 -vn <i>output_file</i></code></p>
<p><code>ffmpeg -i <i>input_file</i> -af "asetnsamples=<i>n=48000</i>" -f framemd5 -vn <i>output_file</i></code></p>
<p>This will create an MD5 checksum for each group of 48000 audio samples.<br> The number of samples per group can be set arbitrarily, but it's good practice to match the samplerate of the media file (so you will get one checksum per second).</p>
<p>Examples for other samplerates:</p>
<ul>
<li>44.1 kHz: "asetnsamples=n=44100"</li>
<li>96 kHz: "asetnsamples=n=96000"</li>
</ul>
<p>Note: This filter trandscodes audio to 16 bit PCM by default. The generated framemd5s will represent this value. Validating these framemd5s will require using the same default settings.</p>
<dl>
<dt>ffmpeg</dt><dd>starts the command</dd>
<dt>-i <i>input_file</i></dt><dd>path, name and extension of the input file</dd>
@ -1201,7 +1202,7 @@ foreach ($file in $inputfiles) {
<dt>-vn</dt><dd>ignores the video stream (video no)</dd>
<dt><i>output_file</i></dt><dd>path, name and extension of the output file</dd>
</dl>
<p>You may verify an MD5 checksum file created this way by using a <a href="check_framemd5.sh" target="_blank">Bash script</a>.</p>
<p>You may verify an MD5 checksum file created this way by using a <a href="check_audio_framemd5.sh" target="_blank">Bash script</a>.</p>
<p class="link"></p>
</div>
</div>