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

Side by Side Diff: tools/ab_compare_daala.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 | « tools/ab_compare.sh ('k') | tools/ab_compare_encode.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2 set -e
3
4 while getopts 's:v:bk:d:E:D:y:n:' OPTIONS; do
5 case $OPTIONS in
6 s) SIZE="$OPTARG";;
7 v) V="$OPTARG";;
8 b) B_MODE='true';;
9 k) KEYINT="$OPTARG";;
10 # -b is whether or not we are running this script to produce images that
11 # are for the secondary Daala in an a-b comparison, as opposed to the
12 # first.
13 d) DAALA_ROOT="$OPTARG";;
14 E) ENCODER_EXAMPLE="$OPTARG";;
15 D) DUMP_VIDEO="$OPTARG";;
16 Y) Y4M2PNG="$OPTARG";;
17 n) FRAMES="$OPTARG";;
18 esac
19 done
20 shift $(($OPTIND - 1))
21
22 if [[ -n "$V" && -n "$SIZE" ]]; then
23 echo "Both quality setting and size specified."
24 exit 1
25 fi
26
27 if [[ -z "$V" && -z "$SIZE" ]]; then
28 echo "Neither quality setting and size specified."
29 exit 1
30 fi
31
32 if [ -z "$DAALA_ROOT" ]; then
33 DAALA_ROOT=.
34 fi
35
36 if [ -z "$ENCODER_EXAMPLE" ]; then
37 ENCODER_EXAMPLE=$DAALA_ROOT/examples/encoder_example
38 fi
39
40 if [ -z "$DUMP_VIDEO" ]; then
41 DUMP_VIDEO=$DAALA_ROOT/examples/dump_video
42 fi
43
44 if [ -z "$Y4M2PNG" ]; then
45 Y4M2PNG=$DAALA_ROOT/tools/y4m2png
46 fi
47
48 if [ ! -x "$ENCODER_EXAMPLE" ]; then
49 echo "Example encoder not found at '$ENCODER_EXAMPLE.'"
50 exit 1
51 fi
52
53 if [ ! -x "$DUMP_VIDEO" ]; then
54 echo "Video dumper not found at '$DUMP_VIDEO'."
55 exit 1
56 fi
57
58 if [ ! -x "$Y4M2PNG" ]; then
59 echo "Y4M2PNG not found at '$Y4M2PNG'."
60 exit 1
61 fi
62
63 if [ -z "$FRAMES" ]; then
64 FRAMES=1
65 fi
66
67 if [ -z "$KEYINT" ]; then
68 KEYINT=256
69 fi
70
71 FILE=$1
72 BASENAME=$(basename "$FILE")
73 if [ -n "$V" ]; then
74 echo "$FILE"
75 $ENCODER_EXAMPLE -v $V "$FILE" -o "$BASENAME-$V.ogv" 2> /dev/null
76 $DUMP_VIDEO -o "$BASENAME-$V.ogv.y4m" "$BASENAME-$V.ogv" 2> /dev/null
77
78 if [ $FRAMES -eq 1 ]; then
79 $Y4M2PNG -o "$BASENAME-$V.ogv.png" "$BASENAME-$V.ogv.y4m"
80 rm "$BASENAME-$V.ogv.y4m"
81 fi
82
83 else
84 # With Daala, the lowest quantizer number yields the highest quality and
85 # vice versa. Here, MAX_QUALITY produces the best looking image, so it's the
86 # lowest number.
87 MAX_QUALITY=0
88 MIN_QUALITY=511
89 while (( $MIN_QUALITY - $MAX_QUALITY > 1 )); do
90 QUALITY=$(( ($MIN_QUALITY + $MAX_QUALITY) / 2 ))
91 if [ "$B_MODE" == 'true' ]; then
92 OGV_FILE="$BASENAME-b-$QUALITY.ogv.tmp"
93 else
94 OGV_FILE="$BASENAME-$QUALITY.ogv.tmp"
95 fi
96 $ENCODER_EXAMPLE -v $QUALITY "$FILE" -k $KEYINT -o "$OGV_FILE" 2> /dev/null
97 OGV_SIZE=$(wc -c "$OGV_FILE" | awk '{ print $1 }')
98 if (($OGV_SIZE > $SIZE)); then
99 MAX_QUALITY=$QUALITY
100 MAX_QUALITY_SIZE=$OGV_SIZE
101 else
102 MIN_QUALITY=$QUALITY
103 MIN_QUALITY_SIZE=$OGV_SIZE
104 fi
105 done
106
107 if [ $MIN_QUALITY -eq 511 ]; then
108 if [ "$B_MODE" == 'true' ]; then
109 FILENAME="$BASENAME-b-$MIN_QUALITY.ogv.tmp"
110 else
111 FILENAME="$BASENAME-$MIN_QUALITY.ogv.tmp"
112 fi
113 $ENCODER_EXAMPLE -v $MIN_QUALITY "$FILE" -k $KEYINT -o "$FILENAME" 2> /dev/n ull
114 MIN_QUALITY_SIZE=$(stat -c %s "$FILENAME")
115 fi
116
117 if [ $MAX_QUALITY -eq 0 ]; then
118 if [ "$B_MODE" == 'true' ]; then
119 FILENAME="$BASENAME-b-$MAX_QUALITY.ogv.tmp"
120 else
121 FILENAME="$BASENAME-$MAX_QUALITY.ogv.tmp"
122 fi
123 $ENCODER_EXAMPLE -v $QUALITY "$FILE" -k $KEYINT -o "$FILENAME" 2> /dev/null
124 MAX_QUALITY_SIZE=$(stat -c %s "$FILENAME")
125 fi
126
127 if (( $MAX_QUALITY_SIZE - $SIZE < $SIZE - $MIN_QUALITY_SIZE )); then
128 VPX_SIZE=$MAX_QUALITY_SIZE
129 BEST_QUALITY=$MAX_QUALITY
130 else
131 BEST_QUALITY=$MIN_QUALITY
132 VPX_SIZE=$MIN_QUALITY_SIZE
133 fi
134
135 if [ "$B_MODE" == 'true' ]; then
136 BEST_FILE="$BASENAME-b-$BEST_QUALITY.ogv"
137 else
138 BEST_FILE="$BASENAME-$BEST_QUALITY.ogv"
139 fi
140
141 mv "$BEST_FILE.tmp" "$BEST_FILE"
142 $DUMP_VIDEO -o "$BEST_FILE.y4m" "$BEST_FILE" 2>/dev/null
143 if [ $FRAMES -eq 1 ]; then
144 $Y4M2PNG -o "$BEST_FILE.png" "$BEST_FILE.y4m"
145 rm "$BASENAME"-*.ogv.tmp "$BEST_FILE.y4m"
146 else
147 rm "$BASENAME"-*.ogv.tmp
148 fi
149 fi
OLDNEW
« no previous file with comments | « tools/ab_compare.sh ('k') | tools/ab_compare_encode.sh » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld