Allows for choosing an alternate decoder when available.
---
avplay.c | 35 ++++++++++++++++++++++++++++++-----
1 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/avplay.c b/avplay.c
index 4d21234..ad27aef 100644
--- a/avplay.c
+++ b/avplay.c
@@ -259,6 +259,8 @@ static int exit_on_keydown;
static int exit_on_mousedown;
static int loop = 1;
static int framedrop = 1;
+static const char *acodec_name;
+static const char *vcodec_name;
static int rdftspeed = 20;
#if CONFIG_AVFILTER
@@ -2167,10 +2169,11 @@ static int stream_component_open(VideoState *is, int
stream_index)
{
AVFormatContext *ic = is->ic;
AVCodecContext *avctx;
- AVCodec *codec;
+ AVCodec *codec = NULL;
SDL_AudioSpec wanted_spec, spec;
AVDictionary *opts;
AVDictionaryEntry *t = NULL;
+ enum AVMediaType codec_type;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return -1;
@@ -2178,7 +2181,26 @@ static int stream_component_open(VideoState *is, int
stream_index)
opts = filter_codec_opts(codec_opts, avctx->codec_id, ic,
ic->streams[stream_index]);
- codec = avcodec_find_decoder(avctx->codec_id);
+ codec_type = avcodec_get_type(avctx->codec_id);
+ if (acodec_name && codec_type == AVMEDIA_TYPE_AUDIO ||
+ vcodec_name && codec_type == AVMEDIA_TYPE_VIDEO) {
+ const char *name;
+ if (codec_type == AVMEDIA_TYPE_AUDIO)
+ name = acodec_name;
+ else
+ name = vcodec_name;
+
+ codec = avcodec_find_decoder_by_name(name);
+ if (!codec) {
+ av_log(NULL, AV_LOG_FATAL, "Unknown decoder '%s'\n", name);
+ } else if (codec->type != codec_type) {
+ av_log(NULL, AV_LOG_FATAL, "Invalid decoder type '%s'\n", name);
+ codec = NULL;
+ }
+ }
+ if (!codec)
+ codec = avcodec_find_decoder(avctx->codec_id);
+
avctx->debug_mv = debug_mv;
avctx->debug = debug;
avctx->workaround_bugs = workaround_bugs;
@@ -2443,9 +2465,6 @@ static int decode_thread(void *arg)
st_index[AVMEDIA_TYPE_AUDIO] :
st_index[AVMEDIA_TYPE_VIDEO]),
NULL, 0);
- if (show_status) {
- av_dump_format(ic, 0, is->filename, 0);
- }
/* open the streams */
if (st_index[AVMEDIA_TYPE_AUDIO] >= 0) {
@@ -2472,6 +2491,10 @@ static int decode_thread(void *arg)
goto fail;
}
+ if (show_status) {
+ av_dump_format(ic, 0, is->filename, 0);
+ }
+
for (;;) {
if (is->abort_request)
break;
@@ -3006,6 +3029,8 @@ static const OptionDef options[] = {
{ "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, {
(void*)&rdftspeed }, "rdft speed", "msecs" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {
(void*)opt_default }, "generic catch all option", "" },
{ "i", 0, { NULL }, "avconv compatibility dummy option", ""},
+ { "acodec", HAS_ARG | OPT_STRING, &acodec_name, "audio codec name", "" },
+ { "vcodec", HAS_ARG | OPT_STRING, &vcodec_name, "video codec name", "" },
{ NULL, },
};
--
1.7.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel