[FFmpeg-devel] [PATCH] avformat/matroskaenc: add reserve free space option

Sigríður Regína Sigurþórsdóttir siggaregina at gmail.com
Wed Sep 5 23:52:41 EEST 2018


---
 Changelog                 | 1 +
 doc/muxers.texi           | 4 ++++
 libavformat/matroskaenc.c | 8 ++++++++
 3 files changed, 13 insertions(+)

diff --git a/Changelog b/Changelog
index 0975fee..689b04c 100644
--- a/Changelog
+++ b/Changelog
@@ -21,6 +21,7 @@ version <next>:
 - Brooktree ProSumer video decoder
 - MatchWare Screen Capture Codec decoder
 - WinCam Motion Video decoder
+- Matroska muxer has optional free space for unspecified use at the
beginning of the file.


 version 4.0:
diff --git a/doc/muxers.texi b/doc/muxers.texi
index f18543e..72da90e 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1213,6 +1213,10 @@ ffmpeg -i sample_left_right_clip.mpg -an -c:v
libvpx -metadata stereo_mode=left_
 This muxer supports the following options:

 @table @option
+
+ at item reserve_free_space
+Reserve the specified amount of bytes for unspecified purpose within
the file header.
+
 @item reserve_index_space
 By default, this muxer writes the index for seeking (called cues in Matroska
 terms) at the end of the file, because it cannot know in advance how much space
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 09a62e1..2eb65f8 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -144,6 +144,7 @@ typedef struct MatroskaMuxContext {
     int have_attachments;
     int have_video;

+    int reserve_free_space;
     int reserve_cues_space;
     int cluster_size_limit;
     int64_t cues_pos;
@@ -2005,6 +2006,12 @@ static int mkv_write_header(AVFormatContext *s)
         ret = AVERROR(ENOMEM);
         goto fail;
     }
+    if (mkv->reserve_free_space) {
+        if (mkv->reserve_free_space == 1)
+            mkv->reserve_free_space++;
+        put_ebml_void(pb, mkv->reserve_free_space);
+    }
+
     if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && mkv->reserve_cues_space) {
         mkv->cues_pos = avio_tell(pb);
         if (mkv->reserve_cues_space == 1)
@@ -2767,6 +2774,7 @@ static const AVCodecTag additional_subtitle_tags[] = {
 #define OFFSET(x) offsetof(MatroskaMuxContext, x)
 #define FLAGS AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
+    {"reserve_free_space", "Reserve a given amount of space at the
beginning og the file for unspecified purpose.",
OFFSET(reserve_free_space), AV_OPT_TYPE_INT,   { .i64 = 0 },   0,
INT_MAX,   FLAGS },
     { "reserve_index_space", "Reserve a given amount of space (in
bytes) at the beginning of the file for the index (cues).",
OFFSET(reserve_cues_space), AV_OPT_TYPE_INT,   { .i64 = 0 },   0,
INT_MAX,   FLAGS },
     { "cluster_size_limit",  "Store at most the provided amount of
bytes in a cluster. ",
OFFSET(cluster_size_limit), AV_OPT_TYPE_INT  , { .i64 = -1 }, -1,
INT_MAX,   FLAGS },
     { "cluster_time_limit",  "Store at most the provided number of
milliseconds in a cluster.",
OFFSET(cluster_time_limit), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1,
INT64_MAX, FLAGS },
-- 
2.6.2


More information about the ffmpeg-devel mailing list