PR #21004 opened by caifan URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21004 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21004.patch
This change lets embedded systems reduce memory usage by adjusting pkt_size through options. The code now applies pkt_size to both read and write cases. This makes the file protocol more flexible on devices with limited RAM. Signed-off-by: caifan3 <[email protected]> >From cb04a6c7ae0b65a97f8dae06e3557acce6d48fe3 Mon Sep 17 00:00:00 2001 From: caifan3 <[email protected]> Date: Mon, 24 Nov 2025 20:59:54 +0800 Subject: [PATCH] libavformat/file: allow configurable pkt_size for lower memory usage on embedded devices This change lets embedded systems reduce memory usage by adjusting pkt_size through options. The code now applies pkt_size to both read and write cases. This makes the file protocol more flexible on devices with limited RAM. Signed-off-by: caifan3 <[email protected]> --- libavformat/file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavformat/file.c b/libavformat/file.c index 97f5955f93..429ea644d7 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 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, { NULL } }; @@ -314,8 +314,11 @@ 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 && (flags & AVIO_FLAG_WRITE)) + h->min_packet_size = h->max_packet_size = c->pkt_size ? c->pkt_size : 262144; + + if (!h->is_streamed && (flags & AVIO_FLAG_READ)) + h->min_packet_size = h->max_packet_size = c->pkt_size ? c->pkt_size : 32768; if (c->seekable >= 0) h->is_streamed = !c->seekable; -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
