Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 22/29] fftools/ffmpeg: track a list of non-lavfi outputs in InputStream
Date: Sun,  9 Apr 2023 16:08:46 +0200
Message-ID: <20230409140853.28858-22-anton@khirnov.net> (raw)
In-Reply-To: <20230409140853.28858-1-anton@khirnov.net>

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;
 
-- 
2.39.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2023-04-09 14:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-09 14:08 [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 02/29] fftools/ffmpeg: move OutputStream.next_pts " Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 03/29] fftools/ffmpeg: move OutputStream.sq_frame " Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 04/29] fftools/ffmpeg: move OutputStream.last_nb0_frames " Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 05/29] fftools/ffmpeg: move OutputStream.last_filter_pts to OutputFilter Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 06/29] fftools/ffmpeg_enc: replace abort() with av_assert0(0) Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 07/29] fftools/ffmpeg: drop a useless goto Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 08/29] fftools/ffmpeg: move the hw_device_free_all() call to ffmpeg_cleanup() Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 09/29] fftools/ffmpeg: eliminate the main_return_code global Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 10/29] fftools/ffmpeg: factorize checking whether any output was written Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 11/29] fftools/ffmpeg: move printing verbose muxing stats to ffmpeg_mux Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 12/29] fftools/ffmpeg_mux: reindent Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 13/29] fftools/ffmpeg_mux: log final stats to muxer context Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 14/29] fftools/ffmpeg: rewrite printing the final output sizes Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 15/29] fftools/ffmpeg_mux: make data_size_mux private to ffmpeg_mux Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 16/29] fftools/ffmpeg: move printing verbose demuxing stats to ffmpeg_demux Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 17/29] fftools/ffmpeg_demux: reindent Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 18/29] fftools/ffmpeg_demux: log final stats to demuxer context Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 19/29] fftools/ffmpeg: disable and deprecate -qphist Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 20/29] fftools/ffmpeg_filter: stop setting encoder channel layout unnecessarily Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 21/29] fftools/ffmpeg_mux_init: print more meaningful error messages Anton Khirnov
2023-04-09 14:08 ` Anton Khirnov [this message]
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 23/29] fftools/ffmpeg: stop calling check_output_constraints() for streamcopy Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 24/29] fftools/ffmpeg: inline check_output_constraints() into its only caller Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 25/29] fftools/ffmpeg_demux: set the timebase on demuxed packets Anton Khirnov
2023-04-12  2:49   ` James Almer
2023-04-12  5:59     ` Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 26/29] fftools/ffmpeg: use AVPacket.time_base to simplify do_streamcopy() Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 27/29] fftools/ffmpeg: only set InputStream.next_pts for decoding Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 28/29] fftools/ffmpeg: move checking for input -t out of do_streamcopy() Anton Khirnov
2023-04-09 14:08 ` [FFmpeg-devel] [PATCH 29/29] fftools/ffmpeg: stop using InputStream.pts for streamcopy Anton Khirnov
2023-04-11  6:35 ` [FFmpeg-devel] [PATCH 01/29] fftools/ffmpeg: move OutputStream.vsync_frame_number to Encoder Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230409140853.28858-22-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git