From patchwork Thu Jun 16 19:55:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 36280 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1129167pzb; Thu, 16 Jun 2022 13:07:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ulXVqaFFUeD1hvRSTz+wEstCTbDQ0k2FwWmhlnXD3ABtWPXoul0g0KqXj5fwEsWhR6gzFK X-Received: by 2002:a05:6402:1f0e:b0:42d:e38a:51f7 with SMTP id b14-20020a0564021f0e00b0042de38a51f7mr8874510edb.68.1655410041091; Thu, 16 Jun 2022 13:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655410041; cv=none; d=google.com; s=arc-20160816; b=uMR/77DIrw0BcGEHD5e/bVhbitBZOeI4QgbRzsGy3JRfIZ0/S2/MzVfugG3Fzb4wgi 6TtoRJ6edPes27Y/oYynz4cB7QDDNdGTQ+d3XLL/CgPpTIP3iNn7wClyD9izQ1WDx0T+ 8XLe47erm5G9JRGb2j+ki8C6YOXZQgA3QjauZ2qOZmmDnQieLOAgIKorEQIpjnCzH47/ lUVXwO9bWpuhm3pECVUbc7OAOwyJUVLEynl2qjqq6Bzk7L7k3Vnlis9x3GOLHRlAvzP4 sBx9gHgu7CpdcWJkLkRdHDLQBN6B3gpKDWB9O9fPp3UqnIxDZcfzuD3aIgAGgEzgttU1 UdhA== 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=oLqkT1R2knfp0jk/joFk94xUZugL4RTSVwrSYNvQx9k=; b=sne9RQZKmYLtgNbOFe+R7ch2E6NlWDnQebevIMwZHcq5wAcg9dPW20InghFpPEK3zU sCIvm9ep9Ec57XwYW1rN4T4seneACa5YzkJ/cv18KQho7scmYPCDBYFty4LxEmZTI263 dL78NjDqiufBF5KyKrPiCAuka/i4Kd7iALJupEsU+k1tsqPio6M9QmWbWAZnEBa11+u1 Sb/oFBvmu5v7XkcrJRlhClhy8iqqLEp7nesBhfq2MwaVi9LtmUoZZSVV/zts6CqoTPzu 21ImjBO8v+5cbNffbfTA8prARidLXpzW/1bE97PCvgU0PH8Qf7q71mFldqeyuO8tKNsx zjww== 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 a2-20020a509b42000000b004351fbc9afcsi2277346edj.466.2022.06.16.13.07.20; Thu, 16 Jun 2022 13:07:21 -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 5294668B860; Thu, 16 Jun 2022 23:04:03 +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 C382E68B850 for ; Thu, 16 Jun 2022 23:03:46 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5D98D240175 for ; Thu, 16 Jun 2022 22:03:46 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rpE4bhzM-KuK for ; Thu, 16 Jun 2022 22:03:45 +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 5011F240688 for ; Thu, 16 Jun 2022 22:03:34 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id CBC0F3A20E7; Thu, 16 Jun 2022 22:03:30 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 21:55:18 +0200 Message-Id: <20220616195534.5278-19-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220616195534.5278-1-anton@khirnov.net> References: <20220616195534.5278-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/35] fftools/ffmpeg: use last filter output pts to choose next output stream 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: Lb1Kz5TOZqlK This will be needed in the following commit that will add a new buffering stages after encoding and bitstream filtering. --- fftools/ffmpeg.c | 23 ++++++++++++++++++----- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_opt.c | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 53ca8c7f7b..4647555ebf 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1343,6 +1343,12 @@ static int reap_filters(int flush) continue; } + if (filtered_frame->pts != AV_NOPTS_VALUE) { + AVRational tb = av_buffersink_get_time_base(filter); + ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb, + AV_TIME_BASE_Q); + } + switch (av_buffersink_get_type(filter)) { case AVMEDIA_TYPE_VIDEO: if (!ost->frame_aspect_ratio.num) @@ -3440,13 +3446,20 @@ static OutputStream *choose_output(void) for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; - int64_t opts = ost->last_mux_dts == AV_NOPTS_VALUE ? INT64_MIN : + int64_t opts; + + if (ost->filter) { + opts = ost->last_filter_pts == AV_NOPTS_VALUE ? + INT64_MIN : ost->last_filter_pts; + } else { + opts = ost->last_mux_dts == AV_NOPTS_VALUE ? INT64_MIN : av_rescale_q(ost->last_mux_dts, ost->st->time_base, AV_TIME_BASE_Q); - if (ost->last_mux_dts == AV_NOPTS_VALUE) - av_log(NULL, AV_LOG_DEBUG, - "cur_dts is invalid st:%d (%d) [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n", - ost->st->index, ost->st->id, ost->initialized, ost->inputs_done, ost->finished); + if (ost->last_mux_dts == AV_NOPTS_VALUE) + av_log(NULL, AV_LOG_DEBUG, + "cur_dts is invalid st:%d (%d) [init:%d i_done:%d finish:%d] (this is harmless if it occurs once at the start per stream)\n", + ost->st->index, ost->st->id, ost->initialized, ost->inputs_done, ost->finished); + } if (!ost->initialized && !ost->inputs_done) return ost->unavailable ? NULL : ost; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 2aa220da29..861f8140cf 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -468,6 +468,8 @@ typedef struct OutputStream { int64_t first_pts; /* dts of the last packet sent to the muxer */ int64_t last_mux_dts; + /* pts of the last frame received from the filters, in AV_TIME_BASE_Q */ + int64_t last_filter_pts; // the timebase of the packets sent to the muxer AVRational mux_timebase; AVRational enc_timebase; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 1bcb7a3006..09a281dba3 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1662,6 +1662,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard; } ost->last_mux_dts = AV_NOPTS_VALUE; + ost->last_filter_pts = AV_NOPTS_VALUE; return ost; }