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

Git pushed a commit to branch master
in repository ffmpeg.

The following commit(s) were added to refs/heads/master by this push:
     new 82144fea48 libavformat/file: apply pkt_size option to read mode
82144fea48 is described below

commit 82144fea488387539d7008bef5cdbf52ccbc6113
Author:     caifan3 <[email protected]>
AuthorDate: Mon Dec 22 14:32:00 2025 +0800
Commit:     Marton Balint <[email protected]>
CommitDate: Tue Dec 30 00:49:13 2025 +0000

    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 <[email protected]>
---
 doc/protocols.texi |  9 +++++++++
 libavformat/file.c | 10 +++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index dee2b845ac..b5330a1160 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -352,6 +352,15 @@ means auto (seekable for normal files, non-seekable for 
named pipes).
 Many demuxers handle seekable and non-seekable resources differently,
 overriding this might speed up opening certain files at the cost of losing some
 features (e.g. accurate seeking).
+
+@item pkt_size
+Set the maximum packet size used for file I/O.
+
+For writing, this sets the size of each write operation. The default is
+262144 bytes.
+For reading, if explicitly set, it overrides the default internal buffer size
+(32768 bytes) and limits the maximum amount of data read per operation.
+Setting a smaller value may reduce memory usage when reading files 
sequentially.
 @end table
 
 @section ftp
diff --git a/libavformat/file.c b/libavformat/file.c
index 97f5955f93..23dc7081d3 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -107,7 +107,7 @@ static const AVOption file_options[] = {
     { "blocksize", "set I/O operation maximum block size", 
offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { "follow", "Follow a file as it is being written", offsetof(FileContext, 
follow), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
     { "seekable", "Sets if the file is seekable", offsetof(FileContext, 
seekable), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 0, AV_OPT_FLAG_DECODING_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM },
-    { "pkt_size", "Maximum packet size", offsetof(FileContext, pkt_size), 
AV_OPT_TYPE_INT, { .i64 = 262144 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM },
+    { "pkt_size", "Maximum packet size", offsetof(FileContext, pkt_size), 
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | 
AV_OPT_FLAG_ENCODING_PARAM },
     { NULL }
 };
 
@@ -314,8 +314,12 @@ static int file_open(URLContext *h, const char *filename, 
int flags)
 
     /* Buffer writes more than the default 32k to improve throughput especially
      * with networked file systems */
-    if (!h->is_streamed && flags & AVIO_FLAG_WRITE)
-        h->min_packet_size = h->max_packet_size = c->pkt_size;
+    if (!h->is_streamed) {
+        if (flags & AVIO_FLAG_WRITE)
+            h->min_packet_size = h->max_packet_size = c->pkt_size ? 
c->pkt_size : 262144;
+        else if (flags & AVIO_FLAG_READ && c->pkt_size)
+            h->max_packet_size = c->pkt_size;
+    }
 
     if (c->seekable >= 0)
         h->is_streamed = !c->seekable;

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

Reply via email to