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

Side by Side Diff: tools/ab_compare_x264.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_libvpx.sh ('k') | tools/ab_compare_x265.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:k:r:d:Y:y:n:' OPTIONS; do
5 case $OPTIONS in
6 s) SIZE="$OPTARG";;
7 k) KEYINT="$OPTARG";;
8 r) X264_ROOT="$OPTARG";;
9 d) DAALA_ROOT="$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 $DAALA_ROOT ]; then
18 DAALA_ROOT=.
19 fi
20
21 if [ -z $X264_ROOT ] || [ ! -d $X264_ROOT ]; then
22 echo "Please set X264_ROOT to the location of your x264 git clone"
23 exit 1
24 fi
25
26 if [ -z "$X264" ]; then
27 export X264=$X264_ROOT/x264
28 fi
29
30 if [ -z "$YUV2YUV4MPEG" ]; then
31 YUV2YUV4MPEG=$DAALA_ROOT/tools/yuv2yuv4mpeg
32 fi
33
34 if [ -z "$Y4M2PNG" ]; then
35 Y4M2PNG=$DAALA_ROOT/tools/y4m2png
36 fi
37
38 if [ ! -x "$X264" ]; then
39 echo "x264 encoder not found at '$X264'."
40 exit 1
41 fi
42
43 if [ ! -x "$YUV2YUV4MPEG" ]; then
44 echo "YUV2YUV4MPEG not found at '$YUV2YUV4MPEG'."
45 exit 1
46 fi
47
48 if [ ! -x "$Y4M2PNG" ]; then
49 echo "Y4M2PNG not found at '$Y4M2PNG'."
50 exit 1
51 fi
52
53 if [ -z "$FRAMES" ]; then
54 FRAMES=1
55 fi
56
57 if [ -z "$KEYINT" ]; then
58 KEYINT=256
59 fi
60
61 FILE=$1
62 echo $FILE
63 BASENAME=$(basename $FILE)
64 WIDTH=$(head -1 $FILE | cut -d\ -f 2 | tr -d 'W')
65 HEIGHT=$(head -1 $FILE | cut -d\ -f 3 | tr -d 'H')
66 QSTR="--preset placebo --crf=\$x"
67 # With x264, the lowest quantizer number yields the highest quality and vice
68 # versa. Here, MAX_QUALITY produces the best looking image, so it's the
69 # lowest number.
70 MIN_QUALITY=51
71 MAX_QUALITY=1
72 while (( $MIN_QUALITY - $MAX_QUALITY > 1 )); do
73 QUALITY=$(( ($MIN_QUALITY + $MAX_QUALITY) / 2 ))
74 X264_FILE=$BASENAME-$QUALITY.x264.tmp
75 $X264 --dump-yuv $X264_FILE.yuv $(echo $QSTR | sed 's/\$x/'$QUALITY'/g') --key int $KEYINT -o $X264_FILE $FILE 2> /dev/null > /dev/null
76 X264_SIZE=$(wc -c $X264_FILE | awk '{ print $1 }')
77 if (($X264_SIZE > $SIZE)); then
78 MAX_QUALITY=$QUALITY
79 MAX_QUALITY_SIZE=$X264_SIZE
80 else
81 MIN_QUALITY=$QUALITY
82 MIN_QUALITY_SIZE=$X264_SIZE
83 fi
84 done
85
86 if [ $MIN_QUALITY -eq 51 ]; then
87 X264_FILE="$BASENAME-$MIN_QUALITY.x264.tmp"
88 $X264 --dump-yuv "$X264_FILE.yuv" $(echo $QSTR | sed 's/\$x/'$MIN_QUALITY'/g') --keyint $KEYINT -o "$X264_FILE" $FILE 2> /dev/null > /dev/null
89 MIN_QUALITY_SIZE=$(stat -c %s "$X264_FILE")
90 fi
91
92 if [ $MAX_QUALITY -eq 1 ]; then
93 X264_FILE="$BASENAME-$MAX_QUALITY.x264.tmp"
94 $X264 --dump-yuv "$X264_FILE.yuv" $(echo $QSTR | sed 's/\$x/'$MAX_QUALITY'/g') --keyint $KEYINT -o "$X264_FILE" $FILE 2> /dev/null > /dev/null
95 MAX_QUALITY_SIZE=$(stat -c %s "$X264_FILE")
96 fi
97
98 if (( $MAX_QUALITY_SIZE - $SIZE < $SIZE - $MIN_QUALITY_SIZE )); then
99 BEST_QUALITY=$MAX_QUALITY
100 else
101 BEST_QUALITY=$MIN_QUALITY
102 fi
103
104 BEST_FILE=$BASENAME-$BEST_QUALITY.x264
105 mv $BEST_FILE.tmp $BEST_FILE
106 $YUV2YUV4MPEG $BEST_FILE.tmp -w$WIDTH -h$HEIGHT -an0 -ad0 -c420mpeg2
107
108 if [ $FRAMES -eq 1 ]; then
109 $Y4M2PNG -o $BEST_FILE.png $BEST_FILE.tmp.y4m
110 rm $BEST_FILE.tmp.y4m
111 else
112 mv $BEST_FILE.tmp.y4m $BEST_FILE.y4m
113 fi
114
115 rm $BASENAME-*.x264.tmp $BASENAME-*.x264.tmp.yuv
OLDNEW
« no previous file with comments | « tools/ab_compare_libvpx.sh ('k') | tools/ab_compare_x265.sh » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld