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

wm4 nfxjfg at googlemail.com
Thu Mar 3 09:55:26 CET 2016


On Wed, 2 Mar 2016 15:29:21 -0800
Sergey Volk <servolk at chromium.org> wrote:

> 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
> https://github.com/mbunkus/mkvtoolnix/issues/1050
> https://lists.w3.org/Archives/Public/public-inbandtracks/2014May/0003.html
> 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);

The int cast makes me suspicious. It might be ok to discard the
additional bits for pathological files, but I don't quite remember
whether or not this can trigger UB.

Might be better after all not to set the id if it's out of range?


More information about the ffmpeg-devel mailing list