-
Notifications
You must be signed in to change notification settings - Fork 5
/
framemd5cmp
executable file
·101 lines (92 loc) · 3.32 KB
/
framemd5cmp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
#
# Author: Dave Rice <dave@dericed.com> and Bay Area Video Coalition <bavc.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
NUM_ARGS=2
SCRIPTNAME=$(basename "${0}")
VERSION=0.1
unset dependencies
dependencies=(ffmpeg ffprobe diff)
OUTPUT_DIR=.
usage()
{
echo
echo "Version: framemd5cmp ${VERSION}"
echo "Usage: framemd5cmp file1 file2"
echo
echo "Dependencies: ${dependencies[@]}"
echo "Description: This script will evaluate two video files and identify descrepencies between their frames. It will only show where frames between the two files do not decode to exactly equal data."
echo
exit
}
is_video(){
# use ffmpeg's index value and stream specifier to determine if the input is a recognized as a video file by ffmpeg
ffprobe "$1" -show_streams -select_streams v 2> /dev/null | grep "index="
}
check_dependencies(){
deps_ok=YES
while [ "$*" != "" ] ; do
dependency="$1"
if [ ! $(which $dependency) ] ; then
echo "This script requires $dependency to run but it is not installed"
echo "If you are running ubuntu or debian you might be able to install $dependency with the following command"
echo "sudo apt-get install ${dependency}"
echo "If you are running mac you might be able to install $dependency with the following command"
echo "brew install ${dependency}"
deps_ok=NO
fi
shift
done
if [[ "$deps_ok" == "NO" ]]; then
echo "Unmet dependencies"
echo "Aborting!"
exit 1
else
return 0
fi
}
check_dependencies "${dependencies[@]}"
if [ ! "${#}" -eq "${NUM_ARGS}" ] ; then
echo "Error: ${SCRIPTNAME} requires exactly two inputs."
usage
fi
if [ ! -s "${1}" -o ! -s "${2}" ] ; then
echo "Error: ${1} and ${2} must be files."
usage
fi
if [ ! $(is_video "${1}") ] ; then
echo "Error: ${1} is not a video file (as recognized by ffmpeg)."
usage
elif [ ! $(is_video "${2}") ] ; then
echo "Error: ${2} is not a video file (as recognized by ffmpeg)."
usage
fi
if [ "${1}" == "${2}" ] ; then
echo "Error: ${1} and ${2} are the same file."
usage
fi
NAME1=$(basename "${1%.*}")
NAME2=$(basename "${2%.*}")
if [ "${NAME1}" == "${NAME2}" ] ; then
NAME1="${NAME1}_1"
NAME2="${NAME2}_2"
fi
FRAMEMD5_1="${OUTPUT_DIR}/${NAME1}_framemd5.txt"
FRAMEMD5_2="${OUTPUT_DIR}/${NAME2}_framemd5.txt"
FRAMEMD5_HASHONLY_1="${OUTPUT_DIR}/${NAME1}_hashonly.txt"
FRAMEMD5_HASHONLY_2="${OUTPUT_DIR}/${NAME2}_hashonly.txt"
ffmpeg -n -i "$1" -an -map 0:v:0 -f framemd5 "${FRAMEMD5_1}"
ffmpeg -n -i "$2" -an -map 0:v:0 -f framemd5 "${FRAMEMD5_2}"
cut -d, -f6 "${FRAMEMD5_1}" | sed 's/ //g' | tail -n +2 > "${FRAMEMD5_HASHONLY_1}"
cut -d, -f6 "${FRAMEMD5_2}" | sed 's/ //g' | tail -n +2 > "${FRAMEMD5_HASHONLY_2}"
diff -u "${FRAMEMD5_HASHONLY_1}" "${FRAMEMD5_HASHONLY_2}" > "${OUTPUT_DIR}/${NAME1}_vs_${NAME2}_diff.txt"