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

Unified 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
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/ab_compare_daala.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/ab_compare.sh
diff --git a/tools/ab_compare.sh b/tools/ab_compare.sh
index 8cbe3faed6059ce8f9a00d2d5d3b846f4b363987..bf4b051732ad476280850f88b4ed9c77e01c348d 100755
--- a/tools/ab_compare.sh
+++ b/tools/ab_compare.sh
@@ -59,11 +59,11 @@ while getopts 'c:s:v:b:k:ha:d:D:l:x:X:' OPTIONS; do
k) KEYINT="$OPTARG";;
h) echo "$USAGE"; exit 0;;
a) AB_ROOT="$OPTARG";;
- d) DAALA_ROOT="$OPTARG";;
- D) DAALA2_ROOT="$OPTARG";;
- l) LIBVPX_ROOT="$OPTARG";;
- x) X264_ROOT="$OPTARG";;
- X) X265_ROOT="$OPTARG";;
+ d) export DAALA_ROOT="$OPTARG";;
+ D) export DAALA2_ROOT="$OPTARG";;
+ l) export LIBVPX_ROOT="$OPTARG";;
+ x) export X264_ROOT="$OPTARG";;
+ X) export X265_ROOT="$OPTARG";;
esac
done
shift $(($OPTIND - 1))
@@ -78,7 +78,7 @@ if [ -z "$AB_ROOT" ]; then
fi
if [ -z "$DAALA_ROOT" ]; then
- DAALA_ROOT='.'
+ export DAALA_ROOT='.'
fi
if [ ! -x "$AB_ROOT" ]; then
@@ -117,6 +117,38 @@ if [ ! -x "$DAALA2_ROOT" ] && echo "$CODECS" | grep 'daala2' > /dev/null; then
exit 1
fi
+export X264="$X264_ROOT/x264"
+export X265="$X265_ROOT/build/linux/x265"
+export VPXENC="$LIBVPX_ROOT/$CODEC/vpxenc"
+export VPXDEC="$LIBVPX_ROOT/vpxdec"
+export AOMENC="$LIBAOM_ROOT/aomenc"
+export AOMDEC="$LIBAOM_ROOT/aomdec"
+if [ -z "$THORENC" ]; then
+ export THORENC="$WORK_ROOT/$CODEC/build/Thorenc"
+fi
+if [ -z "$THORDIR" ]; then
+ export THORDIR="$(dirname $THORENC)/../"
+fi
+if [ -z "$THORDEC" ]; then
+ export THORDEC="$(dirname $THORENC)/Thordec"
+fi
+if [ -z "$ENCODER_EXAMPLE" ]; then
+ export ENCODER_EXAMPLE="$DAALA_ROOT/examples/encoder_example"
+fi
+if [ -z "$YUV2YUV4MPEG" ]; then
+ YUV2YUV4MPEG=$DAALA_ROOT/tools/yuv2yuv4mpeg
+fi
+if [ -z "$YUVJPEG" ]; then
+ export YUVJPEG=yuvjpeg
+fi
+if [ -z "$JPEGYUV" ]; then
+ export JPEGYUV=jpegyuv
+fi
+
+if [ -z "$Y4M2PNG" ]; then
+ Y4M2PNG=$DAALA_ROOT/tools/y4m2png
+fi
+
if [ -z "$KEYINT" ]; then
KEYINT=256;
fi
@@ -185,25 +217,134 @@ for FILE in $@; do
SIZE=$(echo "scale=0;$SIZE/1" | bc)
fi
- if [ $USE_DAALA == "true" ]; then
- if [ -n "$V" ]; then
- $AB_ROOT/ab_compare_daala.sh -d "$DAALA_ROOT" -n "$FRAMES" -v "$V" "$FILE"
- SIZE=$(wc -c $(basename "$FILE")-$V.ogv | awk '{ print $1 }')
- else
- $AB_ROOT/ab_compare_daala.sh -d "$DAALA_ROOT" -n "$FRAMES" -s "$SIZE" "$FILE"
- fi
+ BASENAME=$(basename $FILE)
+
+ if [ -n "$V" ]; then
+ SIZE=$(x=$V CODEC=daala BASENAME=$BASENAME FILE=$FILE $AB_ROOT/ab_compare_encode.sh)
fi
for CODEC in $CODECS; do
+ WIDTH=$(head -1 $FILE | cut -d\ -f 2 | tr -d 'W')
+ HEIGHT=$(head -1 $FILE | cut -d\ -f 3 | tr -d 'H')
case $CODEC in
- daala) : ;;
- jpeg) $AB_ROOT/ab_compare_jpeg.sh -d "$DAALA_ROOT" -n "$FRAMES" -s "$SIZE" "$FILE";;
- vp8) $AB_ROOT/ab_compare_libvpx.sh -d "$DAALA_ROOT" -r "$LIBVPX_ROOT" -n "$FRAMES" -k "$KEYINT" -s "$SIZE" -c vp8 "$FILE";;
- vp9) $AB_ROOT/ab_compare_libvpx.sh -d "$DAALA_ROOT" -r "$LIBVPX_ROOT" -n "$FRAMES" -k "$KEYINT" -s "$SIZE" -c vp9 "$FILE";;
- x264) $AB_ROOT/ab_compare_x264.sh -d "$DAALA_ROOT" -r "$X264_ROOT" -n "$FRAMES" -k "$KEYINT" -s "$SIZE" "$FILE";;
- x265) $AB_ROOT/ab_compare_x265.sh -d "$DAALA_ROOT" -r "$X265_ROOT" -n "$FRAMES" -k "$KEYINT" -s "$SIZE" "$FILE";;
- daala2) $AB_ROOT/ab_compare_daala.sh -d "$DAALA_ROOT" -E "$DAALA2_ROOT/examples/encoder_example" -D "$DAALA2_ROOT/examples/dump_video" -n "$FRAMES" -s "$SIZE" -b "$FILE";;
- *) echo "Unknown codec: $CODEC"
+ x264)
+ if [ ! -x "$X264" ]; then
+ echo "Executable not found X264=$X264"
+ echo "Do you have the right X264_ROOT=$X264_ROOT"
+ exit 1
+ fi
+ MIN_QUALITY_BOUND=51
+ MAX_QUALITY_BOUND=1
+ EXT=x264
+ ;;
+ x265)
+ if [ ! -x "$X265" ]; then
+ echo "Executable not found X265=$X265"
+ echo "Do you have the right X265_ROOT=$X265_ROOT"
+ exit 1
+ fi
+ MIN_QUALITY_BOUND=51
+ MAX_QUALITY_BOUND=1
+ EXT=x265
+ ;;
+ vp8|vp9|av1)
+ if [ ! -x "$VPXENC" ]; then
+ echo "Executable not found VPXENC=$VPXENC"
+ echo "Do you have the right LIBVPX_ROOT=$LIBVPX_ROOT"
+ exit 1
+ fi
+ if [ ! -x "$VPXDEC" ]; then
+ echo "Executable not found VPXDEC=$VPXDEC"
+ echo "Do you have the right LIBVPX_ROOT=$LIBVPX_ROOT"
+ exit 1
+ fi
+ MAX_QUALITY_BOUND=3
+ MIN_QUALITY_BOUND=63
+ EXT=ivf
+ ;;
+ av1)
+ if [ ! -x "$AOMENC" ]; then
+ echo "Executable not found VPXENC=$AOMENC"
+ echo "Do you have the right LIBVPX_ROOT=$LIBAOM_ROOT"
+ exit 1
+ fi
+ if [ ! -x "$AOMDEC" ]; then
+ echo "Executable not found VPXDEC=$VPXDEC"
+ echo "Do you have the right LIBVPX_ROOT=$LIBAOM_ROOT"
+ exit 1
+ fi
+ MAX_QUALITY_BOUND=3
+ MIN_QUALITY_BOUND=63
+ EXT=ivf
+ ;;
+ daala)
+ if [ ! -x "$ENCODER_EXAMPLE" ]; then
+ echo "Example encoder not found at '$ENCODER_EXAMPLE.'"
+ exit 1
+ fi
+ MAX_QUALITY_BOUND=0
+ MIN_QUALITY_BOUND=511
+ EXT=ogv
+ ;;
+ jpeg)
+ if [ ! -x "$YUVJPEG" ]; then
+ echo "Executable not found YUVJPEG=$YUVJPEG"
+ echo "Do you have the right DAALA_ROOT=$DAALA_ROOT"
+ exit 1
+ fi
+ if [ ! -x "$JPEGYUV" ]; then
+ echo "Executable not found JPEGYUV=$JPEGYUV"
+ echo "Do you have the right DAALA_ROOT=$DAALA_ROOT"
+ exit 1
+ fi
+ MAX_QUALITY_BOUND=0
+ MIN_QUALITY_BOUND=100
+ EXT=jpeg
+ ;;
esac
+
+ MAX_QUALITY=$MAX_QUALITY_BOUND
+ MIN_QUALITY=$MIN_QUALITY_BOUND
+
+ export CODEC=$CODEC
+
+ while (( $MIN_QUALITY - $MAX_QUALITY > 1 )); do
+ QUALITY=$(( ($MIN_QUALITY + $MAX_QUALITY) / 2 ))
+ CURRENT_SIZE=$(x="$QUALITY" BASENAME="$BASENAME-$QUALITY-tmp" FILE="$FILE" CODEC="$CODEC" "$AB_ROOT/ab_compare_encode.sh")
+ if (($CURRENT_SIZE > $SIZE)); then
+ MAX_QUALITY=$QUALITY
+ MAX_QUALITY_SIZE=$CURRENT_SIZE
+ else
+ MIN_QUALITY=$QUALITY
+ MIN_QUALITY_SIZE=$CURRENT_SIZE
+ fi
+ done
+
+ if [ $MIN_QUALITY -eq $MIN_QUALITY_BOUND ]; then
+ MIN_QUALITY_SIZE=$(x="$MIN_QUALITY" BASENAME="$BASENAME-$QUALITY-tmp" FILE="$FILE" CODEC="$CODEC" "$AB_ROOT/ab_compare_encode.sh")
+ fi
+
+ if [ $MAX_QUALITY -eq $MAX_QUALITY_BOUND ]; then
+ MAX_QUALITY_SIZE=$(x="$MAX_QUALITY" BASENAME="$BASENAME-$QUALITY-tmp" FILE="$FILE" CODEC="$CODEC" "$AB_ROOT/ab_compare_encode.sh")
+ fi
+
+ if (( $MAX_QUALITY_SIZE - $SIZE < $SIZE - $MIN_QUALITY_SIZE )); then
+ BEST_QUALITY=$MAX_QUALITY
+ else
+ BEST_QUALITY=$MIN_QUALITY
+ fi
+
+ mv "$BASENAME-$BEST_QUALITY-tmp.$EXT" "$BASENAME-$BEST_QUALITY.$EXT"
+ BEST_FILE="$BASENAME-$BEST_QUALITY.$EXT"
+
+ if [ $FRAMES -eq 1 ]; then
+ $Y4M2PNG -o $BASENAME-$BEST_QUALITY.png $BASENAME-$BEST_QUALITY-tmp.y4m
+ else
+ mv $BASENAME-$BEST_QUALITY-tmp.y4m $BASENAME-$BEST_QUALITY.y4m
+ fi
+
+ rm "$BASENAME"-*-tmp*.y4m
+ rm "$BASENAME"-*-tmp*.$EXT
+ rm "$BASENAME"-*-tmp*.out
done
done
« 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