[FFmpeg-cvslog] movenc: support spliting fragments based on bytesize instead of duration.

Michael Niedermayer git at videolan.org
Tue Dec 6 16:47:57 CET 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Tue Dec  6 16:21:10 2011 +0100| [15130b94fc8290ce1427221e3f1101529b44ef0d] | committer: Michael Niedermayer

movenc: support spliting fragments based on bytesize instead of duration.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=15130b94fc8290ce1427221e3f1101529b44ef0d
---

 libavformat/movenc.c |    8 ++++++--
 libavformat/movenc.h |    1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index dcf5af7..80c45a5 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -45,6 +45,7 @@ static const AVOption options[] = {
     { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     { "rtphint", "Add RTP hint tracks", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+    { "frag_size", "maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
     { "frag_duration", "maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
     FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
     { NULL },
@@ -2182,6 +2183,7 @@ static int flush_cluster_buffer(AVFormatContext *s){
         }
         updateSize(s->pb, mov->mdat_pos);
     }
+    mov->mdat_size = 0;
     for (i=0; i<mov->nb_streams; i++) {
         MOVTrack *track= &mov->tracks[i];
         track->cluster_write_index= track->entry;
@@ -2205,7 +2207,9 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (!size) return 0; /* Discard 0 sized packets */
 
     if (mov->fragments && trk->entry > trk->cluster_write_index &&
-        av_rescale_q(pkt->dts - trk->cluster[ trk->cluster_write_index ].dts, st->time_base, AV_TIME_BASE_Q) >= mov->max_fragment_duration){
+        (   mov->max_fragment_duration && av_rescale_q(pkt->dts - trk->cluster[ trk->cluster_write_index ].dts, st->time_base, AV_TIME_BASE_Q) >= mov->max_fragment_duration
+         || mov->max_fragment_size     && mov->mdat_size + size >= mov->max_fragment_size)
+        ){
         flush_cluster_buffer(s);
     }
 
@@ -2369,7 +2373,7 @@ static int mov_write_header(AVFormatContext *s)
     /* Default mode == MP4 */
     mov->mode = MODE_MP4;
 
-    if(mov->max_fragment_duration){
+    if(mov->max_fragment_duration || mov->max_fragment_size){
         mov->fragments= 1;
     }
 
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 95b8bcd..e0ed6e6 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -122,6 +122,7 @@ typedef struct MOVMuxContext {
     int reserved_moov_size;
     int64_t reserved_moov_pos;
     int max_fragment_duration;
+    int max_fragment_size;
 } MOVMuxContext;
 
 #define FF_MOV_FLAG_RTP_HINT 1



More information about the ffmpeg-cvslog mailing list