@@ -97,6 +97,10 @@ if [ -z "$CODEC" ]; then
9797 export CODEC=daala
9898fi
9999
100+ if [ -z " $ENCODING_MODE " ]; then
101+ export ENCODING_MODE=quantizer
102+ fi
103+
100104if [ -z " $x " ]; then
101105 echo Missing quality setting
102106 exit 1
@@ -136,6 +140,18 @@ TIMER='time -v --output='"$TIMEROUT"
136140TIMERDEC=' time -v --output=' " $TIMERDECOUT "
137141AOMDEC_OPTS=' -S'
138142
143+ if [ $ENCODING_MODE = " bitrate" ]; then
144+ FPS_NUM=$( grep -o -a -m 1 -P " (?<=F)([0-9]+)(?=:[0-9]+)" " $FILE " )
145+ FPS_DEN=$( grep -o -a -m 1 -P " (?<=F$FPS_NUM :)([0-9]+)" " $FILE " )
146+ # compute the number of frames from the size of the input given y4m metadata
147+ FRAMES=$(( $(stat - c % s $FILE ) / $WIDTH / $HEIGHT ))
148+
149+ # computes the anchor bitrate in kilobits per second
150+ anchor_bitrate () {
151+ BITRATE=$(( $SIZE * 8 / $FRAMES * $FPS_NUM / $FPS_DEN / 1000 ))
152+ }
153+ fi
154+
139155case $CODEC in
140156daala)
141157 $( OD_LOG_MODULES=' encoder:10' OD_DUMP_IMAGES_SUFFIX=" $BASENAME " $TIMER " $ENCODER_EXAMPLE " -k $KFINT -v " $x " $EXTRA_OPTIONS " $FILE " -o " $BASENAME .ogv" > " $BASENAME -stdout.txt" 2> " $BASENAME -enc.out" )
@@ -231,6 +247,19 @@ rav1e)
231247 echo " AV1 decoder not found, desync/corruption detection disabled."
232248 fi
233249
250+ if [ $ENCODING_MODE = " bitrate" ]; then
251+ SIZE=$( stat -c %s $BASENAME .ivf)
252+ anchor_bitrate
253+
254+ # Perform the encode again in single-pass mode using the anchor bitrate.
255+ $( $TIMER $RAV1E $FILE --bitrate $BITRATE --first-pass $BASENAME .stats -o $BASENAME .ivf -r $BASENAME -rec.y4m --threads 1 $EXTRA_OPTIONS > $BASENAME -enc.out)
256+ if hash dav1d 2> /dev/null; then
257+ $( $TIMERDEC dav1d -q -i $BASENAME .ivf -o $BASENAME .y4m) || (echo " Corrupt bitstream detected!" ; exit 98)
258+ elif hash aomdec 2> dev/null; then
259+ $( $TIMERDEC aomdec --codec=av1 $AOMDEC_OPTS -o $BASENAME .y4m $BASENAME .ivf) || (echo " Corrupt bitstream detected!" ; exit 98)
260+ fi
261+ fi
262+
234263 if [ -f $BASENAME .y4m ]; then
235264 " $Y4M2YUV " " $BASENAME -rec.y4m" -o rec.yuv
236265 " $Y4M2YUV " " $BASENAME .y4m" -o enc.yuv
0 commit comments