From patchwork Sun Apr 9 14:08: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: 41059 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp1591777pzb; Sun, 9 Apr 2023 07:11:28 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXGDk83BBpupNuz3w94XSiKTxX/Eap+yoRe/Et8vy/+JjTv+MU+jaKGzztqgCF1sqkSpOZ X-Received: by 2002:aa7:d855:0:b0:504:88fb:8841 with SMTP id f21-20020aa7d855000000b0050488fb8841mr4302021eds.21.1681049488155; Sun, 09 Apr 2023 07:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681049488; cv=none; d=google.com; s=arc-20160816; b=Ze79TmjZUQr55aA/cp0OpIvQ19QsQYYQuuPQu8GZcVmmh01ccT6ya0nnUfa+dd5jdb EzoNS3MqVY21sDE15jZYUdzPBl9U03/7wF223Vcs3CWMFCeR7xMKu/qqqQZNkqH8WZ7Y 0dMarwO9wysYYXxPAB/jinFThqqpoCliHr1hqx7I/oJinFhj+nKxKb93V+kgRuVztn5N 7cxecqQc8a2N9p+GSktTSvnvrM2QN1n6vgkEJt9xE1WMmlf0YbjDxD227xO1+WDM4KRs 1YzX3YNDsX2llaVmjPXfHocpT9CnaXObVdD/7XuhtesQ7Km5BrwBKxuVlOn8W+Gucdcf I6og== 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=Tv5LyIdxsflvygwtNkPUyNYmBBwINUppj9V6ddsicug=; b=IwGU3pEFwh3dW6mnXQP9YU5AXsvrT+r7/0O/Km7odpKKCZp2SeUZy09OVmAsTNkKXr ap01vsDRd5k/xKEPqmn2MCdJcnz/DobtwwYRFNQk4dLups/Ts+cbTBY5WOn0g1Xnb4bV cjBfJBvp6g6U+n5Eu6iV/bYNpJAxXophnetBgoRjUb8YWqolzMd9BVFOjKOXuBk1bBJr JKZwhP2Bl+XRrBzG6v2thLHEjeNpgL48ragc4N1xao27dRcRlhsII8fh9HTf1sr5ix4O Dhl51FZ0LiZzOUksBNU7fDYAVTFjTfQSc7s8JtWOa28JSxs8+pZPoAKqM2z80OD6hVUP 9CEQ== 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 h15-20020aa7de0f000000b004fbc39bd3a9si6079791edv.318.2023.04.09.07.11.27; Sun, 09 Apr 2023 07:11:28 -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 9916868BE2F; Sun, 9 Apr 2023 17:09:32 +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 8F58F68BCC3 for ; Sun, 9 Apr 2023 17:09:19 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 48DE62404EC for ; Sun, 9 Apr 2023 16:09:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id p0xFviCEX0gf for ; Sun, 9 Apr 2023 16:09:17 +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 C6E6E2404EE for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B2E643A038E for ; Sun, 9 Apr 2023 16:09:10 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Apr 2023 16:08:46 +0200 Message-Id: <20230409140853.28858-22-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230409140853.28858-1-anton@khirnov.net> References: <20230409140853.28858-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/29] fftools/ffmpeg: track a list of non-lavfi outputs in InputStream 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: zVXHaJMokIUW Currently, output streams where an input stream is sent directly (i.e. not through lavfi) are determined by iterating over ALL the output streams and skipping the irrelevant ones. This is awkward and inefficient. --- fftools/ffmpeg.c | 21 +++++++++------------ fftools/ffmpeg.h | 10 ++++++++++ fftools/ffmpeg_demux.c | 7 +++++++ fftools/ffmpeg_mux_init.c | 3 +++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 74aba28a9b..f65ff879c7 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -948,9 +948,6 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; - if (ost->ist != ist) - return 0; - if (ost->finished & MUXER_FINISHED) return 0; @@ -1468,7 +1465,8 @@ static int process_subtitle(InputStream *ist, AVSubtitle *subtitle, int *got_out if (!subtitle->num_rects) goto out; - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { + for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { + OutputStream *ost = ist->outputs[oidx]; if (!check_output_constraints(ist, ost) || !ost->enc_ctx || ost->enc_ctx->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; @@ -1830,7 +1828,8 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } else if (!ist->decoding_needed) eof_reached = 1; - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { + for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { + OutputStream *ost = ist->outputs[oidx]; if (!check_output_constraints(ist, ost) || ost->enc_ctx || (!pkt && no_eof)) continue; @@ -2577,13 +2576,11 @@ static int process_input(int file_index) } /* mark all outputs that don't go through lavfi as finished */ - for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { - if (ost->ist == ist && - (!ost->enc_ctx || ost->enc_ctx->codec_type == AVMEDIA_TYPE_SUBTITLE)) { - OutputFile *of = output_files[ost->file_index]; - close_output_stream(ost); - of_output_packet(of, ost->pkt, ost, 1); - } + for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { + OutputStream *ost = ist->outputs[oidx]; + OutputFile *of = output_files[ost->file_index]; + close_output_stream(ost); + of_output_packet(of, ost->pkt, ost, 1); } } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 80a1192ed0..aef2bbc0df 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -416,6 +416,14 @@ typedef struct InputStream { InputFilter **filters; int nb_filters; + /* + * Output targets that do not go through lavfi, i.e. subtitles or + * streamcopy. Those two cases are distinguished by the OutputStream + * having an encoder or not. + */ + struct OutputStream **outputs; + int nb_outputs; + int reinit_filters; /* hwaccel options */ @@ -867,6 +875,8 @@ void ifile_close(InputFile **f); */ int ifile_get_packet(InputFile *f, AVPacket **pkt); +void ist_output_add(InputStream *ist, OutputStream *ost); + /* iterate over all input streams in all input files; * pass NULL to start iteration */ InputStream *ist_iter(InputStream *prev); diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 93eed28809..f2da0826ad 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -528,6 +528,7 @@ static void ist_free(InputStream **pist) avsubtitle_free(&ist->prev_sub.subtitle); av_frame_free(&ist->sub2video.frame); av_freep(&ist->filters); + av_freep(&ist->outputs); av_freep(&ist->hwaccel_device); av_freep(&ist->dts_buffer); @@ -559,6 +560,12 @@ void ifile_close(InputFile **pf) av_freep(pf); } +void ist_output_add(InputStream *ist, OutputStream *ost) +{ + GROW_ARRAY(ist->outputs, ist->nb_outputs); + ist->outputs[ist->nb_outputs - 1] = ost; +} + static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st, enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 4b6c704046..62e5643a04 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -647,6 +647,9 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, if (ost->ist) { ost->ist->discard = 0; ost->ist->st->discard = ost->ist->user_set_discard; + + if (!(ost->enc && (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO))) + ist_output_add(ost->ist, ost); } ost->last_mux_dts = AV_NOPTS_VALUE;