* [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters
@ 2021-12-17 8:46 Zhexiong Huang
2021-12-17 8:55 ` 黄哲雄
0 siblings, 1 reply; 2+ messages in thread
From: Zhexiong Huang @ 2021-12-17 8:46 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Zhexiong Huang
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 <huangzhexiong@bytedance.com>
---
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
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters
2021-12-17 8:46 [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters Zhexiong Huang
@ 2021-12-17 8:55 ` 黄哲雄
0 siblings, 0 replies; 2+ messages in thread
From: 黄哲雄 @ 2021-12-17 8:55 UTC (permalink / raw)
To: ffmpeg-devel
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@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
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-17 8:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-17 8:46 [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters Zhexiong Huang
2021-12-17 8:55 ` 黄哲雄
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git