[FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters

黄哲雄 huangzhexiong at bytedance.com
Fri Dec 17 10:55:54 EET 2021


To verify if this problem has been fixed, the following bitstream can
be used:
https://streams.videolan.org/ffmpeg/incoming/BlowingBubbles_ctu16.265
This bitstream is encoded by the following command line:
x265 --input BlowingBubbles_416x240_50.yuv --input-res 416x240 --fps 50 -s
16 -o bs.265
The MD5 of decoded yuv shall be 947723f7d8eeca7be6fcf5c91a071ada, not
18ca1e6fd9d8c47709a5bb156ee275a6 in the current version of FFmpeg.
It is verified by HM and libde265 decoder.
On Fri, Dec 17, 2021, 16:46 <huangzhexiong at bytedance.com> wrote:
As we know, in-loop filters in HEVC are applied by the following ordered
steps: firstly deblocking filter, then sample adaptive offset filter if
enabled. However, in the current version of FFmpeg, pixels without being
deblocking-filtered could be used by SAO filter when CTU size is 16 and
chroma format is 4:2:0 or 4:2:2, which could lead to the wrong result in
chroma components. This patch changes the algorithm of deblocking filter,
which ensures that SAO filter is applied after deblocking filter for all
the related pixels. The new algorithm fixes this decoding problem when CTU
size is 16, and shall not affect performance and correctness when CTU size
is 32 or 64. Signed-off-by: Zhexiong Huang --- libavcodec/hevc_filter.c |
17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff
--git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index
3c45b5a39e..c53875d85f 100644 --- a/libavcodec/hevc_filter.c +++
b/libavcodec/hevc_filter.c @@ -512,10 +512,10 @@ static void
deblocking_filter_CTB(HEVCContext *s, int x0, int y0) x_end2 = x_end; if
(x_end2 != s->ps.sps->width) - x_end2 -= 8; + x_end2 += 8; for (y = y0; y <
y_end; y += 8) { // vertical filtering luma - for (x = x0 ? x0 : 8; x <
x_end; x += 8) { + for (x = x0 + 8; x < x_end2; x += 8) { const int bs0 =
s->vertical_bs[(x + y * s->bs_width) >> 2]; const int bs1 =
s->vertical_bs[(x + (y + 4) * s->bs_width) >> 2]; if (bs0 || bs1) { @@
-545,7 +545,7 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0,
int y0) continue; // horizontal filtering luma - for (x = x0 ? x0 - 8 : 0;
x < x_end2; x += 8) { + for (x = x0; x < x_end; x += 8) { const int bs0 =
s->horizontal_bs[( x + y * s->bs_width) >> 2]; const int bs1 =
s->horizontal_bs[((x + 4) + y * s->bs_width) >> 2]; if (bs0 || bs1) { @@
-579,9 +579,13 @@ static void deblocking_filter_CTB(HEVCContext *s, int x0,
int y0) int h = 1 << s->ps.sps->hshift[chroma]; int v = 1 <<
s->ps.sps->vshift[chroma]; + x_end2 = x_end; + if (x_end2 !=
s->ps.sps->width) + x_end2 += 8 * h; + // vertical filtering chroma for (y
= y0; y < y_end; y += (8 * v)) { - for (x = x0 ? x0 : 8 * h; x < x_end; x
+= (8 * h)) { + for (x = x0 + 8 * h; x < x_end2; x += (8 * h)) { const int
bs0 = s->vertical_bs[(x + y * s->bs_width) >> 2]; const int bs1 =
s->vertical_bs[(x + (y + (4 * v)) * s->bs_width) >> 2]; @@ -612,10 +616,7
@@ static void deblocking_filter_CTB(HEVCContext *s, int x0, int y0) //
horizontal filtering chroma tc_offset = x0 ? left_tc_offset :
cur_tc_offset; - x_end2 = x_end; - if (x_end != s->ps.sps->width) - x_end2
= x_end - 8 * h; - for (x = x0 ? x0 - 8 * h : 0; x < x_end2; x += (8 * h))
{ + for (x = x0; x < x_end; x += (8 * h)) { const int bs0 =
s->horizontal_bs[( x + y * s->bs_width) >> 2]; const int bs1 =
s->horizontal_bs[((x + 4 * h) + y * s->bs_width) >> 2]; if ((bs0 == 2) ||
(bs1 == 2)) { -- 2.25.1


More information about the ffmpeg-devel mailing list