On Thu, 19 Jan 2012 09:56:04 -0500, Justin Ruggles <justin.rugg...@gmail.com> wrote: > On 01/19/2012 02:40 AM, Anton Khirnov wrote: > > > > > On Wed, 18 Jan 2012 17:19:43 -0500, Justin Ruggles > > <justin.rugg...@gmail.com> wrote: > >> 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; > > > > I would expect an exit_program() here. > > I thought falling back to the default decoder would be more > user-friendly, but if failing is preferred instead I can change it. >
The user took time specifying the decoder he wants, so he probably cares that exactly this decoder gets used. I consider aborting more user-friendly in this case. > >> + } > >> + } > >> + 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); > >> - } > > > > Why are you moving this block? > > > So that the results of opening the decoder are shown in the console > dump. Currently it's done prior to the opening the decoder, and thus > will always show the default result of avcodec_find_decoder(). I suppose > the codec selection could be broken out into a separate function and put > before this block instead, but this seems like an easier solution. > > Since this is probably a common use case, what do you think of maybe > adding avcodec_find_(en/de)coder2(codec_id, name) where name can be NULL > to get the default? > This wouldn't allow overriding the codec id, no? -- Anton Khirnov _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel