Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Derek Buitenhuis via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Derek Buitenhuis <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PR] [RFC] avformat: Add an option to force analysis of all known streams (PR #21395)
Date: Tue, 06 Jan 2026 15:27:48 -0000
Message-ID: <176771326910.25.734799837863509048@4457048688e7> (raw)

PR #21395 opened by Derek Buitenhuis (dwbuiten)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21395
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21395.patch

Often it happens that when probing streams, we already know the the
number of streams we have, but fail to fill out all the codec info
like pixel format, etc. due to relying on an arbitrary max analyze
duration set by us or the user.

>From a user perspective, using the API or `ffprobe`, you would end
up with weird hacks/workarounds like probing once to get the number
of streams and starting timestamp, since the format has that in its
header, and then probing a second time, with `analyzeduration` set
to the first timestamp, or exponentially increasing until all info
is filled out. This is, of course, silly.

Add an option to probe until all streams are analyzed, if possible.

(This, of course, does not fix the case like in FLV where we may not
even know there is another stream until it is seen.)


>From 14bec46baa75d32765c2dcabcd4472337d1e42ae Mon Sep 17 00:00:00 2001
From: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Date: Tue, 6 Jan 2026 15:12:43 +0000
Subject: [PATCH] avformat: Add an option to force analysis of all known
 streams

Often it happens that when probing streams, we already know the the
number of streams we have, but fail to fill out all the codec info
like pixel format, etc. due to relying on an arbitrary max analyze
duration set by us or the user.

>From a user perspective, using the API or ffprobe, you would end
up with weird hacks/workarounds like probing once to get the number
of streams and starting timestamp, since the format has that in its
header, and then probing a second time, with analyzeduration set
to the first timestamp, or exponentially increasing until all info
is filled out. This is, of course, silly.

Add an option to probe until all streams are analyzed, if possible.

(This, of course, does not fix the case like in FLV where we may not
even know there is another stream until it is seen.)

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
---
 doc/formats.texi            | 7 +++++++
 libavformat/avformat.h      | 7 +++++++
 libavformat/demux.c         | 4 +++-
 libavformat/options_table.h | 1 +
 libavformat/version.h       | 2 +-
 5 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/doc/formats.texi b/doc/formats.texi
index 876a9e92b3..1a66a61fd2 100644
--- a/doc/formats.texi
+++ b/doc/formats.texi
@@ -245,6 +245,13 @@ Default behaviour is a general purpose trade-off, largely adaptive, but the prob
 will not be extended to get streams durations at all costs.
 Must be an integer not lesser than 1, or 0 for default behaviour.
 
+@item force_analyze_all_streams @var{integer} (@emph{input})
+For formats which we know the number of streams (due to header, etc.), setting
+this forces stream probing to keep reading packets until it has info for all
+known streams, regardless of what @code{analyzeduration} is set to. Note that
+this may cause excessive reads, which may matter if probing over a network.
+Note that @code{probesize} is still respected.
+
 @item strict, f_strict @var{integer} (@emph{input/output})
 Specify how strictly to follow the standards. @code{f_strict} is deprecated and
 should be used only via the @command{ffmpeg} tool.
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index bd34132e00..7527129f66 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1884,6 +1884,13 @@ typedef struct AVFormatContext {
      * @see skip_estimate_duration_from_pts
      */
     int64_t duration_probesize;
+
+    /**
+     * Force all streams to be analyzed, regardless of what max_analyze_duration is set
+     * to. Demuxing only. Default is 0 (off).
+     */
+     int force_analyze_all_streams;
+
 } AVFormatContext;
 
 /**
diff --git a/libavformat/demux.c b/libavformat/demux.c
index b40739dc3a..8ea9c00797 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -2872,7 +2872,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
             else if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) limit = max_subtitle_analyze_duration;
             else                                                     limit = max_stream_analyze_duration;
 
-            if (t >= limit) {
+            if (!analyzed_all_streams && ic->force_analyze_all_streams) {
+                av_log(ic, AV_LOG_VERBOSE, "hit max_analyze_duration but ignoring, since force_analyze_all_streams is set.\n");
+            } else if (t >= limit) {
                 av_log(ic, AV_LOG_VERBOSE, "max_analyze_duration %"PRId64" reached at %"PRId64" microseconds st:%d\n",
                        limit,
                        t, pkt->stream_index);
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 5047b5ce50..7e54828c66 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -106,6 +106,7 @@ static const AVOption avformat_options[] = {
 {"skip_estimate_duration_from_pts", "skip duration calculation in estimate_timings_from_pts", OFFSET(skip_estimate_duration_from_pts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D},
 {"max_probe_packets", "Maximum number of packets to probe a codec", OFFSET(max_probe_packets), AV_OPT_TYPE_INT, { .i64 = 2500 }, 0, INT_MAX, D },
 {"duration_probesize", "Maximum number of bytes to probe the durations of the streams in estimate_timings_from_pts", OFFSET(duration_probesize), AV_OPT_TYPE_INT64, {.i64 = 0 }, 0, (double)INT64_MAX, D},
+{"force_analyze_all_streams", "Force all streams to be analyzed, regardless of analyzeduration", OFFSET(force_analyze_all_streams), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D},
 {NULL},
 };
 
diff --git a/libavformat/version.h b/libavformat/version.h
index 1d3a53875a..9d1b6ede7e 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR   8
-#define LIBAVFORMAT_VERSION_MICRO 102
+#define LIBAVFORMAT_VERSION_MICRO 103
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2026-01-06 15:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=176771326910.25.734799837863509048@4457048688e7 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@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