[FFmpeg-cvslog] cmdutils: allow matching by metadata in stream specifiers

Anton Khirnov git at videolan.org
Thu Aug 14 00:59:16 CEST 2014


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Tue Aug 12 16:51:28 2014 +0000| [481a3667495425db9fdffb653292b6460fb68208] | committer: Anton Khirnov

cmdutils: allow matching by metadata in stream specifiers

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=481a3667495425db9fdffb653292b6460fb68208
---

 Changelog                    |    1 +
 cmdutils.c                   |   23 +++++++++++++++++++++++
 doc/avconv.texi              |    5 +++++
 doc/avtools-common-opts.texi |    7 +++++++
 4 files changed, 36 insertions(+)

diff --git a/Changelog b/Changelog
index 4f1507a..ea9d721 100644
--- a/Changelog
+++ b/Changelog
@@ -30,6 +30,7 @@ version <next>:
 - drop avserver, it was unmaintained for years and largely broken
 - Icecast protocol
 - request icecast metadata by default
+- support for using metadata in stream specifiers in avtools
 
 
 version 10:
diff --git a/cmdutils.c b/cmdutils.c
index 69a11bd..b208e52 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1536,6 +1536,29 @@ int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
         spec += 2;
         stream_id = strtol(spec, &endptr, 0);
         return stream_id == st->id;
+    } else if (*spec == 'm' && *(spec + 1) == ':') {
+        AVDictionaryEntry *tag;
+        char *key, *val;
+        int ret;
+
+        spec += 2;
+        val = strchr(spec, ':');
+
+        key = val ? av_strndup(spec, val - spec) : av_strdup(spec);
+        if (!key)
+            return AVERROR(ENOMEM);
+
+        tag = av_dict_get(st->metadata, key, NULL, 0);
+        if (tag) {
+            if (!val || !strcmp(tag->value, val + 1))
+                ret = 1;
+            else
+                ret = 0;
+        } else
+            ret = 0;
+
+        av_freep(&key);
+        return ret;
     } else if (!*spec) /* empty specifier, matches everything */
         return 1;
 
diff --git a/doc/avconv.texi b/doc/avconv.texi
index 6efec55..1156176 100644
--- a/doc/avconv.texi
+++ b/doc/avconv.texi
@@ -720,6 +720,11 @@ To map all the streams except the second audio, use negative mappings
 avconv -i INPUT -map 0 -map -0:a:1 OUTPUT
 @end example
 
+To pick the English audio stream:
+ at example
+avconv -i INPUT -map 0:m:language:eng OUTPUT
+ at end example
+
 Note that using this option disables the default mappings for this output file.
 
 @item -map_metadata[:@var{metadata_spec_out}] @var{infile}[:@var{metadata_spec_in}] (@emph{output,per-metadata})
diff --git a/doc/avtools-common-opts.texi b/doc/avtools-common-opts.texi
index 3bf321f..8468eca 100644
--- a/doc/avtools-common-opts.texi
+++ b/doc/avtools-common-opts.texi
@@ -44,6 +44,13 @@ If @var{stream_index} is given, then matches stream number @var{stream_index} in
 program with id @var{program_id}. Otherwise matches all streams in this program.
 @item i:@var{stream_id}
 Match the stream by stream id (e.g. PID in MPEG-TS container).
+ at item m:@var{key}[:@var{value}]
+Matches streams with the metadata tag @var{key} having the specified value. If
+ at var{value} is not given, matches streams that contain the given tag with any
+value.
+
+Note that in @command{avconv}, matching by metadata will only work properly for
+input files.
 @end table
 @section Generic options
 



More information about the ffmpeg-cvslog mailing list