This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 7346f917e4219888ffdefc80cc5b5803b4d939a3
Author:     Kacper Michajłow <[email protected]>
AuthorDate: Mon Jun 15 03:44:00 2026 +0200
Commit:     Kacper Michajłow <[email protected]>
CommitDate: Mon Jul 27 17:05:20 2026 +0000

    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 <[email protected]>
---
 doc/protocols.texi | 21 +++++++++++++++++++--
 libavformat/avio.c | 35 ++++++++++++++++++++++++++++++++++-
 libavformat/url.h  |  1 +
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index fb0f19c8b4..96c84499f7 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1069,10 +1069,27 @@ It runs transfers on a dedicated event-loop thread 
shared per
 @code{AVFormatContext}, so all of a demuxer's connections (for example HLS
 segments) reuse libcurl's connection cache and HTTP/2 and HTTP/3 multiplexing.
 
-The native @code{http} protocol stays the default; to use libcurl explicitly,
-prefix the URL with @code{libcurl:}, for example
+The native @code{http} protocol stays the default. There are two ways to use
+libcurl instead:
+
+@itemize @bullet
+@item
+Prefix the URL with @code{libcurl:} to force it explicitly, for example
 @code{libcurl:https://example.com/video.mp4}.
 
+@item
+Set the @option{prefer_libcurl} option to route @code{http://} and
+@code{https://} URLs through libcurl transparently.
+@end itemize
+
+@table @option
+@item prefer_libcurl
+When set to @code{1}, open @code{http(s)} URLs with the libcurl protocol 
instead
+of the native one. This is a generic IO option rather than a libcurl-specific
+one, so it also applies on builds without libcurl (where it has no effect).
+Default is @code{0}.
+@end table
+
 The libcurl protocol accepts the following options.
 
 @table @option
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 88bc9557de..ccc98bab67 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -19,6 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config_components.h"
+
+#include <stdlib.h>
+
 #include "libavutil/avstring.h"
 #include "libavutil/dict.h"
 #include "libavutil/mem.h"
@@ -61,6 +65,7 @@ static const AVOption urlcontext_options[] = {
     {"protocol_whitelist", "List of protocols that are allowed to be used", 
OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
     {"protocol_blacklist", "List of protocols that are not allowed to be 
used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, 
D },
     {"rw_timeout", "Timeout for IO operations (in microseconds)", 
offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 
INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
+    {"prefer_libcurl", "use the libcurl protocol for http(s) URLs when 
available", OFFSET(prefer_libcurl), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D },
     { NULL }
 };
 
@@ -365,6 +370,24 @@ int ffurl_alloc(URLContext **puc, const char *filename, 
int flags,
     return AVERROR_PROTOCOL_NOT_FOUND;
 }
 
+#if CONFIG_LIBCURL_PROTOCOL
+extern const URLProtocol ff_libcurl_protocol;
+
+/* Decide whether an http(s) URL should be routed to the libcurl protocol 
instead
+ * of the native one. Controlled by the per-open "prefer_libcurl" option. */
+static int prefer_libcurl(const char *filename, AVDictionary **options)
+{
+    AVDictionaryEntry *e;
+
+    if (!options || !(e = av_dict_get(*options, "prefer_libcurl", NULL, 0)) ||
+        !atoi(e->value))
+        return 0;
+
+    return av_strstart(filename, "http://";,  NULL) ||
+           av_strstart(filename, "https://";, NULL);
+}
+#endif
+
 static int url_open_whitelist(URLContext **puc, const char *filename, int 
flags,
                               const AVIOInterruptCB *int_cb, AVDictionary 
**options,
                               const char *whitelist, const char* blacklist,
@@ -372,7 +395,17 @@ static int url_open_whitelist(URLContext **puc, const char 
*filename, int flags,
 {
     AVDictionary *tmp_opts = NULL;
     AVDictionaryEntry *e;
-    int ret = ffurl_alloc(puc, filename, flags, int_cb);
+    int ret;
+
+#if CONFIG_LIBCURL_PROTOCOL
+    /* The option itself is applied to the URLContext further down; here it 
only
+     * picks the protocol, before the context exists. */
+    if (prefer_libcurl(filename, options))
+        ret = url_alloc_for_protocol(puc, &ff_libcurl_protocol, filename, 
flags,
+                                     int_cb);
+    else
+#endif
+        ret = ffurl_alloc(puc, filename, flags, int_cb);
     if (ret < 0)
         return ret;
     (*puc)->avfc = avfc;
diff --git a/libavformat/url.h b/libavformat/url.h
index eba7a39cca..2c6371e039 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -47,6 +47,7 @@ typedef struct URLContext {
     const char *protocol_blacklist;
     int min_packet_size;        /**< if non zero, the stream is packetized 
with this min packet size */
     struct AVFormatContext *avfc; /**< the AVFormatContext that opened this 
URLContext, or NULL for standalone use */
+    int prefer_libcurl;         /**< route http(s) opens through the libcurl 
protocol */
 } URLContext;
 
 typedef struct URLProtocol {

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to