293 Commits
Author SHA1 Message Date
Niklas Haas 935f29eaae avformat/shared: rename -read_only to -cache_read_only
And add a deprecated alias for backwards compatibility.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-10-23 10:26:32 +00:00
Michael Niedermayer 2e93d7c381 doc/protocols: State that the shared cache key ignores request options
Documenting this was suggested in the report.

Documentation for oSnACc1DZtVF (AISLE-2026-0111-00167)
Found-by: Joshua Rogers <joshua.rogers@aisle.com>
2026-10-20 21:30:18 +00:00
Michael Niedermayer 9eb8831b73 doc/protocols: State that the shared cache directories must be trusted
Documenting that the directories must not be writable by untrusted users
was suggested in the report.

Documentation for umsIH5gcyBXl (AISLE-2026-0111-00168)
Found-by: Joshua Rogers <joshua.rogers@aisle.com>
2026-10-20 21:30:18 +00:00
Michael Niedermayer de6fb646f7 avformat/http: send cookies given without a Domain only to their host
Fixes: cookie disclosure to other hosts
Fixes: u2ys08MO8oEF
Cookie disclosure Replicated through UnModified FFmpeg

Found-by: Yazan Balawneh, Cystack.ps
2026-10-20 02:19:24 +00:00
Zhao Zhili 34370c0ffd avformat/udp: use the circular buffer whenever threads are available
The rx and tx threads no longer use pthread_cancel(), so gate the
circular buffer on HAVE_THREADS instead of HAVE_PTHREAD_CANCEL. This
also drops the w32threads override.

On targets that have threads but no pthread_cancel(), such as Android,
udp inputs now start a receive thread and allocate the default 7*4096
by 188 byte fifo, as on other platforms. Set fifo_size=0 to get the
previous behavior.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2026-10-17 04:24:54 +00:00
Andreas Menze faab9c8e56 avformat/http: keep complete size for Content-Range "bytes A-B/*"
"bytes A-B/*" means the complete length is unknown (RFC 9110 14.4), so
don't read it as a size of 0, and never derive the complete size from a
partial reply. Remember it once learned from a 200 Content-Length or a
"bytes A-B/N" total and reuse it for later "*" replies. If the complete
size was never learned, or the total is not a number, it stays unknown.
A 416 to a read or a seek past the end of a resource of unknown size
ends it with EOF and gives its complete length ("bytes */N"), unless it
states a length past the requested offset. That 416 is retried first
only if reconnect_on_http_error lists 416 by number, reconnect_at_eof
does not retry the end it marks, and an open past the end is retried as
configured. Keep the file size and the complete size when a request
fails. A seek that fails or is refused keeps the offset and the end of
the resource, and when reading goes on over the old connection, also
the range end, chunk state, connection mode and compression of the old
reply. A seek to the current offset makes a new request when there is
no connection.

Fixes #24210

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-10-12 22:42:25 +02:00
Felipe Araújo 1ae485ba98 avformat/file: add Windows handle protocol
Like the fd protocol, but takes a raw Windows HANDLE instead of a CRT file descriptor.
On Windows, CRT file descriptors cannot be reliably passed to child processes, so
HANDLEs need to be used instead.

Signed-off-by: Felipe Araújo <felipdsa21@outlook.com>
2026-10-11 23:10:44 +00:00
Niklas Haas 7d92f8e34e avformat/shared: add -metadata_dir option
This allows storing metadata in a separate directory, e.g. on a faster
drive, a tmpfs, or in a volume without quota limits.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-10-02 12:35:39 +00:00
Romain Beauxis f942d9ea92 doc/protocols: document the libcurl ICY options
Also note where the libcurl protocol differs from the native one once in-band
metadata is active.
2026-09-25 16:04:08 +00:00
Niklas Haas 30afbfcf6f avformat/shared: add -cache_size_max option
This allows users to limit the amount of cached data. Note that this is
*not* a limit on the size of the file cached. For example, a 10 GB file can
work with a 1 GB cache size limit if the user only ever plays some parts of
the file (e.g. 1 minute from a 100 minute stream).

