From: John Stebbins <[email protected]>
Adds "moov_size" option to reserve space for moov at the front of the
file.
Author: Michael Neidermayer
commit: 3a56169f
---
libavformat/movenc.c | 22 ++++++++++++++++++++--
libavformat/movenc.h | 3 +++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 12dce84..82590ad 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -51,6 +51,7 @@ static const AVOption options[] = {
{ "separate_moof", "Write separate moof/mdat atoms for each track", 0,
AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
{ "frag_custom", "Flush fragments on caller requests", 0,
AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
{ "isml", "Create a live smooth streaming feed (for pushing to a
publishing point)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_ISML}, 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),
{ "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext,
iods_skip), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
{ "iods_audio_profile", "iods audio profile atom.",
offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.i64 = -1}, -1,
255, AV_OPT_FLAG_ENCODING_PARAM},
@@ -3156,8 +3157,13 @@ static int mov_write_header(AVFormatContext *s)
FF_MOV_FLAG_FRAGMENT;
}
- if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
+ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) {
+ 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 (t = av_dict_get(s->metadata, "creation_time", NULL, 0))
mov->time = ff_iso8601_to_unix_time(t->value);
@@ -3229,9 +3235,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 %"PRId64" 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);
+ }
} else {
mov_flush_fragment(s);
mov_write_mfra_tag(pb, mov);
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index d15d69c..cf883f6 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -156,6 +156,9 @@ typedef struct MOVMuxContext {
int max_fragment_size;
int ism_lookahead;
AVIOContext *mdat_buf;
+
+ int reserved_moov_size;
+ int64_t reserved_moov_pos;
} MOVMuxContext;
#define FF_MOV_FLAG_RTP_HINT 1
--
1.8.3.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel