summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorBela Bodecs <bodecsb@vivanet.hu>2018-04-13 12:11:32 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2018-04-13 21:44:28 +0200
commit3e1204b94d1ab586e4a5b1fc7c51559bc2447dcd (patch)
tree6f596d34f34a7eb70d8862c3a198a90aa6d7339f /libavformat
parent6b28e551d00912e0efeda8536039f8204752a684 (diff)
avformat/utils: Stream specifier enhancement 2.
In some cases, mainly working with multiprogram mpeg-ts containers as input, it would be handy to select sub stream of a specific program by their metadata. This patch makes it possible to narrow the stream selection among streams of the specified program by stream metadata. Examples: p:601:m:language:hun will select all sub streams of program with id 601 where sub streams have metadata key named 'language' with value 'hun'. p:602:m:guide will select all sub streams of program with id 602 where sub streams have metadata key named 'guide'. Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/utils.c28
1 files changed, 28 insertions, 0 deletions
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:<id>:m:<metadata_spec>
+ 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:<id>:<index>
int stream_idx = strtol(endptr, NULL, 0);
return stream_idx >= 0 &&