After this point, s->read_only is simply turned on, giving us the expected
fallback behavior for uncached blocks.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-09-15 10:04:36 +00:00
Niklas Haas ac72d79059 avformat/shared: add -ignore_errors option
This allows the shared: cache protocol to ignore errors in the underlying
URL (e.g. HTTP server went down) and continue serving the cached data
purely from the cache file. I'm not sure what a good name would be here,
since -ignore_errors overlaps somewhat with -retry_errors, but I think the
distinction is clear enough. (-ignore_errors keeps going after the inner
protocol fails, -retry_errors will retry blocks that previously failed in
the inner protocol)

One slight change is that we now call ffurl_size() on ourself during
init. This is safe, because the spacamap is already initialized by this
point in time, and it also embeds the correct error handling and spacemap
update logic.

Default off because it's a possibly surprising change in behavior.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-09-15 10:04:36 +00:00
Joshua Rogers 2b822b7fb6 avformat/libssh: verify the SSH server host key
The sftp protocol connected and authenticated without checking the server
host key, so credentials were sent to any or spoofed server. Verify against
known_hosts (ssh_session_is_known_server, with a pre-0.8 fallback) before
authenticating; add a 'verify' option (default on) to opt out.

Strict checking is forced on for the check: libssh otherwise reports an
unknown server, and since 0.8 even a changed key, as known when the parsed
ssh config says StrictHostKeyChecking no.

This changes the default behaviour: like OpenSSH with
StrictHostKeyChecking=yes, sftp:// now refuses servers that are not in the
known_hosts file or whose key differs from the recorded one.

Fixes: credentials sent to unverified SSH servers (CWE-295)
Fixes: ZmW0mOvhU0qN
Found-by: Joshua Rogers <joshua.rogers@aisle.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2026-09-12 20:29:19 +00:00
Niklas Haas 7ee873656c avformat/libcurl: implement -short_seek_size
Since libcurl.c doesn't have to care about the exact number of bytes read,
we just perform the seek but defer the actual `start_request()` call until
the next on_done() callback, while simply discarding all data read in the
meantime.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-09-04 17:37:20 +00:00
Niklas Haas 75cf575257 avformat/shared: hard-error on -cache_verify data mismatch
Makes this debug option way more useful. Also matches the existing behavior
on CRC mismatches.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-08-31 19:10:45 +00:00
Niklas Haas 946a450cec avformat/libcurl: implement -initial_request_size
See corresponding feature in http.c.

Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-27 17:05:20 +00:00
Kacper Michajłow 7346f917e4 avformat: add prefer_libcurl option to route http(s) via libcurl
Register a prefer_libcurl IO option that, when set, opens http(s) URLs
with the libcurl protocol instead of the native one. The native http
protocol stays the default.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Kacper Michajłow d0972a725d avformat/libcurl: add options, TLS, proxy, cookies and headers
Add the AVOption table and map it onto libcurl. Verbose curl output is
routed to av_log at debug level. This mirrors subset of http.c options.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2026-07-27 17:05:20 +00:00
Niklas Haas aa8fc9f946 avformat/shared: add -retry_corrupt option
Similar to -retry_errors, this retries blocks whose only crime is failing
the CRC self-check.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-07-02 14:29:42 +00:00
Niklas Haas ee2bc31032 avformat/http: imply keep-alive by default when beneficial
By turning it into a tristate that defaults to -1 (auto). Users can still
force a particular value for debugging.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-28 12:47:40 +02:00
Andreas Rheinhardt 9549c9ad79 avformat/tls: Remove FF_API_NO_DEFAULT_TLS_VERIFY
The decision to switch to checking peer certificates by default
at the next major version bump was announced on 2025-08-09
in commit 5621eee672.

Thanks to Michael Niedermayer for pointing out that the documentation
needs to be updated, too.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2026-06-23 17:15:02 +02:00
Niklas Haas c97a2328c0 avformat/shared: set default cache timeout to 10 ms
This value is matched to the typical seek latency in a reasonably capable
7200 rpm disk device, as well as the typical latency of an on-premise HTTP
request.

Note that this change should rarely have a significant effect, because
it only matters when using multiple concurrent processes, and one process
is somehow stuck in I/O (or died). Since we sleep in a loop for 1/16th of
the requested timeout value, this should only increase the effective read
latency by up to ~500 us on top of the actual underlying latency.

