Maximum size of a MOV chunk should be taken from the configurable
max_chunk_size option in AVFormatContext. If it is not defined revert to
the previously set limit of 1mb.

This patch was made in order to control the size of chunks in a MOV format
writer. I noticed that there was already an option on the AVFormatContext
that was configurable through a setting and figured it was a small fix to
actually get this value when determining chunk sizes.

Would have preferred to be able to set it per Track/Stream but could not
figure out how to get settings on a specific stream and get access to them
from the MOV track so this will do for now.

Regards,
Sander
From e7ffe48e8e23652931ee3bac3fcc25b9d480a0e4 Mon Sep 17 00:00:00 2001
From: Sander Cox <sander@resolume.com>
Date: Fri, 9 Jul 2021 13:40:22 +0200
Subject: [PATCH] max_chunk_size from format context in build_chunks

Maximum size of a MOV chunk should be taken from the configurable
max_chunk_size option in AVFormatContext. If it is not defined revert to
the previously set limit of 1mb.
---
 libavformat/movenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 8fdce359db..138354c232 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4044,18 +4044,19 @@ static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s)
     return 0;
 }
 
-static void build_chunks(MOVTrack *trk)
+static void build_chunks(AVFormatContext* s, MOVTrack *trk)
 {
     int i;
     MOVIentry *chunk = &trk->cluster[0];
     uint64_t chunkSize = chunk->size;
+    int maxChunkSize = (s->max_chunk_size > 0) ? s->max_chunk_size : (1<<20);
     chunk->chunkNum = 1;
     if (trk->chunkCount)
         return;
     trk->chunkCount = 1;
     for (i = 1; i<trk->entry; i++){
         if (chunk->pos + chunkSize == trk->cluster[i].pos &&
-            chunkSize + trk->cluster[i].size < (1<<20)){
+            chunkSize + trk->cluster[i].size < maxChunkSize){
             chunkSize             += trk->cluster[i].size;
             chunk->samples_in_chunk += trk->cluster[i].entries;
         } else {
@@ -4130,7 +4131,7 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov,
         mov->tracks[i].time     = mov->time;
 
         if (mov->tracks[i].entry)
-            build_chunks(&mov->tracks[i]);
+            build_chunks(s, &mov->tracks[i]);
     }
 
     if (mov->chapter_track)
-- 
2.32.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to