From patchwork Wed Sep 11 14:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51509 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:14c:b0:48e:c0f8:d0de with SMTP id h12csp381498vqi; Wed, 11 Sep 2024 08:09:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXY7PvbmEYsHttOzdB8TC9uUT/7b8X8gGauU2ebtgiJb2EbgQuep2Gh5DUYSXo6R6HxXap8LgnOTAPSpR8R8+HE@gmail.com X-Google-Smtp-Source: AGHT+IHc8GvqSEQGp0g+oyheJF7pnBJ/GzkLfic9at8ZTz94abvwJE+69pLfAgj/OWBG0yGFRKuw X-Received: by 2002:a05:6512:3c88:b0:52c:e012:efad with SMTP id 2adb3069b0e04-53673a63416mr2595950e87.12.1726067351462; Wed, 11 Sep 2024 08:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726067351; cv=none; d=google.com; s=arc-20240605; b=Lnp0pu0nfukQTpojuXIHQ4X++JM2pZUZ4w/097pQq3bvwRqXX8Ynvc2v1AY7etTd/Y PxO2t6016BOosZVWkTzcuP8mnQmM+VgriB4S+mj+waNQFCHhd/08Tw8hvmS2+4dKxViQ Q/pxMaJyd4wwXvRF67d7kREEz6AtBff7WjKWLHyfSJduf2Hr8PhrtgB4Mn9xUy49uhNz pWWXlZi9NkHEp9DUWvpAG0MF385vdTfqVH0Oc0ONlOC2Z/kA+zrm09ePaMsdcesA2Zkx csCl5UxTyvlEPXzZGmaQdfTqGbjDeNgluSPSKcGDERYLEO58u7yBg2y7TA6g1ltbacSu bDUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=xilD7e6FXTEtzixULpSReDTT4hfJwSDVsqAU6trT894=; fh=mbGWaNzHabgiiv1Xe/A5AxSfHDgNA8Py6GGI7jUB+28=; b=kxLPxfQ/w+0KNdjpd8QTHzr2Syf6ib0OUG1SphMj0otADU6+UN13MYmKvF6ra3Lp48 l/HSGuOQ3bOoOE8MRphbJwtFXBMXPpdD+2mk6bIWJBKYnRoIcg/BWGd68MkV2JeZXlbA KSUZ3RHyPM5OA9XiyH6JfUdi4xTvVhKuELq6Bp64WqvGQw8TALNf9u6W8i1rbZK5o/PG bRAlTkRMOOFRHDw9CaQsl7dh7UcBia5isMSykNqVngvkkDNJ1YRz9TOH//YcZGF6h4dU nQ70kgjIRhJ5syXoUObUUQ88LdIqq8+yu/H1p5lPItQkiK49AGHjEjQzya49PQgZH8Dh vAxw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=WQCSCefQ; 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 2adb3069b0e04-5365f906079si3280101e87.488.2024.09.11.08.09.10; Wed, 11 Sep 2024 08:09:11 -0700 (PDT) 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=@khirnov.net header.s=mail header.b=WQCSCefQ; 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 4D98968DDCF; Wed, 11 Sep 2024 17:43:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58C3568DED5 for ; Wed, 11 Sep 2024 17:43:40 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=WQCSCefQ; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5B8694DFA; Wed, 11 Sep 2024 16:43:39 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id YfWu0CU2sUak; Wed, 11 Sep 2024 16:43:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1726065816; bh=AkXGeRKPUG6l0YeSURYW3aTRy/UqhpXemucj/aMsOsM=; h=From:To:Cc:Subject:Date:From; b=WQCSCefQEEUaNkOuXo8KahsJkSybqNZFmqrKE3uZiDcvfyZlvJbnzbZQtcNRcw+bj nfF+2t4aITelbl2IblbZ8WATw66IM2LpxvNmhW5ZTYE/Ga9ImRm50m0w5MFii7sFbi jWBbBFbun78O6xNWHUVnkaQIglqm1nR/Z7vxTRlNCfhXbiCDmlD0wZpqXXDE0MM0Pb N/YHXg+o7lv//bMfFuNM5xTmFhdGdruwPR+y0HmdRO5vDtXgOeJ2kXe4u1XQN0xiZi 8s36IrLLk6bnjtTHaFbaLfTtz0agOMqn2IOatZZHtUSKUSpMIY4RmffpM2ch4z51ke Tx21gxHVslVtg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id AE32A4DDE; Wed, 11 Sep 2024 16:43:36 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 89E2D3A0229; Wed, 11 Sep 2024 16:43:36 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 11 Sep 2024 16:41:00 +0200 Message-ID: <20240911144100.8778-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/hevcdec: set output frame pkt_dts 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 Cc: llyyr.public@gmail.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: db1wBFcVKywF pkt_dts needs to be set manually when using the receive_frame() callback, so it was unset after 2fdecbb239714b6203e37067fda2521f80e19d47. Fixes PTS guessing for certain files with broken timestamps. Cf. https://github.com/mpv-player/mpv/issues/14806 Reported-by: llyyr --- libavcodec/hevc/hevcdec.c | 4 ++++ libavcodec/hevc/hevcdec.h | 3 +++ libavcodec/hevc/refs.c | 10 ++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index c8c425fd71..d67730418b 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3444,6 +3444,8 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) uint8_t *sd; size_t sd_size; + s->pkt_dts = AV_NOPTS_VALUE; + if (ff_container_fifo_can_read(s->output_fifo)) goto do_output; @@ -3457,6 +3459,8 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) } else if (ret < 0) return ret; + s->pkt_dts = avpkt->dts; + sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); if (sd && sd_size > 0) { ret = hevc_decode_extradata(s, sd, sd_size, 0); diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index e43f2d0201..e3194fd87e 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -545,6 +545,9 @@ typedef struct HEVCContext { int film_grain_warning_shown; + // dts of the packet currently being decoded + int64_t pkt_dts; + AVBufferRef *rpu_buf; ///< 0 or 1 Dolby Vision RPUs. DOVIContext dovi_ctx; ///< Dolby Vision decoding context } HEVCContext; diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c index 09d759f936..20fdbb5794 100644 --- a/libavcodec/hevc/refs.c +++ b/libavcodec/hevc/refs.c @@ -182,7 +182,7 @@ int ff_hevc_output_frames(HEVCContext *s, HEVCLayerContext *l, int nb_dpb = 0; int nb_output = 0; int min_poc = INT_MAX; - int i, min_idx, ret; + int i, min_idx, ret = 0; for (i = 0; i < FF_ARRAY_ELEMS(l->DPB); i++) { HEVCFrame *frame = &l->DPB[i]; @@ -199,10 +199,12 @@ int ff_hevc_output_frames(HEVCContext *s, HEVCLayerContext *l, if (nb_output > max_output || (nb_output && nb_dpb > max_dpb)) { HEVCFrame *frame = &l->DPB[min_idx]; + AVFrame *f = frame->needs_fg ? frame->frame_grain : frame->f; - ret = discard ? 0 : - ff_container_fifo_write(s->output_fifo, - frame->needs_fg ? frame->frame_grain : frame->f); + if (!discard) { + f->pkt_dts = s->pkt_dts; + ret = ff_container_fifo_write(s->output_fifo, f); + } ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT); if (ret < 0) return ret;