The alternative is hammering the same underlying resource with the exact
same requests at the exact same time (e.g. during init).

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-14 11:10:12 +02:00
Niklas Haas afce637550 avformat/shared: add option to verify cache file contents
This will effectively disable the cache but allows the cache layer to verify
cached files against the original input file. Useful only for debugging
the shared cache protocol itself, as file corruption can already be caught by
the CRC check.
2026-06-04 17:48:12 +02:00
Niklas Haas 56de70a2e6 avformat: add shared concurrent block cache protocol
This adds a new protocol shared:URI which is distinct from the existing
`cache:` in that it is explicity designed to be thread-safe and cross-process,
enabling multiple ffmpeg processes (or multiple ffmpeg decoders within the same
process) to share a single cache file, for e.g. a remote HTTP stream. As such,
it uses a radically different internal design.

To facilitate zero-knowledge cross-process interoperability, the cache file
itself is just a memory-mapped representation of the underlying file data,
which has the side benefit that the resulting cache file will contain a
working copy of the streamed file (assuming the stream was read to
completion).

To keep track of which regions are cached and which are not, we use a
secondary file that contains a minimal header along with a static bytemap of
blocks within the file. This secondary file is also used to store metadata
such as the filesize, if known, as well as marking "failed" blocks.

Both files can grow dynamically in order to accommodate larger/growing files,
and can be atomically updated (through the use of shared space maps). I have
extensively checked the space map initalization and update code for race
conditions, and I believe the current design to be solid.

That said, it is the user's responsibility to some extent to ensure that the
same URI is not used for different streams, as we rely on the URI to uniquely
identify the cache files. That said, we use a cryptographic hash with
sufficient collision resistance to protect against possible abuse. The lack of
any implicit default on `-cache_dir` also means that `shared:` can't be enabled
via URL injection to possibly access random files on the disk (or intentionally
leak content from other streams with similar URIs, even if the cryptograhic
hash function is broken).
2026-06-04 17:48:12 +02:00
Niklas Haas cd3f335207 avformat/file: return ENOSYS for filesize query on files with follow=1
If the input is expected to grow, we shouldn't make any assumptions about
the file size. This matches e.g. the behavior of streamed protocols like
chunked HTTP, which similarly return ENOSYS for streams of unknown size.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
2026-06-04 17:48:12 +02:00
RossWang bce8d61d12 avformat/libsrt: fix ipv6 wildcard listener
For now it fails on srt://[::]:1234?mode=listener

This modification makes it accept a new option "ipv6only"

Reference:
https://github.com/Haivision/srt/pull/2608
https://github.com/Haivision/srt/blob/master/docs/API/API-socket-options.md#SRTO_IPV6ONLY

fix #10539
2026-05-23 10:03:33 -05:00
Niklas Haas 2e7078cda6 avformat/http: add -request-size option
It has come to my attention that a way to limit the request range size
would be useful in general, for reasons beyond just speeding up initial
header parsing.

This patch generalizez -initial_request_size to -request_size. I decided
to continue allowing both options to be used simultaneously, so users can
e.g. set -request_size to something large like 10 MiB, but still use a smaller
size for initial header parsing (e.g. 256 KiB).

Fixes: https://github.com/mpv-player/mpv/issues/8655
2026-02-27 09:20:33 +00:00
Marvin Scholz 64fafd63f0 avformat: remove HLS protocol
The use of this protocol was already discouraged and warned about
for years with the recommendation to use the HLS demuxer instead.
2026-02-23 20:20:20 +01:00
Rost Kurylo d07d2a4ee1 doc/protocols: Document type option for unix domain sockets
Signed-off-by: Rost Kurylo <rost.kurylo@netint.ca>
2026-02-11 20:41:49 +00:00
Niklas Haas 4f5d91e43f avformat/http: allow limiting initial request size
Sometimes, HTTP sources require a lot of seeking during probing / header
parsing (especially for formats like MXF). Currently, we need to completely
tear down and re-establish the connection most times this happens, which puts
a lot of stress on the network stack and also results in transmission of
possibly many unnecessary bytes.

This patch adds an option to allow FFmpeg to request partial ranges during
the initialization stage. This is done until the initial request size is fully
read, after which we fall back to the normal behavior (i.e. infinite streaming
via an unbounded request).

The usefulness of this is limited without also specifying -multiple_requests 1,
since otherwise there is little point to requesting partial ranges to begin
with. (However, it is semantically independent, so we keep it that way.)
2026-02-07 10:02:36 +00:00
Marton Balint 8579037b6c avformat/file: respect pkt_size even in streaming mode
Also clarify the documentation a bit.

