From patchwork Wed Jan 24 08:16:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 45773 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:120f:b0:199:de12:6fa6 with SMTP id v15csp1129925pzf; Wed, 24 Jan 2024 00:19:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHb3bQQP3RcBe0g4qjt8/dATS30l3Wdiew+b4WlkajEqjs4Nn5zjPfUsL3j20Xf7Yvqi0q8 X-Received: by 2002:aa7:da45:0:b0:559:c43d:4196 with SMTP id w5-20020aa7da45000000b00559c43d4196mr810830eds.76.1706084375457; Wed, 24 Jan 2024 00:19:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706084375; cv=none; d=google.com; s=arc-20160816; b=kV5BLPLE8vnWkNFoCw296Olp0LkF+SUcRrj7xVwuVyEKx8sVf8e0d902SZZlSsWwfS FO6C4iqsJpHUy/wn8uqsUGyU/51fkGzBp3HPUlKVAoxm6hYNPmLTdd2bsEi8N3HMe05J QbYIFTvoxE/SJ07HUUVJZe0wraZZncX4r3eKhvlboHMYPuPDY6YEL7Ekt73xQyfZly5m EYzgPQGdSDiYPHmJaulT89VuLgPPbfXlU9KhihH7ugzEDfjtKJs5r3tK6FgZV9ZThkEH JSHpNRpDzWplNg8hlJTKuDeM/M1h+us1jAWCHn+/oT0glasRvJpkRJlXxPnnAhEQTOd4 2RJQ== 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=59jEB2YoodyT+7/sKNP3QPRLq2ow3QW5ZCJM4MXvgTU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=QIEKw0Sp5ypWyPozEdzhMAmPovq3cXbl/PT8GYZnSMQ1pDAD0Y1ozm9EQVs6Wufthc BYq9I2J1BD2FN4NzO/xWvTSoP0g7CdsM0kzhdQD+tcw85A0diq2eUu40P7W1vQ8zBnGf 1T4UDWUsMFqHtKh3JU7Xlik/o2GhqEDkwb4/SoVCIe2RTDUAhWpiQh9LATndHMNF7G5K OLrtZvSJzfssl845TxwBtDqcyF07N71qKZUmq/dWEf8q7kqQBF+IQySXVEuHq7RnGdH6 rBBdnjlQW7k+yD4JKUTEVOWN2U/KKNxUlpu0qEIyvXr+/1OmH2phfL5ATzfoGn0ztR/l Fzrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=gb0SNmaJ; 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 r20-20020a056402235400b0055754875fd0si5185480eda.496.2024.01.24.00.19.35; Wed, 24 Jan 2024 00:19:35 -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=@khirnov.net header.s=mail header.b=gb0SNmaJ; 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 445F268D11D; Wed, 24 Jan 2024 10:17:41 +0200 (EET) 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 4336F68D0F6 for ; Wed, 24 Jan 2024 10:17:27 +0200 (EET) 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=gb0SNmaJ; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 24BF21A41 for ; Wed, 24 Jan 2024 09:17:24 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id gulLQfWPlReT for ; Wed, 24 Jan 2024 09:17:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1706084240; bh=HobtHq6U7iAAht+QhSrAhRqIkuIyRvpw+xsn8n6Cl8A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gb0SNmaJR0QqoGvicBF697ccuKUKEXhg6EAoygJcAVD2+gBcLkFWGSrAIh6zzULzw qZtX44AZKOrFWV/qXuvist1owZYG3fFR7a0fH8ZOuDA+auhqnQvjrZq50+XEhDo8TM dA3FWV1NOZNcb7FxnMA2580WQrf+sKPmZbPOWVDg6dzkJAu6TafoU+Gb31Cc3X+h8J axRx44Ght7NdySOcF1+6+wzzabFAp/Y7wDcUfE8TrgmZ4iLwTu5Qm1ZjKuLZgR1Wf2 Kx36q6Hv7wQdsPNsCs3nCrTw7hzBxmZvtHmnuDgyDqmQ3GuaC5pzVYAihMAgv0vVRU kfp6vZj5FErfw== 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 00F1A1BAD for ; Wed, 24 Jan 2024 09:17:20 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E8ED73A0534 for ; Wed, 24 Jan 2024 09:17:19 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Jan 2024 09:16:48 +0100 Message-ID: <20240124081702.4759-18-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240124081702.4759-1-anton@khirnov.net> References: <20240124081702.4759-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/31] fftools/ffmpeg_dec: pass forced/estimated framerate though DecoderOpts 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: Y/2seL6ME0SK Stop reading them from InputStream. This is a step towards decoupling Decoder and InputStream. --- fftools/ffmpeg.h | 7 +++++++ fftools/ffmpeg_dec.c | 15 ++++++++++----- fftools/ffmpeg_demux.c | 6 ++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b4288e7352..106f943a2b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -284,6 +284,9 @@ enum DecoderFlags { DECODER_FLAG_FIX_SUB_DURATION = (1 << 0), // input timestamps are unreliable (guessed by demuxer) DECODER_FLAG_TS_UNRELIABLE = (1 << 1), + // decoder should override timestamps by fixed framerate + // from DecoderOpts.framerate + DECODER_FLAG_FRAMERATE_FORCED = (1 << 2), }; typedef struct DecoderOpts { @@ -294,6 +297,10 @@ typedef struct DecoderOpts { enum AVHWDeviceType hwaccel_device_type; char *hwaccel_device; enum AVPixelFormat hwaccel_output_format; + + // Either forced (when DECODER_FLAG_FRAMERATE_FORCED is set) or + // estimated (otherwise) video framerate. + AVRational framerate; } DecoderOpts; typedef struct Decoder { diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index babfeb1b96..937e969988 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -45,6 +45,8 @@ typedef struct DecoderPriv { // override output video sample aspect ratio with this value AVRational sar_override; + AVRational framerate_in; + // a combination of DECODER_FLAG_*, provided to dec_open() int flags; @@ -220,6 +222,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr { const DecoderPriv *dp = dp_from_dec(ist->decoder); const int ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE; + const int fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED; int64_t codec_duration = 0; // XXX lavf currently makes up frame durations when they are not provided by @@ -229,7 +232,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr // durations, then this should be simplified. // prefer frame duration for containers with timestamps - if (frame->duration > 0 && (!ts_unreliable || ist->framerate.num)) + if (frame->duration > 0 && (!ts_unreliable || fr_forced)) return frame->duration; if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) { @@ -257,8 +260,8 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr return codec_duration; // try average framerate - if (ist->st->avg_frame_rate.num && ist->st->avg_frame_rate.den) { - int64_t d = av_rescale_q(1, av_inv_q(ist->st->avg_frame_rate), + if (dp->framerate_in.num && dp->framerate_in.den) { + int64_t d = av_rescale_q(1, av_inv_q(dp->framerate_in), frame->time_base); if (d > 0) return d; @@ -330,10 +333,10 @@ static int video_frame_process(InputStream *ist, AVFrame *frame) frame->pts = frame->best_effort_timestamp; // forced fixed framerate - if (ist->framerate.num) { + if (dp->flags & DECODER_FLAG_FRAMERATE_FORCED) { frame->pts = AV_NOPTS_VALUE; frame->duration = 1; - frame->time_base = av_inv_q(ist->framerate); + frame->time_base = av_inv_q(dp->framerate_in); } // no timestamp available - extrapolate from previous frame duration @@ -961,6 +964,8 @@ int dec_open(InputStream *ist, Scheduler *sch, unsigned sch_idx, dp->dec.class = &dec_class; dp->log_parent = ist; + dp->framerate_in = o->framerate; + dp->hwaccel_id = o->hwaccel_id; dp->hwaccel_device_type = o->hwaccel_device_type; dp->hwaccel_output_format = o->hwaccel_output_format; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 5ee07f706b..2a34f97545 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -907,6 +907,12 @@ static int ist_use(InputStream *ist, int decoding_needed) ds->dec_opts.flags = (!!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION) | (!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE); + if (ist->framerate.num) { + ds->dec_opts.flags |= DECODER_FLAG_FRAMERATE_FORCED; + ds->dec_opts.framerate = ist->framerate; + } else + ds->dec_opts.framerate = ist->st->avg_frame_rate; + ret = dec_open(ist, d->sch, ds->sch_idx_dec, &ist->decoder_opts, &ds->dec_opts); if (ret < 0)