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

Carl Eugen Hoyos cehoyos at ag.or.at
Tue Jan 29 10:02:00 CET 2013


On Monday 28 January 2013 12:55:09 pm Hendrik Leppkes wrote:
> What i would do is check all input streams in the muxer (ie in
> mkv_write_tracks), 

> and if none have a default disposition, then mark 
> the first of each type as such (first audio, first video, first
> subtitle).

This may be sensible, but is imo unrelated.

> But if one stream is marked as default, then keep that 
> flag, and write it as 0 for all other streams.

Done in attached patch, thank you for the suggestion!

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index c167c01..204d1b2 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -530,7 +530,7 @@ static int mkv_write_tracks(AVFormatContext *s)
     MatroskaMuxContext *mkv = s->priv_data;
     AVIOContext *pb = s->pb;
     ebml_master tracks;
-    int i, j, ret;
+    int i, j, ret, default_stream_exists = 0;
 
     ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb));
     if (ret < 0) return ret;
@@ -538,6 +538,10 @@ static int mkv_write_tracks(AVFormatContext *s)
     tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0);
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
+        default_stream_exists |= st->disposition & AV_DISPOSITION_DEFAULT;
+    }
+    for (i = 0; i < s->nb_streams; i++) {
+        AVStream *st = s->streams[i];
         AVCodecContext *codec = st->codec;
         ebml_master subinfo, track;
         int native_id = 0;
@@ -570,8 +574,9 @@ 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)
+        if (default_stream_exists) {
             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);
 


More information about the ffmpeg-devel mailing list