From patchwork Sun Dec 4 21:52:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 39592 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp2818445pzb; Sun, 4 Dec 2022 13:53:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CR06MkDQndeZOeppxqZT+n0l8W//Si/2QdD+s9yikr64bAIUP8N8JdgI0cmfI5QuHGLGr X-Received: by 2002:a17:906:60d0:b0:78d:3f87:1725 with SMTP id f16-20020a17090660d000b0078d3f871725mr16630082ejk.492.1670190828353; Sun, 04 Dec 2022 13:53:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670190828; cv=none; d=google.com; s=arc-20160816; b=Dcnxp72LCjvYMcEwLG3263s/Drq0LtjE2rqd4FfV3gDYquwZ4IPzC+oS5WRBgVPFxY hLpO5FyTqha3p4OgN2efAc/sd6tNauev7pMkjLG//BWCAEyw9nupkJJniZ7lbC59uwz+ Nca2neo3+Crf2vN6Yvh3xX0dvGGN/it4qSykjHMec7MP9g7GkVTDfP/EGeQ045xszGL+ HeA46QgteOo+YXSjSc+xP9Eii7TzahMa/p+82qQwSA6lm0K3q7f9XJ5uhCppPjoh/K2R eYweDxTMjfMN6r5e3LREqpOgTDrzO50EpnoLyvmPwNnJYw6/t1qysyJAsc5gp5OgG3WR 5bsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=3kRXThYPmIdOLF2fStommQboKkwRdUWdmULj8tBGwdM=; b=uFrUl7/yp4KM/Ca9cqS/00lOA4tz6oASpy41nz74YHB1Wes2tIqgHHdiZrY0AmPLU5 tyhLihpYsTIWZLm4JquF556fkfU4hI/V2sdmxeIVtxeicpmbiC7pONMCZSuYLrLgaUSw 0lSlgZSWaCb0oItO/KRMakuQwk4vnqDwMycdC6jYnlXlbmVucwWj/dFz8ycO5gT4oxB3 6lTKbiETBDMODcgDbVwlxr2R/NOskvkG2N5VUb7E7/S4j50bVD6wsCas1w0v5EloiFoL uimzK9BPdhHpzIBQxLc8X1UxeHBX0rCmqRI0KwlSJLtKO5LHZQLWI4ORK7AqJLMNnYxh HCeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Jw5SXL+U; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i14-20020a1709064fce00b007c0889e324esi10816141ejw.366.2022.12.04.13.53.47; Sun, 04 Dec 2022 13:53:48 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=Jw5SXL+U; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2722F68BC05; Sun, 4 Dec 2022 23:53:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F41AE68BBF1 for ; Sun, 4 Dec 2022 23:53:10 +0200 (EET) Received: by mail-ot1-f51.google.com with SMTP id a7-20020a056830008700b0066c82848060so6219878oto.4 for ; Sun, 04 Dec 2022 13:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=DZ0LjEDInEf2SIWEnbbM+ue20c9eQM9Fn/FeWWN1g74=; b=Jw5SXL+UjAzVQqaX4vHN4G5kmOlqVsiiKtouck2xCJ7EYacNickexqArQjRVZcIdiq maR1IMT+tq8TXdzIiA+31qC0501fQsj7kyj3i0lc2qAuX5OvqSRBTrl9LoBM7OE5a+u4 gmzcN8WL+3Epwdg1ex9QL4Nt2633N+bIzEplciL6NOtk0XlcaQnfWyxZQmNFHEPEyGiA asO2sDxI+cx8OaloQ54NRCBbqi4/K+hy9Y0HCKuE67704FYnO9TWMhXHU2wT/du3QBuI sofxdy8onZ57EQzuMxuxm+mJj9gKoLZ1NBoE1bI0gSPxUqtlr+7ob6A/EV4fo5drf4b4 9lhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DZ0LjEDInEf2SIWEnbbM+ue20c9eQM9Fn/FeWWN1g74=; b=qnDMu4tZpmLVs9rSNC3VQW88G4jw//LjZ+gko0Ssp/MfSyWBf2yQJTWorXEwWud7s2 QiPrgNRMN619Hwg5wa5DkiBqZVxo0fN0VS6kzhuECkHQ4sfOHNltqDml66Uac2zNM9zd w7Ew+dUUg2KxPlU1GeTU6cTmhtpglmSbeLxtF6qCANkcSptmF+0nUM5FtHaNy84UXI5l 0Yej96cH6aopumauJKWZZwEw1O5JX/sj0BQVWmfqhQChbpL4IxicOPd+b4KsDbG4KId9 apS6PpyEry7PS1A8MjAywfEe+Pl5Q/3rTWBen1T0gbDs0abz/mQ+i20G34gPIdIYyCAb KrhA== X-Gm-Message-State: ANoB5pk7ciTgfgjeS43uMFVBVKEH90Rm5qe09lTz7eHnzOCq2HbnKghw EouaTHpZhN1P122t0+RPYwI+sFjPYyA= X-Received: by 2002:a05:6830:799:b0:66e:7535:a120 with SMTP id w25-20020a056830079900b0066e7535a120mr8722663ots.249.1670190788857; Sun, 04 Dec 2022 13:53:08 -0800 (PST) Received: from localhost.localdomain ([181.85.72.69]) by smtp.gmail.com with ESMTPSA id s16-20020a056830439000b0066c7733be43sm6823100otv.30.2022.12.04.13.53.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Dec 2022 13:53:08 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Dec 2022 18:52:27 -0300 Message-Id: <20221204215227.4186-5-jamrial@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221204215227.4186-1-jamrial@gmail.com> References: <20221204215227.4186-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/mpeg4videodec: duplicate the last decoded frame when the last coded frame was skipped 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZLHRmHL0031P This ensures the video stream duration is not lost after decoding. Signed-off-by: James Almer --- libavcodec/h263dec.c | 13 +++++++++++++ libavcodec/mpegvideo.h | 1 + 2 files changed, 14 insertions(+) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index ac7a8521e5..0a2d7487a8 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -430,6 +430,18 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, return ret; s->next_picture_ptr = NULL; + *got_frame = 1; + } else if (s->skipped_last_frame && s->current_picture_ptr) { + /* Output the last picture we decoded again if the stream ended with + * an NVOP */ + if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0) + return ret; + /* Copy props from the last input packet. Otherwise, props from the last + * returned picture would be reused */ + if ((ret = ff_decode_frame_props(avctx, pict)) < 0) + return ret; + s->current_picture_ptr = NULL; + *got_frame = 1; } @@ -500,6 +512,7 @@ retry: s->extradata_parsed = 1; } ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0, 0); + s->skipped_last_frame = (ret == FRAME_SKIPPED); } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) { ret = ff_intel_h263_decode_picture_header(s); } else if (CONFIG_FLV_DECODER && s->h263_flv) { diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 6440b906b1..42275953b9 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -175,6 +175,7 @@ typedef struct MpegEncContext { Picture *last_picture_ptr; ///< pointer to the previous picture. Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) Picture *current_picture_ptr; ///< pointer to the current picture + int skipped_last_frame; int last_dc[3]; ///< last DC values for MPEG-1 int16_t *dc_val_base; int16_t *dc_val[3]; ///< used for MPEG-4 DC prediction, all 3 arrays must be continuous