Issue 1829 in webm: The encoder config option kf_max_dist is off by one

383 views
Skip to first unread message

w… via monorail

unread,
Nov 3, 2023, 6:42:04 PM11/3/23
to webm-d...@webmproject.org
Status: Available
Owner: ----
CC: angi...@google.com, jing...@google.com, jz...@google.com
Labels: Type-Bug Pri-2

New issue 1829 by w...@google.com: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829

In vpx/vpx_encoder.h, the kf_max_dist encoder option is documented as follows:

/*!\brief Keyframe maximum interval
*
* This value, expressed as a number of frames, forces the encoder to code
* a keyframe if one has not been coded in the last kf_max_dist frames.
* A value of 0 implies all frames will be keyframes. Set kf_min_dist
* equal to kf_max_dist for a fixed interval.
*/
unsigned int kf_max_dist;

According to this comment, if I want the encoder to code a keyframe after 5 consecutive non-keyframes, I should set kf_max_dist to 5.

But setting kf_max_dist to 5 results in the following encoded frame pattern:

I1234I1234I1234I

where

I: keyframe
digit: non-keyframe

So the behavior differs from the comment by one.

This also means setting kf_max_dist to 0 and 1 are equivalent; both results in an all-intra output.

I think it is the libvpx version of the libaom bug https://crbug.com/aomedia/3069, which Angie fixed.

--
You received this message because:
1. The project was configured to send all issue notifications to this address

You may adjust your notification preferences at:
https://bugs.chromium.org/hosting/settings

angie… via monorail

unread,
Nov 21, 2023, 8:14:34 PM11/21/23
to webm-d...@webmproject.org

Comment #3 on issue 1829 by angi...@google.com: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c3

Hey Wan-Teh,
I think here we might only need to modify the comment to match the coding behavior.
kf_max_dist = 0 means every frame is key frame

kf_max_dist > 0 means two key frame's order index should be equal or less than kf_max_dist

second_keyframe_order_idx - first_keyframe_order_idx <= kf_max_dist


Example 1:
kf_max_dist = 5
first_keyframe_order_idx = 0
second_keyframe_order_idx = 5
I1234I1234I1234I seems having the right behavior.

Example 2:
kf_max_dist = 1
first_keyframe_order_idx = 0
second_keyframe_order_idx =1
IIIIIIII seems having the right behavior, although you can also set kf_max_dist = 0 to have the same effect.

The bug you mentioned is happening at one-pass coding.
Our normal test setting is using two-pass coding.

w… via monorail

unread,
Nov 22, 2023, 5:20:36 PM11/22/23
to webm-d...@webmproject.org

Comment #4 on issue 1829 by w...@google.com: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c4

Angie: Thank you for the reply. I wrote a unit test for libaom and found that libaom behaves in the same way:
https://aomedia-review.googlesource.com/c/aom/+/184181

Could you suggest new comments for kf_min_dist and kf_max_dist?

w… via monorail

unread,
Nov 22, 2023, 5:53:48 PM11/22/23
to webm-d...@webmproject.org

Comment #5 on issue 1829 by w...@google.com: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c5

Here is the unit test for libvpx:
https://chromium-review.googlesource.com/c/webm/libvpx/+/5054229

angie… via monorail

unread,
Nov 27, 2023, 3:11:33 PM11/27/23
to webm-d...@webmproject.org

Comment #6 on issue 1829 by angi...@google.com: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c6

I tested the behavior on av1 two-pass mode.
The behavior is also the same as you described for one-pass mode.

My suggestion of the comment is as follows. Please feel free to make modfication.

The maximum display order difference between two key frames.
The encoder will automatically introduce a key frame when there is a scene.
However, if the above event doesn't happen, the encoder will still introduce a key frame so that
the maximum display order between two key frames is less or equal to kf_max_dist, i.e.
kf_order_idx[k] - kf_order_idx[k-1] <= kf_max_dist

angie… via monorail

unread,
Nov 27, 2023, 3:20:51 PM11/27/23
to webm-d...@webmproject.org

Comment #7 on issue 1829 by angi...@google.com: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c7

"scene" --> "scene cut"

Git Watcher via monorail

unread,
Nov 27, 2023, 4:48:14 PM11/27/23
to webm-d...@webmproject.org

Comment #8 on issue 1829 by Git Watcher: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c8

The following revision refers to this bug:
https://aomedia.googlesource.com/aom/+/5be41ae29c56069aeb3918dffbe9366b1365bd45

commit 5be41ae29c56069aeb3918dffbe9366b1365bd45
Author: Wan-Teh Chang <w...@google.com>
Date: Wed Nov 22 22:06:26 2023

Tests kf_max_dist in one-pass zero-lag encoding

The test shows that the comment for kf_max_dist in aom/aom_encoder.h
differs from its behavior by one. We should modify the comment to match
the encoding behavior.

Bug: webm:1829
Change-Id: I729640c1e4ad6b0db5f020b7cbdd5362cbaae82b

[modify] https://crrev.com/5be41ae29c56069aeb3918dffbe9366b1365bd45/test/kf_test.cc

Git Watcher via monorail

unread,
Nov 27, 2023, 6:55:11 PM11/27/23
to webm-d...@webmproject.org

Comment #9 on issue 1829 by Git Watcher: The encoder config option kf_max_dist is off by one
https://bugs.chromium.org/p/webm/issues/detail?id=1829#c9


The following revision refers to this bug:
https://chromium.googlesource.com/webm/libvpx/+/366425079ba685bcd78511297dacb327ec363abe

commit 366425079ba685bcd78511297dacb327ec363abe
Author: Wan-Teh Chang <w...@google.com>
Date: Wed Nov 22 22:49:56 2023


Tests kf_max_dist in one-pass zero-lag encoding

The test shows that the comment for kf_max_dist in vpx/vpx_encoder.h

differs from its behavior by one. We should modify the comment to match
the encoding behavior.

Bug: webm:1829
Change-Id: Icdc58b8f6b25353f10ce8ecc481c862bd3fe86df

[modify] https://crrev.com/366425079ba685bcd78511297dacb327ec363abe/test/keyframe_test.cc
Reply all
Reply to author
Forward
0 new messages