summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/fftools-common-opts.texi3
-rw-r--r--libavformat/utils.c22
2 files changed, 25 insertions, 0 deletions
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 655690956a..2e7c9f7e8f 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -50,6 +50,9 @@ Match the stream by stream id (e.g. PID in MPEG-TS container).
Matches streams 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 u
+Matches streams with usable configuration, the codec must be defined and the
+essential information such as video dimension or audio sample rate must be present.
Note that in @command{ffmpeg}, matching by metadata will only work properly for
input files.
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 17ae300a8f..6a0f666a7d 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4287,6 +4287,28 @@ int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st,
av_freep(&key);
return ret;
+ } else if (*spec == 'u') {
+ AVCodecContext *avctx = st->codec;
+ int val;
+ switch (avctx->codec_type) {
+ case AVMEDIA_TYPE_AUDIO:
+ val = avctx->sample_rate && avctx->channels;
+ if (avctx->sample_fmt == AV_SAMPLE_FMT_NONE)
+ return 0;
+ break;
+ case AVMEDIA_TYPE_VIDEO:
+ val = avctx->width && avctx->height;
+ if (avctx->pix_fmt == AV_PIX_FMT_NONE)
+ return 0;
+ break;
+ case AVMEDIA_TYPE_UNKNOWN:
+ val = 0;
+ break;
+ default:
+ val = 1;
+ break;
+ }
+ return avctx->codec_id != AV_CODEC_ID_NONE && val != 0;
} else if (!*spec) /* empty specifier, matches everything */
return 1;