Signed-off-by: Marton Balint <cus@passwd.hu>
2026-01-01 18:20:58 +00:00
caifan3 82144fea48 libavformat/file: apply pkt_size option to read mode
Previously, the pkt_size option only affected write buffering in the file
protocol. This change extends its effect to read mode as well.

On embedded systems with limited RAM, users can now reduce I/O buffer
memory by setting a smaller pkt_size.

Signed-off-by: caifan3 <caifan3@xiaomi.com>
2025-12-30 00:49:13 +00:00
caifan3 40d7f7774a avformat/unix: add pkt_size option
Add a "pkt_size" AVOption to the Unix domain socket protocol. This option
allows the user to specify the maximum packet size for packet-oriented
sockets (SOCK_DGRAM and SOCK_SEQPACKET).

Signed-off-by: caifan3 <caifan3@xiaomi.com>
2025-12-07 19:36:03 +00:00
Marton Balint 8e11e2cdb8 avformat/tls_openssl: initialize underlying protocol early for dtls_start()
The same way we do with TLS, so all tls URL options will be properly supported.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint 2762ae74c5 avformat/tls: use ff_parse_opts_from_query_string() to set URL parameters
Note that this changes the code to work the same way as other protocols where
an URL parameter can override an AVOption.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint 3166e3b539 avformat/rtpproto: use ff_parse_opts_from_query_string() to set URL parameters
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint f231439ee7 avformat/sctp: use ff_parse_opts_from_query_string() to set URL parameters
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint 49c6e6cc44 avformat/tcp: use ff_parse_opts_from_query_string() to set URL parameters
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint 7e58fff9d0 avformat/udp: use ff_parse_opts_from_query_string() to set URL parameters
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint 2d06ed9308 avformat/libsrt: use ff_parse_opts_from_query_string() to set URL parameters
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-10-01 00:34:19 +02:00
Marton Balint 3a29702cb6 avformat/rtpproto: add some URL options as AVOption aliases
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-09-19 09:59:26 +02:00
Marton Balint 7d1e22b7ea avformat/tls: add some URL options as AVOption aliases
Signed-off-by: Marton Balint <cus@passwd.hu>
2025-09-19 09:59:26 +02:00
Marton Balint 3e7314fe30 avformat/udp: add DSCP as a normal AVOption
Previously this was an URL-only option.

Signed-off-by: Marton Balint <cus@passwd.hu>
2025-09-19 09:59:26 +02:00
iddq 4e9a184d5c avformat/tcp: add option for enabling TCP keepalive 2025-08-22 18:20:08 +00:00
Jack Lau 037fc47f35 doc/protocols: add doc for dtls
Signed-off-by: Jack Lau <jacklau1222@qq.com>
2025-08-09 23:18:57 +02:00
Timo Rothenpieler 262d41c804 all: fix typos found by codespell 2025-08-03 13:48:47 +02:00
Stefan Pöschel 2ac2ebcd76 doc/protocols: fix/improve RTP documentation
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2025-01-17 23:33:26 +01:00
Derek Buitenhuis 2d5fa816fb avformat/http: Add support for Retry-After header
429 and 503 codes can, and often do (e.g. all Google Cloud
Storage URLs can), return a Retry-After header with the error,
indicating how long to wait, asd either a date, or in seconds,
before retrying again. If it is not respected by, for example,
using our default backoff stratetgy instead, chances of success
are very unlikely.

Some references:
    * https://datatracker.ietf.org/doc/html/rfc6585
    * https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.3

This adds an AVOption to respect that header.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2024-04-25 15:21:25 +01:00
Derek Buitenhuis 1f8e5b6d95 doc/protocols: Fill in missing HTTP options
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2024-04-25 14:21:25 +01:00
Derek Buitenhuis 5d568b16a0 doc/protocols: Re-order HTTP options to match http.c order
This makes the list easier to maintain.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2024-04-25 14:20:28 +01:00
Steven Liu 637c761be1 avformat/rtmpproto: support enhanced rtmp
add option named rtmp_enhanced_codec,
it would support hvc1,av01,vp09 now,
the fourcc is using Array of strings.

Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
2023-09-05 09:14:18 +08:00