Commit c49ccf40ca for ffmpeg
commit c49ccf40ca429d2d0ec1cc36c792f56e82711f87
Author: Niklas Haas <git@haasn.dev>
Date: Fri Oct 23 18:21:12 2026 +0200
avformat/shared: add an offset option
This additionally fixes a prior silent corruption when a parent `offset`
option was implicitly passed down to the inner protocol, resulting in a
stream that did not start at 0, yet the inner protocol offset tracking
did not account for this.
By just always handling this option ourselves, we avoid this class of
problem.
Fixes: https://github.com/nxtedition/FFmpeg/issues/80
See-Also: https://github.com/nxtedition/casparcg/pull/103
Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
diff --git a/doc/protocols.texi b/doc/protocols.texi
index aaee2292e9..4544ed3d3f 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -1858,6 +1858,11 @@ blocks, where N is the number of concurrent processes using the same cache
file. Note also that the underlying file system may reserve more space than
written, if the underlying allocation granularity is larger than the block
size.
+
+@item offset
+Initial byte offset to start reading from. This option is not passed on to the
+underlying protocol; it instead gets a regular seek on the first cache miss.
+Defaults to 0.
@end table
URL Syntax is
diff --git a/libavformat/shared.c b/libavformat/shared.c
index f6406da791..38a64412a7 100644
--- a/libavformat/shared.c
+++ b/libavformat/shared.c
@@ -174,6 +174,7 @@ typedef struct SharedContext {
int retry_corrupt;
int verify;
int64_t cache_size_max;
+ int64_t offset;
/* misc state */
int64_t pos; ///< current logical position
@@ -364,6 +365,7 @@ static int shared_open(URLContext *h, const char *arg, int flags, AVDictionary *
h->max_packet_size = s->block_size;
h->min_packet_size = s->block_size;
+ s->pos = s->offset;
ret = 0;
fail:
@@ -949,6 +951,7 @@ static const AVOption options[] = {
{ "retry_errors", "Re-request blocks even if they previously failed", OFFSET(retry_errors), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, .flags = D },
{ "retry_corrupt", "Re-request blocks that fail the CRC check", OFFSET(retry_corrupt), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, .flags = D },
{ "cache_size_max", "Limit the maximum amount of data cached", OFFSET(cache_size_max), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, .flags = D },
+ { "offset", "Initial byte offset", OFFSET(offset), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, .flags = D },
{0},
};