diff mbox

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

Message ID CAPgnUfCmx-=6zEaxM3a8GUEp9x2RH3+q3tnrsOuko1VNgw=3dA@mail.gmail.com
State Superseded
Headers show

Commit Message

Sigríður Regína Sigurþórsdóttir Sept. 5, 2018, 8:52 p.m. UTC
---
 Changelog                 | 1 +
 doc/muxers.texi           | 4 ++++
 libavformat/matroskaenc.c | 8 ++++++++
 3 files changed, 13 insertions(+)

     { "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 },

Comments

Carl Eugen Hoyos Sept. 5, 2018, 9:36 p.m. UTC | #1
2018-09-05 22:52 GMT+02:00, Sigríður Regína Sigurþórsdóttir
<siggaregina@gmail.com>:
> ---
>  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.

No need for a Changelog entry.

In which situation is the new option useful?

Carl Eugen
James Almer Sept. 5, 2018, 10:05 p.m. UTC | #2
On 9/5/2018 6:36 PM, Carl Eugen Hoyos wrote:
> 2018-09-05 22:52 GMT+02:00, Sigríður Regína Sigurþórsdóttir
> <siggaregina@gmail.com>:
>> ---
>>  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.
> 
> No need for a Changelog entry.
> 
> In which situation is the new option useful?

Adding a bunch of reserved filler bytes is something done by a lot of
writing applications and meant to be used mainly by retagging
applications to add or replace tags in place without the risk of having
to rewrite the entire file. Hence it being added right after the Tags
element.

Mkvtoolnix adds a big Void element for this purpose by default, for
example. But for libavformat I'd rather have this be optional.


> 
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
James Darnley Sept. 5, 2018, 10:23 p.m. UTC | #3
On 2018-09-05 22:52, Sigríður Regína Sigurþórsdóttir wrote:
> +    {"reserve_free_space", "Reserve a given amount of space at the
> beginning og the file for unspecified purpose."

I added the "metadata_header_padding" global option many years ago.  Can
you not reuse it for this purpose?  Is it not likely to be "metadata"
that another software might fill this with?

Also there is a typo in the bit I quoted.
diff mbox

Patch

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
+
+@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 },