PR #25393 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25393
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25393.patch

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 <[email protected]>


>From 602af1416a8f11dbd142e5561dc9d46fad0fc654 Mon Sep 17 00:00:00 2001
From: Niklas Haas <[email protected]>
Date: Fri, 23 Oct 2026 18:21:12 +0200
Subject: [PATCH] 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 <[email protected]>
---
 doc/protocols.texi   | 5 +++++
 libavformat/shared.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index aaee2292e9d..4544ed3d3f0 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 f6406da791a..38a64412a7d 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},
 };
 
-- 
2.54.0

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

Reply via email to