From patchwork Tue Nov 14 17:20:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44662 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134628pzg; Tue, 14 Nov 2023 09:21:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoU/VwERQgVl3e4A9Bru8ULdg0tuX9aLF/+AkCwL2OrtyHN7yvA2y1osT8onuK476oM/1R X-Received: by 2002:a05:6402:60e:b0:545:5601:4148 with SMTP id n14-20020a056402060e00b0054556014148mr8380871edv.7.1699982500200; Tue, 14 Nov 2023 09:21:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982500; cv=none; d=google.com; s=arc-20160816; b=QknUhpyUhx3w0v4tiHZ3vvaxDJJov8nnXZLBU80Oz/G9RPTx1YOV5jTU/0Yo9FNvBA GXe8D6xoqOmSjQsnUhJ1btxVVxFOY+J3ESkVuoAraHvrAII/IfsN9PBaXz3ylprtFJi/ sRiBRfxa1vnCHqgJojoDtA1IzhIDyWi+k2He2i4eMo+tAPyUNEvgenZKQETfbI0y69Tx Tw4al622MX8MRh4+wnQmxgnyBg4M5DIodf0+pLcV3znfRCJ/XVI7yGFsVe2A7fmUCmNm UdcYWzOyAv+bRI/uLAtiI4+3MizDlQzg9FKbCjZzyfCJNjFfMkdpnlSAhQhXN07I7uco xYBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=iY3JmCgg1AIITa2KzZJEQTlw0M8HVaU3zMumVMHlEh4=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=EluT1poLi9QMHyAZ9qffAcmwQ4zOexGTO19Api6rAqV2QWnNxMnKwNZEOKCvNs7TW3 dMPGGF6T2irl7fLdnAWa1yG0BONn0INa+/RzoX/borQXz/CbooYrPiuFVcvm3akqXjDV BtmjG9NtPfzzdp9KyM5xQMHCp2MfDyQOTFbr1Ihc1jxG2i3cCRinx7QNQd7GgQKVPDlF TpKnd71tbgqA8iP6TcR/b6gKQ9xWBc1vbMHXBFWqTJvwiFAyKfwlos2HLSv+GiPIKAy0 +UZvQcH//RRPxbFecUrMYh+Lomyi7YlmgY41wss5f+FUtg4s+93zG1gL1X1G61kabhJy JUnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v26-20020a056402185a00b005434096092asi4266180edy.509.2023.11.14.09.21.39; Tue, 14 Nov 2023 09:21:40 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 214A068CD7E; Tue, 14 Nov 2023 19:21:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C95CA68CD69 for ; Tue, 14 Nov 2023 19:20:56 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 03C5F40003 for ; Tue, 14 Nov 2023 17:20:55 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:50 +0100 Message-Id: <20231114172051.13872-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231114172051.13872-1-michael@niedermayer.cc> References: <20231114172051.13872-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 5/6] avcodec/h264: Avoid using gray gap frames as references 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: c5nuZyvMkz07 Signed-off-by: Michael Niedermayer --- libavcodec/h264_refs.c | 11 +++++++++++ libavcodec/h264dec.c | 1 + libavcodec/h264dec.h | 1 + 3 files changed, 13 insertions(+) diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index 92778e737a5..9bc7b20988f 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -410,6 +410,17 @@ int ff_h264_build_ref_list(H264Context *h, H264SliceContext *sl) else return -1; } + if (h->noref_gray>0 && sl->ref_list[list][index].parent->gray && h->non_gray) { + for (int j=0; jlist_count; j++) { + int list2 = (list+j)&1; + if (h->default_ref[list2].parent && !h->default_ref[list2].parent->gray + && !(!FIELD_PICTURE(h) && (h->default_ref[list2].reference&3) != 3)) { + sl->ref_list[list][index] = h->default_ref[list2]; + av_log(h, AV_LOG_DEBUG, "replacement of gray gap frame\n"); + break; + } + } + } av_assert0(av_buffer_get_ref_count(sl->ref_list[list][index].parent->f->buf[0]) > 0); } } diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 7ea55db75dd..b48821db244 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -1091,6 +1091,7 @@ static const AVOption h264_options[] = { { "nal_length_size", "nal_length_size", OFFSET(nal_length_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VDX }, { "enable_er", "Enable error resilience on damaged frames (unsafe)", OFFSET(enable_er), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VD }, { "x264_build", "Assume this x264 version if no x264 version found in any SEI", OFFSET(x264_build), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VD }, + { "noref_gray", "Avoid using gray gap frames as references", OFFSET(noref_gray), AV_OPT_TYPE_INT, {.i64 = 1}, -1, 1, VD }, { NULL }, }; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 366626c056c..591769ab258 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -571,6 +571,7 @@ typedef struct H264Context { int ref2frm[MAX_SLICES][2][64]; ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1 int non_gray; ///< Did we encounter a intra frame after a gray gap frame + int noref_gray; } H264Context; extern const uint16_t ff_h264_mb_sizes[4];