[FFmpeg-cvslog] avformat/utils: Stream specifier enhancement 2.

2018-04-13 Thread Bela Bodecs
ffmpeg | branch: master | Bela Bodecs  | Fri Apr 13 
12:11:32 2018 +0200| [3e1204b94d1ab586e4a5b1fc7c51559bc2447dcd] | committer: 
Michael Niedermayer

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 
Signed-off-by: Michael Niedermayer 

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

 doc/fftools-common-opts.texi | 10 --
 libavformat/utils.c  | 28 
 2 files changed, 36 insertions(+), 2 deletions(-)

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();
+return ret;
+
 } else {  // p::
 int stream_idx = strtol(endptr, NULL, 0);
 return stream_idx >= 0 &&

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avformat/utils: Stream specifier enhancement

2018-04-12 Thread Bela Bodecs
ffmpeg | branch: master | Bela Bodecs  | Sun Apr  1 
23:29:14 2018 +0200| [37d0213968a2b58499f52dfe09c8d7a27d4c5a86] | committer: 
Michael Niedermayer

avformat/utils: Stream specifier enhancement

Currently when specifying the program id you can only decide to select
all stream of the specified program (e.g. p:103 will select all streams
of program 103) or narrow the selection to a specific stream sub index
(e.g. p:145:1 will select 2nd stream of program 145.) But you can not
specify like all audio streams of program 145 or 3rd video stream of
program 311.
In some case, mainly working with multiprogram mpeg-ts containers as
input, this feature would be handy.
This patch makes it possible to narrow the stream selection among
streams of the specified program by stream type and optionally its
index. Handled types: a, v, s, d.
Examples: p:601:a  will select all audio streams of program 601,
p:603:a:1 will select 2nd audio streams of program 603,
p:604:v:0 will select first video stream of program 604.

Signed-off-by: Bela Bodecs 
Signed-off-by: Michael Niedermayer 

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

 doc/fftools-common-opts.texi | 10 +--
 libavformat/utils.c  | 65 
 2 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 7787e11cda..79feb39ca7 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -42,10 +42,14 @@ 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}]
-If @var{stream_index} is given, then it matches the stream with number 
@var{stream_index}
+@item p:@var{program_id}[:@var{stream_index}] or 
p:@var{program_id}[:@var{stream_type}[:@var{stream_index}]]
+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.
+program. In the latter 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}.
 @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 3e482a3bbc..cc35998336 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -5070,11 +5070,66 @@ FF_ENABLE_DEPRECATION_WARNINGS
 if (s->programs[i]->id != prog_id)
 continue;
 
-if (*endptr++ == ':') {
-int stream_idx = strtol(endptr, NULL, 0);
-return stream_idx >= 0 &&
-stream_idx < s->programs[i]->nb_stream_indexes &&
-st->index == s->programs[i]->stream_index[stream_idx];
+if (*endptr++ == ':') {  // p::
+if ( *endptr == 'a' || *endptr == 'v' ||
+ *endptr == 's' || *endptr == 'd') {  // 
p::[:]
+enum AVMediaType type;
+
+switch (*endptr++) {
+case 'v': type = AVMEDIA_TYPE_VIDEO;  break;
+case 'a': type = AVMEDIA_TYPE_AUDIO;  break;
+case 's': type = AVMEDIA_TYPE_SUBTITLE;   break;
+case 'd': type = AVMEDIA_TYPE_DATA;   break;
+default:  av_assert0(0);
+}
+if (*endptr++ == ':') {  // p:::
+int stream_idx = strtol(endptr, NULL, 0), type_counter 
= 0;
+for (j = 0; j < s->programs[i]->nb_stream_indexes; 
j++) {
+int stream_index = s->programs[i]->stream_index[j];
+if (st->index == s->programs[i]->stream_index[j]) {
+#if FF_API_LAVF_AVCTX
+FF_DISABLE_DEPRECATION_WARNINGS
+return type_counter == stream_idx &&
+   (type == st->codecpar->codec_type ||
+type == st->codec->codec_type);
+FF_ENABLE_DEPRECATION_WARNINGS
+#else
+return type_counter == stream_idx &&
+   type == st->codecpar->codec_type;
+#endif
+ }
+#if FF_API_LAVF_AVCTX