[FFmpeg-devel] [PATCH]Fix default stream flag value wrt matroska muxing

Carl Eugen Hoyos cehoyos at ag.or.at
Mon Jan 28 10:37:23 CET 2013


On Monday 28 January 2013 12:17:58 am Carl Eugen Hoyos wrote:
> Hi!
>
> The matroska specification describes a stream flag "FlagDefault" that
> defaults to "default".
> FFmpeg has a stream disposition AV_DISPOSITION_DEFAULT. Since disposition
> is initialized to "0", the default value for the FFmpeg flag is "not
> default". The result is that except for a corner case (forced flag set)
> whenever a matroska stream is used as input, the output stream is set as
> "default" in matroska files because either the flag was set and is written
> or it was not set, then it is not written and the matroska default value
> takes effect, see ticket #1815.
>
> Attached is a possibility to fix this problem by adding an additional flag
> to tell if the value is set or not.
> I am not convinced that always writing the matroska "FlagDefault" instead
> is a better solution because it would suddenly make nearly all streams in
> matroska files written by lavf "non-default".

Alternative, simpler patch attached that makes AV_DISPOSITION_DEFAULT the 
default for new streams and only resets it in demuxers that set the flag 
correctly (missing nut tests and changes).

Please review, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 1a15558..0c363c6 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1724,8 +1724,8 @@ static int matroska_read_header(AVFormatContext *s)
             av_dict_set(&st->metadata, "language", track->language, 0);
         av_dict_set(&st->metadata, "title", track->name, 0);
 
-        if (track->flag_default)
-            st->disposition |= AV_DISPOSITION_DEFAULT;
+        if (!track->flag_default)
+            st->disposition &= ~AV_DISPOSITION_DEFAULT;
         if (track->flag_forced)
             st->disposition |= AV_DISPOSITION_FORCED;
 
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index c167c01..290385a 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -570,8 +570,7 @@ static int mkv_write_tracks(AVFormatContext *s)
         tag = av_dict_get(st->metadata, "language", NULL, 0);
         put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und");
 
-        if (st->disposition)
-            put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
+        put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT));
         if (st->disposition & AV_DISPOSITION_FORCED)
             put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, 1);
 
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 4eaffd8..ed125b8 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -649,6 +649,7 @@ static int vobsub_read_header(AVFormatContext *s)
             st->id = stream_id;
             st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
             st->codec->codec_id   = AV_CODEC_ID_DVD_SUBTITLE;
+            st->disposition      &= ~AV_DISPOSITION_DEFAULT;
             av_dict_set(&st->metadata, "language", id, 0);
             av_log(s, AV_LOG_DEBUG, "IDX stream[%d] id=%s\n", stream_id, id);
             header_parsed = 1;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 97d6558..1c064f3 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3331,6 +3331,8 @@ AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c)
     st->info->fps_first_dts = AV_NOPTS_VALUE;
     st->info->fps_last_dts  = AV_NOPTS_VALUE;
 
+    st->disposition |= AV_DISPOSITION_DEFAULT;
+
     s->streams[s->nb_streams++] = st;
     return st;
 }


More information about the ffmpeg-devel mailing list