-
Notifications
You must be signed in to change notification settings - Fork 27
/
verifypackage
executable file
·142 lines (133 loc) · 6.91 KB
/
verifypackage
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
# verifypackage checks the validity of files created with makebroadcast,
# makeyoutube, and makedvd
_usage(){
echo
echo "$(basename "verifypackage") ${VERSION}"
echo "This application will test particular files of a package for compliance with mediaconch policies or ffmpeg-based outcomes."
echo "Usage: $(basename "${0}") [ -a | -v | -i ] fileorpackage1 [ fileorpackage2 ...]"
echo " -a run all tests known on the package"
echo " -v test the volume of the service and youtube files"
echo " -i use interlacement detection on the service file"
exit
}
OPTIND=1
while getopts ":avih" OPT ; do
case "${OPT}" in
a) ALL_TESTS="Y" ;;
v) VOL_TEST="Y" ;;
i) IDET_TEST="Y" ;;
h) _usage ;;
*) echo "bad option -${OPTARG}" ; _usage ;;
esac
done
shift $(( ${OPTIND} - 1 ))
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }
DEPENDENCIES=(mediaconch xmlstarlet)
_initialize_make
_assess_volume(){
INPUT="${1}"
NAME=$(basename "${INPUT}")
VOL=$(ffmpeg -i "$INPUT" -vn -af ebur128 -f null - 2>&1 | grep "^ I:" | awk '{print $2}')
VOL_OK=$(echo "-22 > ${VOL} && ${VOL} > -26" | bc)
if [[ "${VOL_OK}" == "1" ]] ; then
_report -dt "Pass: ${INPUT}. Integrated loudness is ${VOL} LUFS, which is in the range of -26 ... -22 LUFS."
else
_report -wt "Fail: ${NAME}. Integrated loudness is ${VOL} LUFS. Should be in a range of -26 ... -22 LUFS."
fi
}
_assess_interlacement(){
EXPECTATION="${1}"
INPUT="${2}"
NAME=$(basename "${INPUT}")
IDET_RESULTS=$(ffmpeg -i "${INPUT}" -vf idet -f null - 2>&1 | grep "Multi frame detection:")
TFF_COUNT=$(echo "${IDET_RESULTS}" | sed 's|:|: |g' | grep -o "TFF:[ ]*[0-9]*" | awk '{print $2}')
BFF_COUNT=$(echo "${IDET_RESULTS}" | sed 's|:|: |g' | grep -o "BFF:[ ]*[0-9]*" | awk '{print $2}')
PROG_COUNT=$(echo "${IDET_RESULTS}" | sed 's|:|: |g' | grep -o "Progressive:[ ]*[0-9]*" | awk '{print $2}')
UND_COUNT=$(echo "${IDET_RESULTS}" | sed 's|:|: |g' | grep -o "Undetermined:[ ]*[0-9]*" | awk '{print $2}')
IDET_SORT=$(echo -e "${TFF_COUNT} TFF\n${BFF_COUNT} BFF\n${PROG_COUNT} Progressive\n${UND_COUNT} Undetermined" | sort -n -r)
IDET_FIRST_NAME=$(echo "${IDET_SORT}" | head -n 1 | awk '{print $2}')
IDET_FIRST_COUNT=$(echo "${IDET_SORT}" | head -n 1 | awk '{print $1}')
FIRST_PERCENTAGE=$(echo "scale=3 ; (100 * ${IDET_FIRST_COUNT}) / ( ${TFF_COUNT} + ${BFF_COUNT} + ${PROG_COUNT} + ${UND_COUNT})" | bc)
if [[ "${IDET_FIRST_NAME}" == "${EXPECTATION}" ]] ; then
_report -dt "Pass: ${INPUT}. The file is ${IDET_FIRST_NAME} as expected. ${FIRST_PERCENTAGE}% of frames are ${EXPECTATION}."
else
_report -wt "Fail: ${INPUT}. The file is ${IDET_FIRST_NAME} but expected to be ${EXPECTATION}. ${FIRST_PERCENTAGE}% of frames are ${IDET_FIRST_NAME}."
_report -w "$IDET_RESULTS"
fi
}
_check_for_illegal_characters(){
COLONALERT=$(find "${1}" -iname '*:*')
if [ -n "${COLONALERT}" ] ; then
_report -w "Illegal characters (colons) have been detected in the following file(s):"
for i in ${COLONALERT} ; do
_report -w " ${i}"
done
fi
}
#input the package
while [ "${*}" != "" ] ; do
PACKAGE="${1}"
MEDIAID=$(basename "${PACKAGE}")
shift
#verify objects files
while read OBJECT_FILE ; do
STATUS=$(mediaconch --force -fx -p "${SCRIPTDIR}/object_policies.xml" "${OBJECT_FILE}" | xmlstarlet sel -N mc="https://mediaarea.net/mediaconch" -t -v mc:MediaConch/mc:media/mc:policy/@outcome -n)
if [[ "$STATUS" = "pass" ]] ; then
_report -dt "Pass: ${OBJECT_FILE}"
else
mediaconch --force -fs -p "${SCRIPTDIR}/object_policies.xml" "${OBJECT_FILE}"
fi
done < <(find "${PACKAGE}/objects" -type f ! -name "*.tif" -size +0 "${OBJECTS_FIND_EXCLUSIONS[@]}")
#verify the makebroadcast file
if [ -f "${PACKAGE}/objects/service/${MEDIAID}.mov" ] ; then
STATUS=$(mediaconch --force -fx -p "${SCRIPTDIR}/makebroadcast_policies.xml" "${PACKAGE}/objects/service/${MEDIAID}.mov" | xmlstarlet sel -N mc="https://mediaarea.net/mediaconch" -t -v mc:MediaConch/mc:media/mc:policy/@outcome -n)
if [[ "$STATUS" = "pass" ]] ; then
_report -dt "Pass: ${PACKAGE}/objects/service/${MEDIAID}.mov"
else
mediaconch --force -fs -p "${SCRIPTDIR}/makebroadcast_policies.xml" "${PACKAGE}/objects/service/${MEDIAID}.mov"
fi
if [[ "${ALL_TESTS}" == "Y" ]] || [[ "${VOL_TEST}" == "Y" ]] ; then
_assess_volume "${PACKAGE}/objects/service/${MEDIAID}.mov"
fi
if [[ "${ALL_TESTS}" == "Y" ]] || [[ "${IDET_TEST}" == "Y" ]] ; then
_assess_interlacement "TFF" "${PACKAGE}/objects/service/${MEDIAID}.mov"
fi
fi
#check for illegal characters in filenames or directories.
_check_for_illegal_characters "${PACKAGE}"
#verify the makeyoutube file
if [ -f "${PACKAGE}/objects/access/youtube_up/${MEDIAID}.mp4" ] ; then
STATUS=$(mediaconch --force -fx -p "${SCRIPTDIR}/makeyoutube_policies.xml" "${PACKAGE}/objects/access/youtube_up/${MEDIAID}.mp4" | xmlstarlet sel -N mc="https://mediaarea.net/mediaconch" -t -v mc:MediaConch/mc:media/mc:policy/@outcome -n)
if [[ "$STATUS" = "pass" ]] ; then
_report -dt "Pass: ${PACKAGE}/objects/access/youtube_up/${MEDIAID}.mp4"
else
mediaconch --force -fs -p "${SCRIPTDIR}/makeyoutube_policies.xml" "${PACKAGE}/objects/access/youtube_up/${MEDIAID}.mp4"
fi
if [[ "${ALL_TESTS}" == "Y" ]] || [[ "${VOL_TEST}" == "Y" ]] ; then
_assess_volume "${PACKAGE}/objects/access/youtube_up/${MEDIAID}.mp4"
fi
fi
#verify the makedvd file
if [ -f "${PACKAGE}/objects/access/dvd/${MEDIAID}.iso" ] ; then
STATUS=$(mediaconch --force -fx -p "${SCRIPTDIR}/makedvd_policies.xml" "${PACKAGE}/objects/access/dvd/${MEDIAID}.iso" | xmlstarlet sel -N mc="https://mediaarea.net/mediaconch" -t -v mc:MediaConch/mc:media/mc:policy/@outcome -n)
if [[ "$STATUS" = "pass" ]] ; then
_report -dt "Pass: ${PACKAGE}/objects/access/dvd/${MEDIAID}.iso"
else
mediaconch --force -fs -p "${SCRIPTDIR}/makedvd_policies.xml" "${PACKAGE}/objects/access/dvd/${MEDIAID}.iso"
fi
fi
#verify the audio podcast file
if [ -f "${PACKAGE}/objects/access/podcast/${MEDIAID}.m4a" ] ; then
if [[ "${ALL_TESTS}" == "Y" ]] || [[ "${VOL_TEST}" == "Y" ]] ; then
_assess_volume "${PACKAGE}/objects/access/podcast/${MEDIAID}.m4a"
fi
fi
#verify the mp3 file
if [ -f "${PACKAGE}/objects/access/mp3/${MEDIAID}.mp3" ] ; then
if [[ "${ALL_TESTS}" == "Y" ]] || [[ "${VOL_TEST}" == "Y" ]] ; then
_assess_volume "${PACKAGE}/objects/access/mp3/${MEDIAID}.mp3"
fi
fi
done