Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support first-pass encoding mode for rav1e #58

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions metrics_gather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ if [ -z "$CODEC" ]; then
export CODEC=daala
fi

if [ -z "$ENCODING_MODE" ]; then
export ENCODING_MODE=quantizer
fi

if [ -z "$x" ]; then
echo Missing quality setting
exit 1
Expand Down Expand Up @@ -136,6 +140,18 @@ TIMER='time -v --output='"$TIMEROUT"
TIMERDEC='time -v --output='"$TIMERDECOUT"
AOMDEC_OPTS='-S'

if [ $ENCODING_MODE = "bitrate" ]; then
FPS_NUM=$(grep -o -a -m 1 -P "(?<=F)([0-9]+)(?=:[0-9]+)" "$FILE")
FPS_DEN=$(grep -o -a -m 1 -P "(?<=F$FPS_NUM:)([0-9]+)" "$FILE")
# compute the number of frames from the size of the input given y4m metadata
FRAMES=$(($(stat -c %s $FILE) / $WIDTH / $HEIGHT))

# computes the anchor bitrate in kilobits per second
anchor_bitrate() {
BITRATE=$(($SIZE * 8 / $FRAMES * $FPS_NUM / $FPS_DEN / 1000))
}
fi

case $CODEC in
daala)
$(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")
Expand Down Expand Up @@ -231,6 +247,20 @@ rav1e)
echo "AV1 decoder not found, desync/corruption detection disabled."
fi

if [ $ENCODING_MODE = "bitrate" ]; then
SIZE=$(stat -c %s $BASENAME.ivf)
anchor_bitrate
rm $BASENAME.ivf

# Perform the encode again in single-pass mode using the anchor bitrate.
$($TIMER $RAV1E $FILE --bitrate $BITRATE -o $BASENAME.ivf -r $BASENAME-rec.y4m --threads 1 $EXTRA_OPTIONS > $BASENAME-enc.out)
if hash dav1d 2>/dev/null; then
$($TIMERDEC dav1d -q -i $BASENAME.ivf -o $BASENAME.y4m) || (echo "Corrupt bitstream detected!"; exit 98)
elif hash aomdec 2>dev/null; then
$($TIMERDEC aomdec --codec=av1 $AOMDEC_OPTS -o $BASENAME.y4m $BASENAME.ivf) || (echo "Corrupt bitstream detected!"; exit 98)
fi
fi

if [ -f $BASENAME.y4m ]; then
"$Y4M2YUV" "$BASENAME-rec.y4m" -o rec.yuv
"$Y4M2YUV" "$BASENAME.y4m" -o enc.yuv
Expand Down
1 change: 1 addition & 0 deletions rd_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def run(self):
run.rundir = config['runs'] + '/' + run_id
run.log = log_file
run.set = info['task']
run.encoding_mode = info['encoding_mode']
run.bindir = run.rundir + '/x86_64/'
run.prefix = run.rundir + '/' + run.set
try:
Expand Down
20 changes: 20 additions & 0 deletions sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3417,5 +3417,25 @@
"sintel_trailer_2k_720p24-003.y4m",
"sintel_trailer_2k_720p24-004.y4m"
]
},
"vimeo-corpus": {
"type": "video",
"sources": [
"autumn.y4m",
"blower.y4m",
"brothers.y4m",
"coffee.y4m",
"dolphin.y4m",
"ffmpeg.y4m",
"ocean.y4m",
"rabbit.y4m",
"running_man.y4m",
"sky.y4m",
"slideshow.y4m",
"slow_pan.y4m",
"snowboard.y4m",
"surfing.y4m",
"xmas.y4m"
]
}
}
3 changes: 3 additions & 0 deletions work.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, codec):
self.info = {}
self.codec = codec
self.quality = quality_presets[codec]
self.encoding_mode = 'quantizer'
self.runid = get_time()
self.extra_options = ''
self.save_encode = False
Expand Down Expand Up @@ -179,6 +180,7 @@ def execute(self):
command += 'DAALATOOL_ROOT="'+daalatool_dir+'"'
command += ' x="'+str(work.quality) + '" '
command += 'CODEC="'+work.codec+'" '
command += 'ENCODING_MODE="'+work.encoding_mode + '" '
command += 'EXTRA_OPTIONS="'+work.extra_options + '" '
if self.no_delete:
command += 'NO_DELETE=1 '
Expand Down Expand Up @@ -227,6 +229,7 @@ def create_rdwork(run, video_filenames):
work.run = run
work.log = run.log
work.quality = q
work.encoding_mode = run.encoding_mode
work.runid = run.runid
work.codec = run.codec
work.bindir = run.bindir
Expand Down