Browse code

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

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

Michael Niedermayer authored on 2011/10/27 05:09:26
Showing 2 changed files
... ...
@@ -44,6 +44,7 @@
44 44
 static const AVOption options[] = {
45 45
     { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
46 46
     { "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" },
47
+    { "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 },
47 48
     FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
48 49
     { NULL },
49 50
 };
... ...
@@ -2274,6 +2275,11 @@ static int mov_write_header(AVFormatContext *s)
2274 2274
         av_set_pts_info(st, 64, 1, track->timescale);
2275 2275
     }
2276 2276
 
2277
+    if(mov->reserved_moov_size){
2278
+        mov->reserved_moov_pos= avio_tell(pb);
2279
+        avio_skip(pb, mov->reserved_moov_size);
2280
+    }
2281
+
2277 2282
     mov_write_mdat_tag(pb, mov);
2278 2283
 
2279 2284
 #if FF_API_TIMESTAMP
... ...
@@ -2328,9 +2334,21 @@ static int mov_write_trailer(AVFormatContext *s)
2328 2328
         ffio_wfourcc(pb, "mdat");
2329 2329
         avio_wb64(pb, mov->mdat_size+16);
2330 2330
     }
2331
-    avio_seek(pb, moov_pos, SEEK_SET);
2331
+    avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET);
2332 2332
 
2333 2333
     mov_write_moov_tag(pb, mov, s);
2334
+    if(mov->reserved_moov_size){
2335
+        int64_t size=  mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos);
2336
+        if(size < 8){
2337
+            av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %Ld additional\n", 8-size);
2338
+            return -1;
2339
+        }
2340
+        avio_wb32(pb, size);
2341
+        ffio_wfourcc(pb, "free");
2342
+        for(i=0; i<size; i++)
2343
+            avio_w8(pb, 0);
2344
+        avio_seek(pb, moov_pos, SEEK_SET);
2345
+    }
2334 2346
 
2335 2347
     if (mov->chapter_track)
2336 2348
         av_freep(&mov->tracks[mov->chapter_track].enc);
... ...
@@ -112,6 +112,8 @@ typedef struct MOVMuxContext {
112 112
 
113 113
     int flags;
114 114
     int rtp_flags;
115
+    int reserved_moov_size;
116
+    int64_t reserved_moov_pos;
115 117
 } MOVMuxContext;
116 118
 
117 119
 #define FF_MOV_FLAG_RTP_HINT 1