Skip to content

Commit e8a5879

Browse files
committed
Support single-pass bitrate target mode for rav1e
1 parent 5084371 commit e8a5879

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

metrics_gather.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ if [ -z "$CODEC" ]; then
9797
export CODEC=daala
9898
fi
9999

100+
if [ -z "$ENCODING_MODE" ]; then
101+
export ENCODING_MODE=quantizer
102+
fi
103+
100104
if [ -z "$x" ]; then
101105
echo Missing quality setting
102106
exit 1
@@ -136,6 +140,18 @@ TIMER='time -v --output='"$TIMEROUT"
136140
TIMERDEC='time -v --output='"$TIMERDECOUT"
137141
AOMDEC_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+
139155
case $CODEC in
140156
daala)
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

rd_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def run(self):
103103
run.rundir = config['runs'] + '/' + run_id
104104
run.log = log_file
105105
run.set = info['task']
106+
run.encoding_mode = info['encoding_mode']
106107
run.bindir = run.rundir + '/x86_64/'
107108
run.prefix = run.rundir + '/' + run.set
108109
try:

work.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, codec):
3838
self.info = {}
3939
self.codec = codec
4040
self.quality = quality_presets[codec]
41+
self.encoding_mode = 'quantizer'
4142
self.runid = get_time()
4243
self.extra_options = ''
4344
self.save_encode = False
@@ -179,6 +180,7 @@ def execute(self):
179180
command += 'DAALATOOL_ROOT="'+daalatool_dir+'"'
180181
command += ' x="'+str(work.quality) + '" '
181182
command += 'CODEC="'+work.codec+'" '
183+
command += 'ENCODING_MODE="'+work.encoding_mode + '" '
182184
command += 'EXTRA_OPTIONS="'+work.extra_options + '" '
183185
if self.no_delete:
184186
command += 'NO_DELETE=1 '
@@ -227,6 +229,7 @@ def create_rdwork(run, video_filenames):
227229
work.run = run
228230
work.log = run.log
229231
work.quality = q
232+
work.encoding_mode = run.encoding_mode
230233
work.runid = run.runid
231234
work.codec = run.codec
232235
work.bindir = run.bindir

0 commit comments

Comments
 (0)