On Tue, 5 Feb 2019, Marton Balint wrote:
This removes lots of code duplication and also allows more complex specifiers,
for example you can use p:204:a:m:language:eng to select the English language
audio stream from program 204.
Ping... Will apply soon.
Thanks,
Marton
Signed-off-by: Marton Balint
---
doc/fftools-common-opts.texi | 30 +++-
libavformat/utils.c | 172 +--
2 files changed, 65 insertions(+), 137 deletions(-)
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 84705c0b68..43c1f4d2d6 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -34,27 +34,21 @@ Possible forms of stream specifiers are:
@table @option
@item @var{stream_index}
Matches the stream with this index. E.g. @code{-threads:1 4} would set the
-thread count for the second stream to 4.
-@item @var{stream_type}[:@var{stream_index}]
+thread count for the second stream to 4. If @var{stream_index} is used as an
+additional stream specifier (see below), then it selects stream number
+@var{stream_index} from the matching streams.
+@item @var{stream_type}[:@var{additional_stream_specifier}]
@var{stream_type} is one of following: 'v' or 'V' for video, 'a' for audio, 's'
for subtitle, 'd' for data, and 't' for attachments. 'v' matches all video
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}]] 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 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.
+thumbnails or cover arts. If @var{additional_stream_specifier} is used, then
+it matches streams which both have this type and match the
+@var{additional_stream_specifier}. Otherwise, it matches all streams of the
+specified type.
+@item p:@var{program_id}[:@var{additional_stream_specifier}]
+Matches streams which are in the program with the id @var{program_id}. If
+@var{additional_stream_specifier} is used, then it matches streams which both
+are part of the program and match the @var{additional_stream_specifier}.
@item #@var{stream_id} or i:@var{stream_id}
Match the stream by stream id (e.g. PID in MPEG-TS container).
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 7afef545fe..b3c30fe14c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -5097,13 +5097,21 @@ AVRational av_guess_frame_rate(AVFormatContext *format,
AVStream *st, AVFrame *f
return fr;
}
-int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
-const char *spec)
-{
-if (*spec <= '9' && *spec >= '0') /* opt:index */
-return strtol(spec, NULL, 0) == st->index;
-else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
- *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
+/* Matches a stream specifier (but ignores requested index)
+ * Returns:
+ * - negative on error
+ * - 0 if st is NOT a matching stream
+ * - >0 if st is a matching stream
+ * *index is set if a specific index is requested from the matching streams. */
+static int match_stream_specifier(AVFormatContext *s, AVStream *st,
+ const char *spec, int *index)
+{
+if (*spec <= '9' && *spec >= '0') { /* opt:index */
+if (index)
+*index = strtol(spec, NULL, 0);
+return 1;
+} else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' ||
+ *spec == 't' || *spec == 'V') { /* opt:[vasdtV] */
enum AVMediaType type;
int nopic = 0;
@@ -5128,27 +5136,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif
if (nopic && (st->disposition & AV_DISPOSITION_ATTACHED_PIC))
return 0;
-if (*spec++ == ':') { /* possibly followed by :index */
-int i, index = strtol(spec, NULL, 0);
-for (i = 0; i < s->nb_streams; i++) {
-#if FF_API_LAVF_AVCTX
-FF_DISABLE_DEPRECATION_WARNINGS
-