[FFmpeg-devel] [PATCH] Use matroska TrackNumber for populating AVStream::id

Sergey Volk servolk at chromium.org
Thu Mar 3 00:29:21 CET 2016

As far as I can see FFmpeg currently doesn't set AVStream::id for
matroska/webm streams. I think we could use either MatroskaTrack::num
(TrackNumber) or MatroskaTrack::uid (TrackUID) for that.
I have found a few discussions claiming that TrackUID could be missing,
even though TrackUID is marked as mandatory field in matroska spec, for
example see
So I guess it's safer to use TrackNumber for now.
 libavformat/matroskadec.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index d20568c..8b80df1 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1856,6 +1856,8 @@ static int matroska_parse_tracks(AVFormatContext *s)
             return AVERROR(ENOMEM);

+        st->id = (int) track->num;
         if (key_id_base64) {
             /* export encryption key id as base64 metadata tag */
             av_dict_set(&st->metadata, "enc_key_id", key_id_base64, 0);

More information about the ffmpeg-devel mailing list