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

Side by Side Diff: tools/ab_compare_jpeg.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_encode.sh ('k') | tools/ab_compare_libvpx.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:d:J:j:Y:y:n:' OPTIONS; do
5 case $OPTIONS in
6 s) SIZE="$OPTARG";;
7 d) DAALA_ROOT="$OPTARG";;
8 J) YUVJPEG="$OPTARG";;
9 j) JPEGYUV="$OPTARG";;
10 Y) Y4M2PNG="$OPTARG";;
11 y) YUV2YUV4MPEG="$OPTARG";;
12 n) FRAMES="$OPTARG";;
13 esac
14 done
15 shift $(($OPTIND - 1))
16
17 if [ -z "$SIZE" ]; then
18 echo "No file size given."
19 exit 1
20 fi
21
22 if [ -z $DAALA_ROOT ]; then
23 DAALA_ROOT=.
24 fi
25
26 if [ -z "$YUVJPEG" ]; then
27 YUVJPEG=$DAALA_ROOT/tools/yuvjpeg
28 fi
29
30 if [ -z "$JPEGYUV" ]; then
31 JPEGYUV=$DAALA_ROOT/tools/jpegyuv
32 fi
33
34 if [ -z "$YUV2YUV4MPEG" ]; then
35 YUV2YUV4MPEG=$DAALA_ROOT/tools/yuv2yuv4mpeg
36 fi
37
38 if [ -z "$Y4M2PNG" ]; then
39 Y4M2PNG=$DAALA_ROOT/tools/y4m2png
40 fi
41
42 if [ ! -x "$YUVJPEG" ]; then
43 echo "YUVJPEG not found at '$YUVJPEG'."
44 # exit 1
45 fi
46
47 if [ ! -x "$JPEGYUV" ]; then
48 echo "JPEGYUV not found at '$JPEGYUV'."
49 exit 1
50 fi
51
52 if [ ! -x "$YUV2YUV4MPEG" ]; then
53 echo "YUV2YUV4MPEG not found at '$YUV2YUV4MPEG'."
54 exit 1
55 fi
56
57 if [ ! -x "$Y4M2PNG" ]; then
58 echo "Y4M2PNG not found at '$Y4M2PNG'."
59 exit 1
60 fi
61
62 if [ -z "$FRAMES" ]; then
63 FRAMES=1
64 fi
65
66 if [ $FRAMES -gt 1 ]; then
67 echo "JPEG can't encode videos, only still pictures."
68 exit 1
69 fi
70
71 FILE=$1
72 echo $FILE
73 BASENAME=$(basename $FILE)
74 tail -n+3 $FILE > $BASENAME-in.yuv
75 WIDTH=$(head -1 $FILE | cut -d\ -f 2 | tr -d 'W')
76 HEIGHT=$(head -1 $FILE | cut -d\ -f 3 | tr -d 'H')
77 # With JPEG, the highest quality number creates the best-looking image.
78 MAX_QUALITY=100
79 MIN_QUALITY=0
80 while (( $MAX_QUALITY - $MIN_QUALITY > 1 )); do
81 QUALITY=$(( ($MIN_QUALITY + $MAX_QUALITY) / 2 ))
82 JPEG_FILE=$BASENAME-$QUALITY.jpeg.tmp
83 $YUVJPEG $QUALITY "$WIDTH"x$HEIGHT $BASENAME-in.yuv $JPEG_FILE
84 JPEG_SIZE=$(wc -c $JPEG_FILE | awk '{ print $1 }')
85 if (($JPEG_SIZE > $SIZE)); then
86 MAX_QUALITY=$QUALITY
87 MAX_QUALITY_SIZE=$JPEG_SIZE
88 else
89 MIN_QUALITY=$QUALITY
90 MIN_QUALITY_SIZE=$JPEG_SIZE
91 fi
92 done
93
94 if [ $MIN_QUALITY -eq 0 ]; then
95 $YUVJPEG $MIN_QUALITY "$WIDTH"x$HEIGHT $BASENAME-in.yuv $BASENAME-$MIN_QUALITY.j peg.tmp
96 MIN_QUALITY_SIZE=$(stat -c %s $BASENAME-$MIN_QUALITY.jpeg.tmp)
97 fi
98
99 if [ $MAX_QUALITY -eq 100 ]; then
100 $YUVJPEG $MAX_QUALITY "$WIDTH"x$HEIGHT $BASENAME-in.yuv $BASENAME-$MAX_QUALITY.j peg.tmp
101 MAX_QUALITY_SIZE=$(stat -c %s $BASENAME-$MAX_QUALITY.jpeg.tmp)
102 fi
103
104 if (( $MAX_QUALITY_SIZE - $SIZE < $SIZE - $MIN_QUALITY_SIZE )); then
105 BEST_QUALITY=$MAX_QUALITY
106 else
107 BEST_QUALITY=$MIN_QUALITY
108 fi
109
110 BEST_FILE=$BASENAME-$BEST_QUALITY.jpeg
111 mv $BEST_FILE.tmp $BEST_FILE
112 $JPEGYUV $BEST_FILE $BEST_FILE.yuv
113 $YUV2YUV4MPEG $BEST_FILE -w$WIDTH -h$HEIGHT -an0 -ad0 -c420mpeg2
114 $Y4M2PNG -o $BEST_FILE.png $BEST_FILE.y4m
115 rm $BASENAME-in.yuv $BASENAME-*.jpeg.tmp
116 rm $BEST_FILE.yuv $BEST_FILE.y4m
OLDNEW
« no previous file with comments | « tools/ab_compare_encode.sh ('k') | tools/ab_compare_libvpx.sh » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld