[FFmpeg-cvslog] movenc: reserved_moov_size, which allows placing moov at the begin of the file.

Michael Niedermayer git at videolan.org
Wed Oct 26 22:29:10 CEST 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Oct 26 22:09:26 2011 +0200| [3a56169fec207a75d9b48b471c8fd1b8bb0a05cb] | committer: Michael Niedermayer

movenc: reserved_moov_size, which allows placing moov at the begin of the file.

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

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

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

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 1d5a96e..efa0b92 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -44,6 +44,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 },
     FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
     { NULL },
 };
@@ -2274,6 +2275,11 @@ static int mov_write_header(AVFormatContext *s)
         av_set_pts_info(st, 64, 1, track->timescale);
     }
 
+    if(mov->reserved_moov_size){
+        mov->reserved_moov_pos= avio_tell(pb);
+        avio_skip(pb, mov->reserved_moov_size);
+    }
+
     mov_write_mdat_tag(pb, mov);
 
 #if FF_API_TIMESTAMP
@@ -2328,9 +2334,21 @@ static int mov_write_trailer(AVFormatContext *s)
         ffio_wfourcc(pb, "mdat");
         avio_wb64(pb, mov->mdat_size+16);
     }
-    avio_seek(pb, moov_pos, SEEK_SET);
+    avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
 
     mov_write_moov_tag(pb, mov, s);
+    if(mov->reserved_moov_size){
+        int64_t size=  mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
+        if(size < 8){
+            av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %Ld additional\n", 8-size);
+            return -1;
+        }
+        avio_wb32(pb, size);
+        ffio_wfourcc(pb, "free");
+        for(i=0; i<size; i++)
+            avio_w8(pb, 0);
+        avio_seek(pb, moov_pos, SEEK_SET);
+    }
 
     if (mov->chapter_track)
         av_freep(&mov->tracks[mov->chapter_track].enc);
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index 610683f..1aa23fa 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -112,6 +112,8 @@ typedef struct MOVMuxContext {
 
     int flags;
     int rtp_flags;
+    int reserved_moov_size;
+    int64_t reserved_moov_pos;
 } MOVMuxContext;
 
 #define FF_MOV_FLAG_RTP_HINT 1



More information about the ffmpeg-cvslog mailing list