From patchwork Tue Nov 14 17:20:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44658 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134210pzg; Tue, 14 Nov 2023 09:21:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRuwUA4Gs3CJuHPYfyEO/03zeEj6fIobq4mOL3nflbHEZ/oPuCD9AMoxGQke17g/gmPyLO X-Received: by 2002:a17:906:3950:b0:9e0:4910:164a with SMTP id g16-20020a170906395000b009e04910164amr6867923eje.28.1699982463986; Tue, 14 Nov 2023 09:21:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982463; cv=none; d=google.com; s=arc-20160816; b=eftMXHrQX78bms3468wJYV84oQAzZUqDcNufUd/CBC0Hz7QRO/XhiJ2GNhI6LpJfIg 7Vo569/MfoqeXgHFjDmRJKWU5EqCzVyhzgwrqU2r/9cQ6iOz3AYAeZaxIKchp6yZgkD3 cPTittggVQPt6Ln7FsSPpIofqDxBnznw6q523gkKDEXX8Udw1iQVYoGQ15xO3BoA/Eqp gKNdBdv9Qir0n9NtXvHbCzw9PJ8IESoJhREq+tc48kcz9QpA0D16e9FhuX3mjVoaYMx1 L7QiPtvDS42nG3fePGl4dEH+1YE1p9Zf15LF+GIbauAdxome124y4F1tcI3wSOu2HqsE QHFg== 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:message-id:date:to:from:delivered-to; bh=+lQqqlF6MaB7I3ShF+9+DCa/UErZN1cUtG79j9jPlzE=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=Yd2xdzEm4EbocVN/I03DzoPMEe5sg7xlXfCk7kEB6cGKvDaF+/E7ZtqJvI6rZEUbna /y2riThs/LFompaxjs2hgGOg7r2Pypril8XuNBDdLikIbK/eAnECuXJO+ZhClDx62yc2 t0zCvl/7vCR6ytKOj572iZQiGdP/lOS4qOIdwCL0I4qLvAHsmXDNn+PLYkRWv/10Ge6P KBcYgn9NLBj8++A2aZnTIMctCFYkLNyEj5q+UZ+YoFjl2rAHJRtJ+0QCW0DobGWlilat NhB1IgW6yzGVz0DMU1YK5zyxfxFm+5V4Ic3tAwOpB+4uSf/Efa+7zl0Rowkr4WrT5kLJ 8hkw== 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 kt12-20020a170906aacc00b009a1b857e3a4si4450671ejb.165.2023.11.14.09.21.02; Tue, 14 Nov 2023 09:21:03 -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 271F068CD41; Tue, 14 Nov 2023 19:21:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D5E068CBCB for ; Tue, 14 Nov 2023 19:20:53 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2A3CDFF80A for ; Tue, 14 Nov 2023 17:20:51 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:46 +0100 Message-Id: <20231114172051.13872-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/6] avcodec/h264: Seperate SEI and IDR recovery handling 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: 90dj+qCwvZQc This avoids SEI and IDR recovery flags affecting each other Also eliminate litteral numbers from recovery handling This should make the code clearer Improves: tickets/4738/tickets_cut.ts Signed-off-by: Michael Niedermayer --- libavcodec/h264_refs.c | 2 +- libavcodec/h264_slice.c | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index a11597745c8..25e521dafc0 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -822,7 +822,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) || pps_ref_count[0] <= 1 + (h->picture_structure != PICT_FRAME) && pps_ref_count[1] <= 1) && pps_ref_count[0]<=2 + (h->picture_structure != PICT_FRAME) + (2*!h->has_recovery_point) && h->cur_pic_ptr->f->pict_type == AV_PICTURE_TYPE_I){ - h->cur_pic_ptr->recovered |= 1; + h->cur_pic_ptr->recovered |= FRAME_RECOVERED_IDR; if(!h->avctx->has_b_frames) h->frame_recovered |= FRAME_RECOVERED_SEI; } diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 07cc1b094f9..4861a2cabba 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1356,12 +1356,11 @@ static int h264_select_output_frame(H264Context *h) } else h->next_outputed_poc = out->poc; - if (out->recovered) { - // We have reached an recovery point and all frames after it in - // display order are "recovered". - h->frame_recovered |= FRAME_RECOVERED_SEI; - } - out->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_SEI); + // We have reached an recovery point and all frames after it in + // display order are "recovered". + h->frame_recovered |= out->recovered; + + out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI; if (!out->recovered) { if (!(h->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) && @@ -1643,15 +1642,18 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, h->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY * !!(nal->type == H264_NAL_IDR_SLICE); - if (nal->type == H264_NAL_IDR_SLICE || - (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) { - h->recovery_frame = -1; - h->cur_pic_ptr->recovered = 1; - } - // If we have an IDR, all frames after it in decoded order are - // "recovered". - if (nal->type == H264_NAL_IDR_SLICE) + if (nal->type == H264_NAL_IDR_SLICE) { + h->cur_pic_ptr->recovered |= FRAME_RECOVERED_IDR; + // If we have an IDR, all frames after it in decoded order are + // "recovered". h->frame_recovered |= FRAME_RECOVERED_IDR; + } + + if (h->recovery_frame == h->poc.frame_num && nal->ref_idc) { + h->recovery_frame = -1; + h->cur_pic_ptr->recovered |= FRAME_RECOVERED_SEI; + } + #if 1 h->cur_pic_ptr->recovered |= h->frame_recovered; #else From patchwork Tue Nov 14 17:20:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44659 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134311pzg; Tue, 14 Nov 2023 09:21:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4Zr0/nIGra/Uq6onqMNpbG2yHlHLD4l8oZy1HcwEd/1+l6rB06rFfYwUyuLvWgIVsQiOB X-Received: by 2002:a05:6512:3142:b0:505:7371:ec83 with SMTP id s2-20020a056512314200b005057371ec83mr6677861lfi.48.1699982472944; Tue, 14 Nov 2023 09:21:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982472; cv=none; d=google.com; s=arc-20160816; b=bPyKLfGw+U9OmZUSGuU/PS+cOjMWGmUyO6Ql1Z4BokG7oZngTzCJPPeBd4buax/qpN mWTtMZO/ONMPSsdyXJgw1Jz+kS6aWPArdwCLUjv/Yl7+70yIECcRPl25Tm/elp3tDrAQ BxrUiuLgmzuupdogLu96G9VlkIAJzCH47KR6s6lvrov/Tw/PMuSCnK4mree95k94ytUQ exa++pUY7Evk3Ili6GCuw6+8JHU7fIh5r3UVelCxCXClV8mkhOgjyCXa/K+e5TrPpo9O AchCOghMsRu+z92Ne8N5VqJbh99hNrfJr0AY6cJK1QbS7Ano9CSlq7CvtECYPTLG/mzb 4p8Q== 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=zE200U35arZzRKPtGvaqNBCzTro+gVB5AiRamb8KWAg=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=hFmXBZRdopjcyRAhdffq86sQ/MwNgDN9XJOM/IXaCj1g/fM1SXz34Fr5KEnwTlnrbt FrHjFOy1sN7Ec6rYapgq4dDtudiVUVrdmQw5eZsOxQEPlLDtNnTukM6Y8ClLFOzI4MVh pcCGRPMnwBTHuWVvDzPvyqzAV6hNtR9mOx2tliOUVQCk4eMPuymqrOqC3yLSt5eQrdqj wtkMe99NdOoKMT7vuAKw+DkTMUdY5XL5aoYLJDGu5c9p5SDJgUG3LdHmoYuA3HmY1asR Bt0bBsFP5/c7zPn1jTZ4gtnQJngAfNA7xQZr0O15LOIrrA5+/zZ7QDR+PCDvoRJHS462 46Lw== 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 u26-20020a50951a000000b00543312678dcsi3997843eda.625.2023.11.14.09.21.12; Tue, 14 Nov 2023 09:21:12 -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 552E368CD30; Tue, 14 Nov 2023 19:21:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA76368CBCB for ; Tue, 14 Nov 2023 19:20:53 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 310571BF203 for ; Tue, 14 Nov 2023 17:20:52 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:47 +0100 Message-Id: <20231114172051.13872-2-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 2/6] avcodec/h264: Use FRAME_RECOVERED_HEURISTIC instead of IDR/SEI 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: EojsiZWkxgpD This keeps IDR/SEI and heuristically detected recovery points cleaner seperated Signed-off-by: Michael Niedermayer --- libavcodec/h264_refs.c | 4 ++-- libavcodec/h264dec.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index 25e521dafc0..92778e737a5 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -822,9 +822,9 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) || pps_ref_count[0] <= 1 + (h->picture_structure != PICT_FRAME) && pps_ref_count[1] <= 1) && pps_ref_count[0]<=2 + (h->picture_structure != PICT_FRAME) + (2*!h->has_recovery_point) && h->cur_pic_ptr->f->pict_type == AV_PICTURE_TYPE_I){ - h->cur_pic_ptr->recovered |= FRAME_RECOVERED_IDR; + h->cur_pic_ptr->recovered |= FRAME_RECOVERED_HEURISTIC; if(!h->avctx->has_b_frames) - h->frame_recovered |= FRAME_RECOVERED_SEI; + h->frame_recovered |= FRAME_RECOVERED_HEURISTIC; } out: diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 5ce3a6be735..b0c54ad82fb 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -519,6 +519,10 @@ typedef struct H264Context { * so all the following frames in presentation order are correct. */ #define FRAME_RECOVERED_SEI (1 << 1) +/** + * Recovery point detected by heuristic + */ +#define FRAME_RECOVERED_HEURISTIC (1 << 2) int frame_recovered; ///< Initial frame has been completely recovered From patchwork Tue Nov 14 17:20:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44660 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134425pzg; Tue, 14 Nov 2023 09:21:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGV8gOivzR564uwpnAkqR/idgOGTN0oUodoRXStjltu0nq/Ed5SXe/rRChO5+yNp2QevQ2/ X-Received: by 2002:a05:6402:10cf:b0:53f:2671:e0f4 with SMTP id p15-20020a05640210cf00b0053f2671e0f4mr7439566edu.38.1699982482174; Tue, 14 Nov 2023 09:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982482; cv=none; d=google.com; s=arc-20160816; b=pvJ8aoo+oseRPeEdyeOzSrMSkgmkdZnKwN4n/kdUd1rL9xw9zr6qz8cfOzZyiLJ+i3 /9GMwJfSRvGRbOx1FEnoSY5o3B8JMZhJmnk0jJ0aYGD2NfWSMANn1ISpxmHLR0DsjqWp xy9m9tq1hYCYQDk68RIsNGvtc5RPy4diWykBHeWAoTwovllFXLR6vLv5istCB50S3nCA PIZdgRcUtjHPJtEp3mwnXPiLqCuT35wPwcl3XVQvZOUILKCo2w+ZJtoQDvoxq/YP5IKv nfL79GMiwrhyrOeIONkeArsOZ4vZVB14geFeslaFOE5x6ZPLsWvDohAnEOBMvjW2/T1m eR4Q== 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=aDHnMhK6vcGMsfYikeRL6830M3ngGwD6zqkvje2VtHQ=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=IJg0lUjUDjHCM+j5STP5DFyBeJULTjmlmgiCZklcjDJ8OBXUUJYIm+Zgh+Bu499fZB nhtci2e65YrAzw1Bsthdq0VTQmPYTspjOYiMjPHe7YO3HayhACdEP7t2AUADidCiorPE 5b3aupnYh+S3/PW/JnS8Do/pCX+2YGuqut7uu5fzyH0DcvUFYOS4448Yy60PWyfWF3Vm KzFJaV13lth5L0aailufn5M9qXBoGoUdQ7FI5jlE9L5D7b5S5r2Akz84cKWZTsJkhmF4 4VU5Mewh3XQVGMQ7DjuDjXLPUZvAG+1RhPKHRrGbd7tZ/kVfxu7YZHz3plfbCPsa/61I whSA== 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 dm11-20020a05640222cb00b0054550d6e9b1si4086785edb.497.2023.11.14.09.21.20; Tue, 14 Nov 2023 09:21:22 -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 A7E6868CD67; Tue, 14 Nov 2023 19:21:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9AF668CD41 for ; Tue, 14 Nov 2023 19:20:54 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 303C160002 for ; Tue, 14 Nov 2023 17:20:53 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:48 +0100 Message-Id: <20231114172051.13872-3-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 3/6] avcodec/h264dec: More elaborate documentation for frame_recovered 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: vR75fayNv35h Signed-off-by: Michael Niedermayer --- libavcodec/h264dec.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index b0c54ad82fb..ede51951727 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -524,7 +524,17 @@ typedef struct H264Context { */ #define FRAME_RECOVERED_HEURISTIC (1 << 2) - int frame_recovered; ///< Initial frame has been completely recovered + /** + * Initial frame has been completely recovered. + * + * Once this is set, all following decoded as well as displayed frames will be marked as recovered + * If a frame is marked as recovered frame_recovered will be set once this frame is output and thus + * all subsequently output fraames are also marked as recovered + * + * In effect, if you want all subsequent DECODED frames marked as recovered, set frame_recovered + * If you want all subsequent DISPAYED frames marked as recovered, set the frame->recovered + */ + int frame_recovered; int has_recovery_point; From patchwork Tue Nov 14 17:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44661 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134521pzg; Tue, 14 Nov 2023 09:21:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGc5mUQT16Fk3O427wIjuu2luUL5HjB+8uwqHQeeDoYP7zkNaFLjS6/YvcGphLykoYa49Ou X-Received: by 2002:a50:ee1a:0:b0:532:bf2a:8cbc with SMTP id g26-20020a50ee1a000000b00532bf2a8cbcmr7399585eds.16.1699982490808; Tue, 14 Nov 2023 09:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982490; cv=none; d=google.com; s=arc-20160816; b=rojnYjJ0W+Eqx/y+aFoZXPaxIn7q8LZjX+Rr0TVWhz5kWZhRJJOM+i3mWma1IuZdL3 EoQEznZjqfo6UosLx3Ns1HEUZwvD8uONSk6der8roR6JOcV68370REEw9MyJORNN0M/Z StBPE1la3Wd114nyccW9J2Wcu1VHLf0fA5PP/r/XCTfFkDb7awg+2YbwH5E86rEZDM2X /apk06CanHDIQwX45mlXW3EzGS+6O7i2uMRDky6XNE8Nh6VC/V94F9djVxYRZ2LGA8/N DvufTYVPTL9iL2qK33Yr/vN1miKJ3XoW19BDfk00bKOHEpHpXnZXfyfHWCh1poAyYR6k 2pHQ== 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=PwkUfVEUpuNuPQhP1EGP1aoJJ7AZ+QZ3dXxtAJ/skjo=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=McV4b1jg96t29ecnFDa65SWd6yN5v6dDj0+xjMC1PKb5H/P82h3Z1PCbwia0gUqixc 2t/Wa0ODaFBGnnI3WcDfuz15Fb1GDkrOiNSZUPghuNIrFlvArnwBZUU1V+gbhYD+AvtS z8K2D4GqzO46vwxxiZYV8PZqsYpg/LyrGaA2Wbo9rw0k3Mw2FBUrvYGVx+UPph6V0ISQ sNaY6MeKxRN6G1shldGixIk3e55/4pcbwJ+hSIDjVtIyQAf2RIcWtkgG6nPzQM5HJttV HJsQNiCyAiV1JexGX6o342WjyRRiRb2fZxM/nH0MOe+SYGT0EPW09dYo5DjxUqU/lstk AluQ== 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 f8-20020a056402354800b005455445041asi4361658edd.346.2023.11.14.09.21.30; Tue, 14 Nov 2023 09:21:30 -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 7C96568CD7D; Tue, 14 Nov 2023 19:21:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3D6E68CD32 for ; Tue, 14 Nov 2023 19:20:55 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 072DEC0009 for ; Tue, 14 Nov 2023 17:20:54 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:49 +0100 Message-Id: <20231114172051.13872-4-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 4/6] avcodec/h264: keep track of which frames used gray 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: V0myLJj7fEX+ Signed-off-by: Michael Niedermayer --- libavcodec/h264_picture.c | 1 + libavcodec/h264_slice.c | 19 ++++++++++++++++++- libavcodec/h264dec.c | 1 + libavcodec/h264dec.h | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 691c61eea23..3234141dbd6 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -96,6 +96,7 @@ static void h264_copy_picture_params(H264Picture *dst, const H264Picture *src) dst->field_picture = src->field_picture; dst->reference = src->reference; dst->recovered = src->recovered; + dst->gray = src->gray; dst->invalid_gap = src->invalid_gap; dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt; dst->mb_width = src->mb_width; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 4861a2cabba..2c4ab89dae1 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -457,6 +457,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst, h->poc.prev_frame_num = h->poc.frame_num; h->recovery_frame = h1->recovery_frame; + h->non_gray = h1->non_gray; return err; } @@ -1544,11 +1545,14 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl, if (ret < 0) return ret; h->short_ref[0]->poc = prev->poc + 2U; + h->short_ref[0]->gray = prev->gray; ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 0); if (h->short_ref[0]->field_picture) ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 1); - } else if (!h->frame_recovered && !h->avctx->hwaccel) + } else if (!h->frame_recovered && !h->avctx->hwaccel) { color_frame(h->short_ref[0]->f, c); + h->short_ref[0]->gray = 1; + } h->short_ref[0]->frame_num = h->poc.prev_frame_num; } } @@ -2007,6 +2011,19 @@ static int h264_slice_init(H264Context *h, H264SliceContext *sl, (sl->ref_list[j][i].reference & 3); } + if (sl->slice_type_nos == AV_PICTURE_TYPE_I) { + h->cur_pic_ptr->gray = 0; + h->non_gray = 1; + } else { + int gray = 0; + for (j = 0; j < sl->list_count; j++) { + for (i = 0; i < sl->ref_count[j]; i++) { + gray |= sl->ref_list[j][i].parent->gray; + } + } + h->cur_pic_ptr->gray = gray; + } + if (h->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(h->avctx, AV_LOG_DEBUG, "slice:%d %c mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index ef9e60bbf33..7ea55db75dd 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -492,6 +492,7 @@ static void h264_decode_flush(AVCodecContext *avctx) ff_h264_unref_picture(&h->cur_pic); h->mb_y = 0; + h->non_gray = 0; ff_h264_free_tables(h); h->context_initialized = 0; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index ede51951727..366626c056c 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -154,6 +154,8 @@ typedef struct H264Picture { /// RefStruct reference; its pointee is shared between decoding threads. atomic_int *decode_error_flags; + + int gray; } H264Picture; typedef struct H264Ref { @@ -567,6 +569,8 @@ typedef struct H264Context { struct FFRefStructPool *ref_index_pool; struct FFRefStructPool *decode_error_flags_pool; 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 } H264Context; extern const uint16_t ff_h264_mb_sizes[4]; 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]; From patchwork Tue Nov 14 17:20:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 44663 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp2134750pzg; Tue, 14 Nov 2023 09:21:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvu5C3qVpA/FvdEFXid2gqGSUnND3eCkxNhCIhfHNBfUX9C6JWcoD9ImxFDJZspi5RL/WO X-Received: by 2002:a17:906:3615:b0:9be:834a:f80b with SMTP id q21-20020a170906361500b009be834af80bmr7879499ejb.75.1699982509080; Tue, 14 Nov 2023 09:21:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699982509; cv=none; d=google.com; s=arc-20160816; b=JOB+p+TGq2bVCKGKbfqpehCa+kSc0+9rE3sMNEshYR+XXFauSbJ3b24RrQyS76xgk+ shvNV6F8A1K8erkCBtR0HB6b4U8dVWKciBxvIolrEpV9w5raQ9a8GwR9V/qFrKXat1jr uiHirQAwuK8g4pw/MM8n7bVXNe134BPXMI3SDWFsB+v4DA0ZRdHWP73/pxt9HuAWvASv LZjRae9cAnqCX3ZK6p53myAoA/Jg8DSHptJ7mSHUBwIElRWm4+QGgpjdrH3p9QhNFbqn 3B9TruL51WCoge5BBoPOzk3mwsIbJwTHrkRppQbP+hp41WastgRAwvWBcJjSYDsYFdjC 7lSw== 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=iTB44fQsJe3dIITYAXfiLHOiLwKAJGOFw1HlyXA7fMA=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=enfPoXm/fxeZ0Wroa/RjFNj5wACWCRO4nbpTTECxuTg0ToGNC9+UJ2Hc1nmgBtXWsl XOKN25Ux334DHADTpbxyfKq4+zUOLvVkiQMGyGPSG/vW0ungQyhwWCC+TJSfYamlQxB8 ZK8GVPs+Flv7Pxc5wev8I1IQo23WLe3gxV3zyduNuuQY0X0A658ZtlIn7Cfj6n3dccEL iApo0A0uW7BG+GO1mbLm6t5ehDFn9g0EC/LOp0eorTFX1ke2pMwIUGTjfoefd9m/nhW+ 4zL2o57jNqXbVJUhYprPqIttj7WnBn4EV8xhVlYrujyYYMUf1LNbMbmnDQVHoyAOpOXv axkA== 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 g19-20020a170906395300b009ae027abbc0si4107063eje.1034.2023.11.14.09.21.48; Tue, 14 Nov 2023 09:21:49 -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 8766468CC56; Tue, 14 Nov 2023 19:21:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57A1368CD70 for ; Tue, 14 Nov 2023 19:20:57 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id ACF12FF809 for ; Tue, 14 Nov 2023 17:20:56 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 14 Nov 2023 18:20:51 +0100 Message-Id: <20231114172051.13872-6-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 6/6] avcodec/h264dec: Support skipping frames that used gray gap frames 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: XigWfhM3QnNZ Signed-off-by: Michael Niedermayer --- libavcodec/h264dec.c | 7 +++++++ libavcodec/h264dec.h | 1 + 2 files changed, 8 insertions(+) diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index b48821db244..aa0022a3aba 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -939,6 +939,12 @@ static int finalize_frame(H264Context *h, AVFrame *dst, H264Picture *out, int *g (h->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL) || out->recovered)) { + if (h->skip_gray > 0 && + h->non_gray && out->gray && + !(h->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL) + ) + return 0; + if (!h->avctx->hwaccel && (out->field_poc[0] == INT_MAX || out->field_poc[1] == INT_MAX) @@ -1091,6 +1097,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 }, + { "skip_gray", "Do not return gray gap frames", OFFSET(skip_gray), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, 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 591769ab258..447c2499d97 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -572,6 +572,7 @@ typedef struct H264Context { int non_gray; ///< Did we encounter a intra frame after a gray gap frame int noref_gray; + int skip_gray; } H264Context; extern const uint16_t ff_h264_mb_sizes[4];