From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6B07A422D1 for ; Fri, 17 Dec 2021 08:56:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DAD9E68AE6B; Fri, 17 Dec 2021 10:56:01 +0200 (EET) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0869668A59F for ; Fri, 17 Dec 2021 10:55:56 +0200 (EET) Received: by mail-lj1-f175.google.com with SMTP id z8so2201356ljz.9 for ; Fri, 17 Dec 2021 00:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=references:mime-version:in-reply-to:from:date:message-id:subject:to; bh=ad6k7e8Qur79MYBt+iScEn/FOfk1xTStmomjAlgu8EE=; b=XSIMQad+WkNKmPeLWsrRBfSsQJeCwCnlPvnAuquzbY4q6UsJ6K/KnYKgk3/AZ9Mwbh sSx5b/ZZrB+6n/HxT+m09Mg/an+ElW5zd7gNzvK6WgLNZygNcZWyCI2pWpOwFDqQZwhU KPkpc5JemSB1SVrCGQPunlzkpYoC36t0qMdg050yyzHt076g8VTlbWTIDv/QTA+mNW0T u8G8bxBHYXql2dXzjurAVHOtVF20MrmNWi9YXh8ELnVUzpsMWX3d+s4XXwflxPaWGUWH 7MPVnH3E5Iq2IXwkjM4YT1pD9io/ZMu2tUd2GEuMUR1tIWBXgKsKECig0xFU43gSppx5 RbjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:references:mime-version:in-reply-to:from:date :message-id:subject:to; bh=ad6k7e8Qur79MYBt+iScEn/FOfk1xTStmomjAlgu8EE=; b=6G2pl5tf4Mp4Zvj1sby+ne4Rq4Yf7/e6J09VQZopKzsKHBtHLwQxjSHxshJpUxbMfA alOSK5JbEVidAxp1MKum2f36H5e/HmCYIwrGpWa9KJTaFCTMB7b5HGlojFAQa6tJLrwW wi4f6ogTRDU+EBr6OpYHRevN+jDmGUOCrC4Gls1E1U3BwvaAmB3Zn5hpfIDq+tXwybfa aFXvHXhGorEOCBJKf7aeXOin6Ymb5cY/jY6eHey84iX2Zbkmd7sDLahIjPkwjNARoquJ H5a4lsBA4hop7J7tzjl2ZXFNbOs+nrz3feLvTiDWBx/xhfF335ufVYCkXPt0L4TuCvhF PI+A== X-Gm-Message-State: AOAM531eHOs7FGiF6z+xTSRPVCHy7YQ03Re1KrvJMv0o1KS58KnQ9Kl2 bmcdxqSlOeNeBRX8Dfv597sRKjqo5JtJ3h+2+BYEzyMhcUo= X-Google-Smtp-Source: ABdhPJz144Wisd6PnA1M6m9d5RKf8ZaT+WON2EoGqT8CQBqBpL0yBsXqoNz6SXMkD7WhS3kv7X2xHfRI4R1lsjoVFaw= X-Received: by 2002:a2e:9699:: with SMTP id q25mr1977095lji.6.1639731354733; Fri, 17 Dec 2021 00:55:54 -0800 (PST) Received: from 349319672217 named unknown by gmailapi.google.com with HTTPREST; Fri, 17 Dec 2021 00:55:54 -0800 References: <20211217084611.3234-1-huangzhexiong@bytedance.com> Mime-Version: 1.0 In-Reply-To: <20211217084611.3234-1-huangzhexiong@bytedance.com> From: =?UTF-8?B?6buE5ZOy6ZuE?= Date: Fri, 17 Dec 2021 00:55:54 -0800 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH] avcodec/hevcdec: fix the order of in-loop filters X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 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".