forked from carevealed/cavppers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifymedia
executable file
·184 lines (179 loc) · 8.19 KB
/
verifymedia
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/bin/bash
# verifymedia, makes a file according to the video preservation master specifications listed at http://calpreservation.org/wp-content/uploads/2013/10/CAVPPTargetAudioandVideo-Specs2013_IMLS.pdf as of March 10, 2014
version="1.0"
scriptname=$(basename $(which "$0"))
scriptdir=$(dirname $(which "$0"))
. "$scriptdir/cavpperfunctions" || { echo "Missing '$scriptdir/cavpperfunctions'. Exiting." ; exit 1 ;};
dependencies=(ffmpeg ffprobe)
_initialize_make
specset=p
usage(){
echo
echo "$(basename ${0}) ${version}"
echo ""
echo "Dependencies: ${dependencies[@]}"
echo "Usage: $(basename $0) [ -h ] [ -s a/p ] file1 [ file2 ...]"
echo " -s ( set a specification set, either 'va' for video access file, 'vp' for video preservation file, 'aa' for audio access file, 'ap' for audio preservation file, default is 'vp' )"
echo " -v ( be verbose and show all tests, pass or file )"
echo " -h ( display this help )"
echo
exit
}
[ "${#}" = 0 ] && usage
_makeffprobe(){
ffprobetmp=$(maketemp)
ffprobe -v 0 "$1" -show_format -show_streams -of flat > "${ffprobetmp}"
videoids=$(grep "streams.stream.*.codec_type=\"video\"" "${ffprobetmp}" | cut -d. -f3)
audioids=$(grep "streams.stream.*.codec_type=\"audio\"" "${ffprobetmp}" | cut -d. -f3)
}
_makemediainfo(){
mediainfotmp=$(maketemp)
mediainfo -f --language=raw "$1" > "${mediainfotmp}"
}
_check(){
key="${1}"
operator="${2}"
value="${3}"
if [[ "${key}" == mediainfo.* ]] ; then
actualvalue=$(grep "${key#mediainfo.} " "${mediainfotmp}" | cut -d: -f2 | sed 's/ //g')
else
actualvalue=$(grep "${key}" "${ffprobetmp}" | cut -d= -f2 | sed 's/^"//g' | sed 's/"$//g' )
fi
if [[ "${operator}" == "equals" ]] ; then
if [[ "${value}" == "${actualvalue}" ]] ; then
if [[ "${verbose}" == "Y" ]] ; then
report -d "VALID: ${key}:${actualvalue} ${operator} ${value}"
fi
else
report -w "INVALID: ${key}:${actualvalue} does not ${operator} ${value}"
fi
elif [[ "${operator}" == "contains" ]] ; then
if [[ "${value}" != "${actualvalue/$value/}" ]] ; then
if [[ "${verbose}" == "Y" ]] ; then
report -d "VALID: ${key}:${actualvalue} ${operator} ${value}"
fi
else
report -w "INVALID: ${key}:${actualvalue} does not ${operator} ${value}"
fi
elif [[ "${operator}" == "is_in_list" ]] ; then
if [[ "${value}" == *"${actualvalue/$value/}"* ]] ; then
if [[ "${verbose}" == "Y" ]] ; then
report -d "VALID: ${key}:${actualvalue} ${operator} ${value}"
fi
else
report -w "INVALID: ${key}:${actualvalue} does not ${operator} ${value}"
fi
elif [[ "${operator}" == "greater" ]] ; then
if [[ "${value}" -le "${actualvalue}" ]] ; then
if [[ "${verbose}" == "Y" ]] ; then
report -d "VALID: ${key}:${actualvalue} ${operator} ${value}"
fi
else
report -w "INVALID: ${key}:${actualvalue} is not ${operator} ${value}"
fi
elif [[ "${operator}" == "less" ]] ; then
if [[ "${value}" -ge "${actualvalue}" ]] ; then
if [[ "${verbose}" == "Y" ]] ; then
report -d "VALID: ${key}:${actualvalue} ${operator} ${value}"
fi
else
report -w "INVALID: ${key}:${actualvalue} is not ${operator} ${value}"
fi
else
report -w "ERROR: unknown operator, ${operator}"
exit
fi
}
# command-line options
OPTIND=1
while getopts "s:vh" opt ; do
case "${opt}" in
s) specset="${OPTARG}" ;;
v) verbose="Y" ;;
h) usage ;;
*) echo "bad option -$OPTARG" ; usage ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
input="$1"
report -dt "Testing ${input}"
_makeffprobe "${input}"
_makemediainfo "${input}"
if [[ "${specset}" = "vp" ]] ; then
# Preservation media file checks
# format checks
_check "format.filename" contains ".mov"
_check "format.format_long_name" equals "QuickTime / MOV"
# stream checks
for videoid in $(echo "${videoids}") ; do
_check "streams.stream.${videoid}.codec_tag_string" equals "v210"
_check "streams.stream.${videoid}.pix_fmt" equals "yuv422p10le"
_check "streams.stream.${videoid}.width" equals "720"
_check "streams.stream.${videoid}.height" equals "486"
_check "streams.stream.${videoid}.r_frame_rate" is_in_list "2997/100 30 30000/1001"
_check "streams.stream.${videoid}.display_aspect_ratio" equals "4:3"
_check "streams.stream.${videoid}.bit_rate" greater "223500000" # 224Mb (rounded) in bits
_check "streams.stream.${videoid}.bit_rate" less "224500000" # 225Mb (rounded) in bits
done
for audioid in $(echo "${audioids}") ; do
_check "streams.stream.${audioid}.codec_name" contains "pcm"
_check "streams.stream.${audioid}.sample_rate" equals "48000"
_check "streams.stream.${audioid}.channels" equals "2"
_check "streams.stream.${audioid}.bits_per_sample" equals "24"
_check "streams.stream.${audioid}.bit_rate" equals "2304000"
done
elif [[ "${specset}" = "va" ]] ; then
# Access media file checks
# format checks
_check "format.filename" contains ".mp4"
_check "format.format_long_name" equals "QuickTime / MOV"
_check "mediainfo.ScanType" equals "Progressive"
_check "mediainfo.OverallBitRate" greater "3500000" # 3.5Mb in bits
_check "mediainfo.OverallBitRate" less "4300000" # 4.3Mb in bits
# stream checks
for videoid in $(echo "${videoids}") ; do
_check "streams.stream.${videoid}.codec_tag_string" equals "avc1"
_check "streams.stream.${videoid}.pix_fmt" equals "yuv420p"
_check "streams.stream.${videoid}.width" equals "720"
_check "streams.stream.${videoid}.height" equals "540"
_check "streams.stream.${videoid}.r_frame_rate" is_in_list "2997/100 30 30000/1001"
_check "streams.stream.${videoid}.display_aspect_ratio" equals "4:3"
done
for audioid in $(echo "${audioids}") ; do
_check "streams.stream.${audioid}.codec_name" contains "aac"
_check "streams.stream.${audioid}.sample_rate" equals "48000"
_check "streams.stream.${audioid}.channels" equals "2"
_check "streams.stream.${audioid}.bit_rate" greater "157000" # 157Kb in bits (rounds to 160)
_check "streams.stream.${audioid}.bit_rate" less "160500" # 160.5Kb in bits
done
elif [[ "${specset}" = "ap" ]] ; then
# Preservation media file checks
# format checks
_check "format.filename" contains ".wav"
_check "format.format_name" equals "wav"
# stream checks
for audioid in $(echo "${audioids}") ; do
_check "streams.stream.${audioid}.bits_per_sample" equals "24"
_check "streams.stream.${audioid}.sample_rate" equals "96000"
_check "streams.stream.${audioid}.channels" equals "2"
_check "streams.stream.${audioid}.bit_rate" equals "4608000"
done
elif [[ "${specset}" = "aa" ]] ; then
# Access media file checks
# format checks
_check "format.filename" contains ".mp3"
_check "format.format_name" equals "mp3"
# stream checks
for audioid in $(echo "${audioids}") ; do
_check "streams.stream.${audioid}.sample_rate" equals "44100"
_check "streams.stream.${audioid}.channel_layout" equals "stereo"
_check "streams.stream.${audioid}.channels" equals "2"
_check "streams.stream.${audioid}.bit_rate" equals "320000"
done
fi
rm "${ffprobetmp}"
shift
_log -e
done