diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-10-26 22:09:26 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-10-26 22:18:01 +0200 |
commit | 3a56169fec207a75d9b48b471c8fd1b8bb0a05cb (patch) | |
tree | de6b29563c2f78a9ce73747963bce910cccb69e8 | |
parent | 4416931fc069332e267ab6df037a1227c051d7b1 (diff) | |
download | ffmpeg-3a56169fec207a75d9b48b471c8fd1b8bb0a05cb.tar.gz |
movenc: reserved_moov_size, which allows placing moov at the begin of the file.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/movenc.c | 20 | ||||
-rw-r--r-- | libavformat/movenc.h | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 1d5a96e51a..efa0b92cad 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 610683fa6a..1aa23fa1a9 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 |