diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 79feb39ca7..84705c0b68 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -42,14 +42,20 @@ streams, 'V' only matches video streams which are not attached pictures, video thumbnails or cover arts. If @var{stream_index} is given, then it matches stream number @var{stream_index} of this type. Otherwise, it matches all streams of this type. -@item p:@var{program_id}[:@var{stream_index}] or p:@var{program_id}[:@var{stream_type}[:@var{stream_index}]] +@item p:@var{program_id}[:@var{stream_index}] or p:@var{program_id}[:@var{stream_type}[:@var{stream_index}]] or +p:@var{program_id}:m:@var{key}[:@var{value}] In first version, if @var{stream_index} is given, then it matches the stream with number @var{stream_index} in the program with the id @var{program_id}. Otherwise, it matches all streams in the -program. In the latter version, @var{stream_type} is one of following: 'v' for video, 'a' for audio, 's' +program. In the second version, @var{stream_type} is one of following: 'v' for video, 'a' for audio, 's' for subtitle, 'd' for data. If @var{stream_index} is also given, then it matches stream number @var{stream_index} of this type in the program with the id @var{program_id}. Otherwise, if only @var{stream_type} is given, it matches all streams of this type in the program with the id @var{program_id}. +In the third version matches streams in the program with the id @var{program_id} with the metadata +tag @var{key} having the specified value. If +@var{value} is not given, matches streams that contain the given tag with any +value. + @item #@var{stream_id} or i:@var{stream_id} Match the stream by stream id (e.g. PID in MPEG-TS container). @item m:@var{key}[:@var{value}] diff --git a/libavformat/utils.c b/libavformat/utils.c index cc35998336..84b926dc5a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5124,6 +5124,34 @@ FF_ENABLE_DEPRECATION_WARNINGS } return 0; } + + } else if ( *endptr == 'm') { // p::m: + AVDictionaryEntry *tag; + char *key, *val; + int ret = 0; + + if (*(++endptr) != ':') { + av_log(s, AV_LOG_ERROR, "Invalid stream specifier syntax, missing ':' sign after :m.\n"); + return AVERROR(EINVAL); + } + + val = strchr(++endptr, ':'); + key = val ? av_strndup(endptr, val - endptr) : av_strdup(endptr); + if (!key) + return AVERROR(ENOMEM); + + for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) + if (st->index == s->programs[i]->stream_index[j]) { + tag = av_dict_get(st->metadata, key, NULL, 0); + if (tag && (!val || !strcmp(tag->value, val + 1))) + ret = 1; + + break; + } + + av_freep(&key); + return ret; + } else { // p:: int stream_idx = strtol(endptr, NULL, 0); return stream_idx >= 0 &&