From: "Zhexiong Huang" <huangzhexiong@bytedance.com> To: <ffmpeg-devel@ffmpeg.org> Cc: Zhexiong Huang <huangzhexiong@bytedance.com> Subject: [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters Date: Fri, 17 Dec 2021 16:46:37 +0800 Message-ID: <20211217084611.3234-1-huangzhexiong@bytedance.com> (raw) 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".
next reply other threads:[~2021-12-17 8:46 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-17 8:46 Zhexiong Huang [this message] 2021-12-17 8:55 ` 黄哲雄
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211217084611.3234-1-huangzhexiong@bytedance.com \ --to=huangzhexiong@bytedance.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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