Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(480035)

Side by Side Diff: tools/ab_compare.sh

Issue 1393: Deduplicate code in ab_compare.sh.
Patch Set: Deduplicate code in ab_compare.sh. Created 2 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/ab_compare_daala.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 set -e 2 set -e
3 3
4 USAGE=\ 4 USAGE=\
5 'This script creates images or videos that are compressed by different codecs 5 'This script creates images or videos that are compressed by different codecs
6 but have nearly the same size, facilitating comparison among codecs. 6 but have nearly the same size, facilitating comparison among codecs.
7 7
8 Usage: 8 Usage:
9 ab_compare.sh [OPTIONS] file1.y4m file2.y4m ... fileN.y4m 9 ab_compare.sh [OPTIONS] file1.y4m file2.y4m ... fileN.y4m
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 while getopts 'c:s:v:b:k:ha:d:D:l:x:X:' OPTIONS; do 53 while getopts 'c:s:v:b:k:ha:d:D:l:x:X:' OPTIONS; do
54 case $OPTIONS in 54 case $OPTIONS in
55 c) CODECS="$OPTARG";; 55 c) CODECS="$OPTARG";;
56 s) SIZE="$OPTARG";; 56 s) SIZE="$OPTARG";;
57 v) V="$OPTARG";; 57 v) V="$OPTARG";;
58 b) BPP="$OPTARG";; 58 b) BPP="$OPTARG";;
59 k) KEYINT="$OPTARG";; 59 k) KEYINT="$OPTARG";;
60 h) echo "$USAGE"; exit 0;; 60 h) echo "$USAGE"; exit 0;;
61 a) AB_ROOT="$OPTARG";; 61 a) AB_ROOT="$OPTARG";;
62 d) DAALA_ROOT="$OPTARG";; 62 d) export DAALA_ROOT="$OPTARG";;
63 D) DAALA2_ROOT="$OPTARG";; 63 D) export DAALA2_ROOT="$OPTARG";;
64 l) LIBVPX_ROOT="$OPTARG";; 64 l) export LIBVPX_ROOT="$OPTARG";;
65 x) X264_ROOT="$OPTARG";; 65 x) export X264_ROOT="$OPTARG";;
66 X) X265_ROOT="$OPTARG";; 66 X) export X265_ROOT="$OPTARG";;
67 esac 67 esac
68 done 68 done
69 shift $(($OPTIND - 1)) 69 shift $(($OPTIND - 1))
70 70
71 if [ -z "$1" ]; then 71 if [ -z "$1" ]; then
72 echo "No input files given." 72 echo "No input files given."
73 exit 0 73 exit 0
74 fi 74 fi
75 75
76 if [ -z "$AB_ROOT" ]; then 76 if [ -z "$AB_ROOT" ]; then
77 AB_ROOT="./tools/" 77 AB_ROOT="./tools/"
78 fi 78 fi
79 79
80 if [ -z "$DAALA_ROOT" ]; then 80 if [ -z "$DAALA_ROOT" ]; then
81 DAALA_ROOT='.' 81 export DAALA_ROOT='.'
82 fi 82 fi
83 83
84 if [ ! -x "$AB_ROOT" ]; then 84 if [ ! -x "$AB_ROOT" ]; then
85 echo "Comparison scripts not found at '$AB_ROOT'. Please give their location" 85 echo "Comparison scripts not found at '$AB_ROOT'. Please give their location"
86 echo "with -a." 86 echo "with -a."
87 exit 1 87 exit 1
88 fi 88 fi
89 89
90 if [ ! -x "$LIBVPX_ROOT" ] && echo "$CODECS" | grep 'vp[89]' > /dev/null; then 90 if [ ! -x "$LIBVPX_ROOT" ] && echo "$CODECS" | grep 'vp[89]' > /dev/null; then
91 echo "Libvpx build not found at '$LIBVPX_ROOT'. Please give its location" 91 echo "Libvpx build not found at '$LIBVPX_ROOT'. Please give its location"
(...skipping 16 matching lines...) Expand all
108 if [ ! -x "$DAALA_ROOT" ] && echo "$CODECS" | grep 'daala$\|daala,' > /dev/null; then 108 if [ ! -x "$DAALA_ROOT" ] && echo "$CODECS" | grep 'daala$\|daala,' > /dev/null; then
109 echo "Daala build not found at $DAALA_ROOT. Please give its location" 109 echo "Daala build not found at $DAALA_ROOT. Please give its location"
110 echo "with -d." 110 echo "with -d."
111 exit 1 111 exit 1
112 fi 112 fi
113 113
114 if [ ! -x "$DAALA2_ROOT" ] && echo "$CODECS" | grep 'daala2' > /dev/null; then 114 if [ ! -x "$DAALA2_ROOT" ] && echo "$CODECS" | grep 'daala2' > /dev/null; then
115 echo "Second Daala build not found at $DAALA2_ROOT. Please give its location" 115 echo "Second Daala build not found at $DAALA2_ROOT. Please give its location"
116 echo "with -D." 116 echo "with -D."
117 exit 1 117 exit 1
118 fi
119
120 export X264="$X264_ROOT/x264"
121 export X265="$X265_ROOT/build/linux/x265"
122 export VPXENC="$LIBVPX_ROOT/$CODEC/vpxenc"
123 export VPXDEC="$LIBVPX_ROOT/vpxdec"
124 export AOMENC="$LIBAOM_ROOT/aomenc"
125 export AOMDEC="$LIBAOM_ROOT/aomdec"
126 if [ -z "$THORENC" ]; then
127 export THORENC="$WORK_ROOT/$CODEC/build/Thorenc"
128 fi
129 if [ -z "$THORDIR" ]; then
130 export THORDIR="$(dirname $THORENC)/../"
131 fi
132 if [ -z "$THORDEC" ]; then
133 export THORDEC="$(dirname $THORENC)/Thordec"
134 fi
135 if [ -z "$ENCODER_EXAMPLE" ]; then
136 export ENCODER_EXAMPLE="$DAALA_ROOT/examples/encoder_example"
137 fi
138 if [ -z "$YUV2YUV4MPEG" ]; then
139 YUV2YUV4MPEG=$DAALA_ROOT/tools/yuv2yuv4mpeg
140 fi
141 if [ -z "$YUVJPEG" ]; then
142 export YUVJPEG=yuvjpeg
143 fi
144 if [ -z "$JPEGYUV" ]; then
145 export JPEGYUV=jpegyuv
146 fi
147
148 if [ -z "$Y4M2PNG" ]; then
149 Y4M2PNG=$DAALA_ROOT/tools/y4m2png
118 fi 150 fi
119 151
120 if [ -z "$KEYINT" ]; then 152 if [ -z "$KEYINT" ]; then
121 KEYINT=256; 153 KEYINT=256;
122 fi 154 fi
123 155
124 if [ -z "$CODECS" ]; then 156 if [ -z "$CODECS" ]; then
125 CODECS="daala vp8 x264 x265" 157 CODECS="daala vp8 x264 x265"
126 else 158 else
127 CODECS=$( echo $CODECS | tr '[,]' '[ ]') 159 CODECS=$( echo $CODECS | tr '[,]' '[ ]')
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 # This ignores the size of the headers, but should be good enough for most 210 # This ignores the size of the headers, but should be good enough for most
179 # cases. 211 # cases.
180 FRAMES=$( echo "scale=5; $INSIZE / ( $WIDTH * $HEIGHT * $CHROMA_FACTOR )" | bc ) 212 FRAMES=$( echo "scale=5; $INSIZE / ( $WIDTH * $HEIGHT * $CHROMA_FACTOR )" | bc )
181 FRAMES=$(echo "scale=0;$FRAMES/1" | bc) 213 FRAMES=$(echo "scale=0;$FRAMES/1" | bc)
182 214
183 if [ -n "$BPP" ]; then 215 if [ -n "$BPP" ]; then
184 SIZE=$(echo "scale=5;( $BPP * $HEIGHT * $WIDTH * $FRAMES) / 8 + 0.5" | bc) 216 SIZE=$(echo "scale=5;( $BPP * $HEIGHT * $WIDTH * $FRAMES) / 8 + 0.5" | bc)
185 SIZE=$(echo "scale=0;$SIZE/1" | bc) 217 SIZE=$(echo "scale=0;$SIZE/1" | bc)
186 fi 218 fi
187 219
188 if [ $USE_DAALA == "true" ]; then 220 BASENAME=$(basename $FILE)
189 if [ -n "$V" ]; then 221
190 $AB_ROOT/ab_compare_daala.sh -d "$DAALA_ROOT" -n "$FRAMES" -v "$V" "$FILE" 222 if [ -n "$V" ]; then
191 SIZE=$(wc -c $(basename "$FILE")-$V.ogv | awk '{ print $1 }') 223 SIZE=$(x=$V CODEC=daala BASENAME=$BASENAME FILE=$FILE $AB_ROOT/ab_compare_en code.sh)
192 else
193 $AB_ROOT/ab_compare_daala.sh -d "$DAALA_ROOT" -n "$FRAMES" -s "$SIZE" "$FI LE"
194 fi
195 fi 224 fi
196 225
197 for CODEC in $CODECS; do 226 for CODEC in $CODECS; do
227 WIDTH=$(head -1 $FILE | cut -d\ -f 2 | tr -d 'W')
228 HEIGHT=$(head -1 $FILE | cut -d\ -f 3 | tr -d 'H')
198 case $CODEC in 229 case $CODEC in
199 daala) : ;; 230 x264)
200 jpeg) $AB_ROOT/ab_compare_jpeg.sh -d "$DAALA_ROOT" -n "$FRAMES" -s "$SIZE" "$FILE";; 231 if [ ! -x "$X264" ]; then
201 vp8) $AB_ROOT/ab_compare_libvpx.sh -d "$DAALA_ROOT" -r "$LIBVPX_ROOT" -n " $FRAMES" -k "$KEYINT" -s "$SIZE" -c vp8 "$FILE";; 232 echo "Executable not found X264=$X264"
202 vp9) $AB_ROOT/ab_compare_libvpx.sh -d "$DAALA_ROOT" -r "$LIBVPX_ROOT" -n " $FRAMES" -k "$KEYINT" -s "$SIZE" -c vp9 "$FILE";; 233 echo "Do you have the right X264_ROOT=$X264_ROOT"
203 x264) $AB_ROOT/ab_compare_x264.sh -d "$DAALA_ROOT" -r "$X264_ROOT" -n "$FR AMES" -k "$KEYINT" -s "$SIZE" "$FILE";; 234 exit 1
204 x265) $AB_ROOT/ab_compare_x265.sh -d "$DAALA_ROOT" -r "$X265_ROOT" -n "$FR AMES" -k "$KEYINT" -s "$SIZE" "$FILE";; 235 fi
205 daala2) $AB_ROOT/ab_compare_daala.sh -d "$DAALA_ROOT" -E "$DAALA2_ROOT/exa mples/encoder_example" -D "$DAALA2_ROOT/examples/dump_video" -n "$FRAMES" -s "$S IZE" -b "$FILE";; 236 MIN_QUALITY_BOUND=51
206 *) echo "Unknown codec: $CODEC" 237 MAX_QUALITY_BOUND=1
238 EXT=x264
239 ;;
240 x265)
241 if [ ! -x "$X265" ]; then
242 echo "Executable not found X265=$X265"
243 echo "Do you have the right X265_ROOT=$X265_ROOT"
244 exit 1
245 fi
246 MIN_QUALITY_BOUND=51
247 MAX_QUALITY_BOUND=1
248 EXT=x265
249 ;;
250 vp8|vp9|av1)
251 if [ ! -x "$VPXENC" ]; then
252 echo "Executable not found VPXENC=$VPXENC"
253 echo "Do you have the right LIBVPX_ROOT=$LIBVPX_ROOT"
254 exit 1
255 fi
256 if [ ! -x "$VPXDEC" ]; then
257 echo "Executable not found VPXDEC=$VPXDEC"
258 echo "Do you have the right LIBVPX_ROOT=$LIBVPX_ROOT"
259 exit 1
260 fi
261 MAX_QUALITY_BOUND=3
262 MIN_QUALITY_BOUND=63
263 EXT=ivf
264 ;;
265 av1)
266 if [ ! -x "$AOMENC" ]; then
267 echo "Executable not found VPXENC=$AOMENC"
268 echo "Do you have the right LIBVPX_ROOT=$LIBAOM_ROOT"
269 exit 1
270 fi
271 if [ ! -x "$AOMDEC" ]; then
272 echo "Executable not found VPXDEC=$VPXDEC"
273 echo "Do you have the right LIBVPX_ROOT=$LIBAOM_ROOT"
274 exit 1
275 fi
276 MAX_QUALITY_BOUND=3
277 MIN_QUALITY_BOUND=63
278 EXT=ivf
279 ;;
280 daala)
281 if [ ! -x "$ENCODER_EXAMPLE" ]; then
282 echo "Example encoder not found at '$ENCODER_EXAMPLE.'"
283 exit 1
284 fi
285 MAX_QUALITY_BOUND=0
286 MIN_QUALITY_BOUND=511
287 EXT=ogv
288 ;;
289 jpeg)
290 if [ ! -x "$YUVJPEG" ]; then
291 echo "Executable not found YUVJPEG=$YUVJPEG"
292 echo "Do you have the right DAALA_ROOT=$DAALA_ROOT"
293 exit 1
294 fi
295 if [ ! -x "$JPEGYUV" ]; then
296 echo "Executable not found JPEGYUV=$JPEGYUV"
297 echo "Do you have the right DAALA_ROOT=$DAALA_ROOT"
298 exit 1
299 fi
300 MAX_QUALITY_BOUND=0
301 MIN_QUALITY_BOUND=100
302 EXT=jpeg
303 ;;
207 esac 304 esac
305
306 MAX_QUALITY=$MAX_QUALITY_BOUND
307 MIN_QUALITY=$MIN_QUALITY_BOUND
308
309 export CODEC=$CODEC
310
311 while (( $MIN_QUALITY - $MAX_QUALITY > 1 )); do
312 QUALITY=$(( ($MIN_QUALITY + $MAX_QUALITY) / 2 ))
313 CURRENT_SIZE=$(x="$QUALITY" BASENAME="$BASENAME-$QUALITY-tmp" FILE="$FILE" CODEC="$CODEC" "$AB_ROOT/ab_compare_encode.sh")
314 if (($CURRENT_SIZE > $SIZE)); then
315 MAX_QUALITY=$QUALITY
316 MAX_QUALITY_SIZE=$CURRENT_SIZE
317 else
318 MIN_QUALITY=$QUALITY
319 MIN_QUALITY_SIZE=$CURRENT_SIZE
320 fi
321 done
322
323 if [ $MIN_QUALITY -eq $MIN_QUALITY_BOUND ]; then
324 MIN_QUALITY_SIZE=$(x="$MIN_QUALITY" BASENAME="$BASENAME-$QUALITY-tmp" FILE ="$FILE" CODEC="$CODEC" "$AB_ROOT/ab_compare_encode.sh")
325 fi
326
327 if [ $MAX_QUALITY -eq $MAX_QUALITY_BOUND ]; then
328 MAX_QUALITY_SIZE=$(x="$MAX_QUALITY" BASENAME="$BASENAME-$QUALITY-tmp" FILE ="$FILE" CODEC="$CODEC" "$AB_ROOT/ab_compare_encode.sh")
329 fi
330
331 if (( $MAX_QUALITY_SIZE - $SIZE < $SIZE - $MIN_QUALITY_SIZE )); then
332 BEST_QUALITY=$MAX_QUALITY
333 else
334 BEST_QUALITY=$MIN_QUALITY
335 fi
336
337 mv "$BASENAME-$BEST_QUALITY-tmp.$EXT" "$BASENAME-$BEST_QUALITY.$EXT"
338 BEST_FILE="$BASENAME-$BEST_QUALITY.$EXT"
339
340 if [ $FRAMES -eq 1 ]; then
341 $Y4M2PNG -o $BASENAME-$BEST_QUALITY.png $BASENAME-$BEST_QUALITY-tmp.y4m
342 else
343 mv $BASENAME-$BEST_QUALITY-tmp.y4m $BASENAME-$BEST_QUALITY.y4m
344 fi
345
346 rm "$BASENAME"-*-tmp*.y4m
347 rm "$BASENAME"-*-tmp*.$EXT
348 rm "$BASENAME"-*-tmp*.out
208 done 349 done
209 done 350 done
OLDNEW
« no previous file with comments | « no previous file | tools/ab_compare_daala.sh » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld