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

Side by Side Diff: tools/ab_compare_x265.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_x264.sh ('k') | no next file » | 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:n:' OPTIONS; do
5 case $OPTIONS in
6 s) SIZE="$OPTARG";;
7 k) KEYINT="$OPTARG";;
8 r) X265_ROOT="$OPTARG";;
9 d) DAALA_ROOT="$OPTARG";;
10 Y) Y4M2PNG="$OPTARG";;
11 n) FRAMES="$OPTARG";;
12 esac
13 done
14 shift $(($OPTIND - 1))
15
16 if [ -z $DAALA_ROOT ]; then
17 DAALA_ROOT=.
18 fi
19
20 if [ -z $X265_ROOT ] || [ ! -d $X265_ROOT ]; then
21 echo "Please set X265_ROOT to the location of your x265 hg checkout"
22 exit 1
23 fi
24
25 if [ -z "$X265" ]; then
26 export X265=$X265_ROOT/build/linux/x265
27 fi
28
29 if [ -z "$Y4M2PNG" ]; then
30 Y4M2PNG=$DAALA_ROOT/tools/y4m2png
31 fi
32
33 if [ ! -x "$X265" ]; then
34 echo "x265 encoder not found at '$X265'."
35 exit 1
36 fi
37
38 if [ ! -x "$Y4M2PNG" ]; then
39 echo "Y4M2PNG not found at '$Y4M2PNG'."
40 exit 1
41 fi
42
43 if [ -z "$FRAMES" ]; then
44 FRAMES=1
45 fi
46
47 if [ -z "$KEYINT" ]; then
48 KEYINT=256
49 fi
50
51 FILE=$1
52 echo $FILE
53 BASENAME=$(basename $FILE)
54 WIDTH=$(head -1 $FILE | cut -d\ -f 2 | tr -d 'W')
55 HEIGHT=$(head -1 $FILE | cut -d\ -f 3 | tr -d 'H')
56 QSTR="--crf=\$x"
57 # With x265, the lowest quantizer number yields the highest quality and vice
58 # versa. Here, MAX_QUALITY produces the best looking image, so it's the
59 # lowest number.
60 MAX_QUALITY=1
61 MIN_QUALITY=51
62 while (( $MIN_QUALITY - $MAX_QUALITY > 1 )); do
63 QUALITY=$(( ($MIN_QUALITY + $MAX_QUALITY) / 2 ))
64 X265_FILE=$BASENAME-$QUALITY.x265.tmp
65 $X265 -r $X265_FILE.y4m $(echo $QSTR | sed 's/\$x/'$QUALITY'/g') --keyint $KEY INT -o $X265_FILE $FILE 2> /dev/null > /dev/null
66 X265_SIZE=$(wc -c $X265_FILE | awk '{ print $1 }')
67 if (($X265_SIZE > $SIZE)); then
68 MAX_QUALITY=$QUALITY
69 MAX_QUALITY_SIZE=$X265_SIZE
70 else
71 MIN_QUALITY=$QUALITY
72 MIN_QUALITY_SIZE=$X265_SIZE
73 fi
74 done
75
76 if [ $MIN_QUALITY -eq 51 ]; then
77 X265_FILE="$BASENAME-$MIN_QUALITY.x265.tmp"
78 $X265 -r "$X265_FILE.y4m" $(echo $QSTR | sed 's/\$x/'$MIN_QUALITY'/g') --keyin t $KEYINT -o "$X265_FILE" $FILE 2> /dev/null > /dev/null
79 MIN_QUALITY_SIZE=$(stat -c %s "$X265_FILE")
80 fi
81
82 if [ $MAX_QUALITY -eq 1 ]; then
83 X265_FILE="$BASENAME-$MAX_QUALITY.x265.tmp"
84 $X265 -r "$X265_FILE.y4m" $(echo $QSTR | sed 's/\$x/'$MAX_QUALITY'/g') --keyin t $KEYINT -o "$X265_FILE" $FILE 2> /dev/null > /dev/null
85 MAX_QUALITY_SIZE=$(stat -c %s "$X265_FILE")
86 fi
87
88 if (( $MAX_QUALITY_SIZE - $SIZE < $SIZE - $MIN_QUALITY_SIZE )); then
89 BEST_QUALITY=$MAX_QUALITY
90 else
91 BEST_QUALITY=$MIN_QUALITY
92 fi
93
94 mv $BASENAME-$BEST_QUALITY.x265.tmp $BASENAME-$BEST_QUALITY.x265
95
96 if [ $FRAMES -eq 1 ]; then
97 $Y4M2PNG -o $BASENAME-$BEST_QUALITY.x265.png $BASENAME-$BEST_QUALITY.x265.tmp. y4m
98 else
99 mv $BASENAME-$BEST_QUALITY.x265.tmp.y4m $BASENAME-$BEST_QUALITY.x265.y4m
100 fi
101
102 rm $BASENAME-*.x265.tmp $BASENAME-*.x265.tmp.y4m
OLDNEW
« no previous file with comments | « tools/ab_compare_x264.sh ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld