Ticket #9407: 00-commands.sh

File 00-commands.sh, 3.6 KB (added by Michael Witten, 5 years ago)

Bash script that produces tests results

Line 
1#!/bin/bash
2
3main()
4(:
5 version_info
6 make_files
7 analyze_files
8 conclusion
9)
10
11version_info()
12{
13 echo 'Versions:'
14 echo '========'
15
16 version bash
17 version tee
18 version sed
19 version --all ffmpeg -version
20 version identify -version
21 version md5sum
22 version diff
23}
24
25version()
26{
27 if [[ $1 == --all ]]; then
28 printf '\n %s:\n\n' "$2"
29 "$2" "${3:---version}" | wrap
30 else
31 printf '\n %s:\n\n' "$1"
32 "$1" "${2:---version}" | sed -n 'p;q' | wrap
33 fi
34}
35
36wrap()
37{
38 fold -s -w 65 | indent
39}
40
41indent()
42{
43 sed -e "s/^/ &/"
44}
45
46make_files()
47{
48 local args f
49
50 echo
51 echo 'Making files:'
52 echo '============'
53 echo
54
55 args=(
56 -hide_banner
57 -loglevel quiet
58 -f lavfi -i '
59 color=0x7FFFD4:size=480x270, format=rgb24,
60 setparams=prog:pc:bt709:iec61966-2-1:bt709
61 '
62 -frames 1
63 )
64
65 f=01-rgb24.png
66 exists || ffmpeg "${args[@]}" "$f"
67
68 f=02-rbg24-to-yuv444p-to-rgb24.png
69 exists || ffmpeg "${args[@]}" -vf '
70 scale=out_range=pc, format=yuv444p,
71 scale=out_range=pc, format=rgb24
72 ' "$f"
73
74 f=03-rbg24-to-yuv444p10le-to-rgb24.png
75 exists || ffmpeg "${args[@]}" -vf '
76 scale=out_range=pc, format=yuv444p10le,
77 scale=out_range=pc, format=rgb24
78 ' "$f"
79
80 f=04-rbg24-to-yuv444p10le-to-yuv444p-to-rgb24.png
81 exists || ffmpeg "${args[@]}" -vf '
82 scale=out_range=pc, format=yuv444p10le,
83 scale=out_range=pc, format=yuv444p,
84 scale=out_range=pc, format=rgb24
85 ' "$f"
86
87 f=05-rbg24-to-yuv444p10le-to-rgb24-to-yuv444p-to-rgb24.png
88 exists || ffmpeg "${args[@]}" -vf '
89 scale=out_range=pc, format=yuv444p10le,
90 scale=out_range=pc, format=rgb24,
91 scale=out_range=pc, format=yuv444p,
92 scale=out_range=pc, format=rgb24
93 ' "$f"
94}
95
96exists()
97{
98 printf ' %s' "$f"
99 [[ -e $f ]] || { echo; return 1; }
100 spaces=' '
101 echo "${spaces:${#f}}" '(already exists)'
102}
103
104analyze_files()
105{
106 echo
107 echo 'Analyzing:'
108 echo '========='
109
110 md5sums
111 show_lossiness_of_yuv444p
112 show_bonkers_conversion_between_yuvs
113}
114
115md5sums()
116{
117 echo
118 echo ' md5sums':
119 echo
120
121 local h f i=0 files
122 local -A same
123
124 while read h f; do
125 same[$h]+=" $i"
126 files[i]=$f
127 ((++i)) || { echo 'ERROR: Overflow?'; return 1; }
128 done < <(md5sum *.png)
129
130 for h in "${!same[@]}"; do
131 echo ' ' "$h:"
132 echo
133 for i in ${same[$h]}; do
134 echo ' ' "${files[i]}"
135 done
136 echo
137 done
138}
139
140show_lossiness_of_yuv444p()
141{
142 echo ' rgb24 -> yuv444p is imperceptibly lossy:'
143 echo
144
145 diff -u \
146 <(identify -verbose 01-rgb24.png) \
147 <(identify -verbose 02-rbg24-to-yuv444p-to-rgb24.png) \
148 | sed '1,2d' | indent
149}
150
151show_bonkers_conversion_between_yuvs()
152{
153 echo
154 echo ' yuv444p10le -> yuv444p is bonkers:'
155 echo ' (it SHOULD be the same as rgb24 -> yuv444p)'
156 echo
157
158 diff -u \
159 <(identify -verbose 02-rbg24-to-yuv444p-to-rgb24.png) \
160 <(identify -verbose 04-rbg24-to-yuv444p10le-to-yuv444p-to-rgb24.png) \
161 | sed '1,2d' | indent
162}
163
164conclusion()
165{
166 cat <<'EOF'
167
168Conclusion:
169==========
170
171 As indicated by the hashes, the *workaround* is to convert
172 "yuv444p10le" to some other class of pixel format (like "rgb24")
173 before converting to another "yuv*" pixel format:
174
175 scale=out_range=pc, format=yuv444p10le,
176 scale=out_range=pc, format=rgb24, <--------- workaround
177 scale=out_range=pc, format=yuv444p
178
179 Nevertheless, a workaround should not even be necessary. There
180 is a bug that should be investigated and fixed.
181
182 (As an aside, look at all that "out_range" gibberish; it should
183 not be necessary to do that little dance.)
184EOF
185}
186
187main | tee 06-log.txt