From patchwork Wed May 31 14:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41922 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328464pzb; Wed, 31 May 2023 07:57:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ncwECqyVwzMafP9VFZtgtwl1vuCeGYkbtPdtZGsYyjYAFr93eeOjwGQ0oIyHXW4Lmk3i+ X-Received: by 2002:a17:907:16a1:b0:973:93e3:bc9a with SMTP id hc33-20020a17090716a100b0097393e3bc9amr5826781ejc.6.1685545053456; Wed, 31 May 2023 07:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545053; cv=none; d=google.com; s=arc-20160816; b=jSDfA2LPCXlqoOGlVM9OmKrHk9bkc7VLHkN7fcYD0qz49gBqAwAGa3dxvXsr5ubnzB 0T7D0M7TMDwkvyDf8u/NkuSGFvpqje/8z4VEzQq29b6KbS+SHKlPkYxImtyEhVfqoN4c iPJIDnmGZq3W93FIu76FQ7gyLkCSkoH6112S2kXvk/7e9FRl8rvzTBF4ZNnXvd1V/ISO T+V2WwR1f7s8NvJskaUSA7COntTGMxUX/3RgdjnABgUdukDty9RWrk/ppf7+ZBsdOwQh 2gLFLQ/sztxQeXI4SOg6jnt/GVn7YKU0xEOOM47ZYFwqNXanOX6cWVIoNYdh6rKmx0Mp 8zwA== 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:delivered-to; bh=506dCbj7GJonew0H0Mgt31Z1Shs9Ba3gsqizWHrnmXg=; b=nVUPfwil3IyRLbAp8JWYdzmXBhH/QkN0XPp2zyvvXdYOOshJt5V6veX1429S8EzhAy JW+WYmzKRnx1peBMLs5uFpQXTAk3rec+IdYBQ3GnyJiHFxgOQVMXdLpzGhjqM7iCbhq2 GvUKktcnLLGCZuLG2HGdnEdYV2ki5m6A87SutabFLj6eysiOv2CUOx/KwNcBL+tSY4Q0 9CwwPf/GZ/leRj+eKyqH1arVdk1WaAySlIlMV0oK94DQ4ws3ghs/LJ6ZIGlvHppVhQSB ghBSzWk6jwNy/DYe4eDO3W50/t9ojRPHMVr2UcDgy5KeHto73LeqrQDM2/tpwnFc6IN1 +l4g== 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 z1-20020a1709067e4100b0096f61c20399si2954142ejr.689.2023.05.31.07.57.33; Wed, 31 May 2023 07:57:33 -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; 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 1C48368C300; Wed, 31 May 2023 17:55:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2AC7668C236 for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E1E772405EC for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id B6fWTpB4NCAo for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) 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 mail0.khirnov.net (Postfix) with ESMTPS id CA6962405F9 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 812DD3A0C42 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:46 +0200 Message-Id: <20230531145453.20994-16-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/23] fftools/ffmpeg: attach filter framerate to 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: M8Hg8NYNNV1G This way the encoder does not need to reach backward into the filter. --- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_enc.c | 19 +++++++++++-------- fftools/ffmpeg_filter.c | 10 ++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6f71e85658..49c07ede95 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -655,6 +655,8 @@ typedef struct FrameData { uint64_t idx; int64_t pts; AVRational tb; + + AVRational frame_rate_filter; } FrameData; extern InputFile **input_files; diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f6431b29d1..cd2faccf4e 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -217,8 +217,10 @@ int enc_open(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_VIDEO: { AVRational fr = ost->frame_rate; - if (!fr.num) - fr = av_buffersink_get_frame_rate(ost->filter->filter); + if (!fr.num && frame) { + FrameData *fd = frame_data(frame); + fr = fd->frame_rate_filter; + } if (!fr.num && !ost->max_frame_rate.num) { fr = (AVRational){25, 1}; av_log(ost, AV_LOG_WARNING, @@ -1024,17 +1026,18 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) int ret; Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; - AVRational frame_rate; int64_t nb_frames, nb_frames_prev, i; double duration = 0; - AVFilterContext *filter = ost->filter->filter; - if (frame) + if (frame) { + FrameData *fd = frame_data(frame); + duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base)); - frame_rate = av_buffersink_get_frame_rate(filter); - if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0) - duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base)); + if (duration <= 0 && + fd->frame_rate_filter.num > 0 && fd->frame_rate_filter.den > 0) + duration = 1 / (av_q2d(fd->frame_rate_filter) * av_q2d(enc->time_base)); + } video_sync_process(of, ost, frame, duration, &nb_frames, &nb_frames_prev); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 1150f6fc65..a2b45a14b8 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1711,6 +1711,16 @@ int reap_filters(int flush) tb.num, tb.den); } + if (ost->type == AVMEDIA_TYPE_VIDEO) { + FrameData *fd = frame_data(filtered_frame); + if (!fd) { + av_frame_unref(filtered_frame); + report_and_exit(AVERROR(ENOMEM)); + } + + fd->frame_rate_filter = av_buffersink_get_frame_rate(filter); + } + enc_frame(ost, filtered_frame); av_frame_unref(filtered_frame); }