[FFmpeg-cvslog] ffplay: improve robustness of opt_codec(), and add options acodec, vcodec, scodec

Stefano Sabatini git at videolan.org
Sun Dec 16 11:03:36 CET 2012


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sat Dec 15 22:40:26 2012 +0100| [cb0f97b59d67bda2c33586922640e65e128c17fb] | committer: Stefano Sabatini

ffplay: improve robustness of opt_codec(), and add options acodec,vcodec,scodec

Fail with a meaningfull error message in case of bogus input.

Also the new options are more consistent with the rest of the tool
options, since it does not support generic stream specifiers.

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

 doc/ffplay.texi |   16 ++++++++++++++--
 ffplay.c        |   29 +++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/doc/ffplay.texi b/doc/ffplay.texi
index e2bded7..1396b01 100644
--- a/doc/ffplay.texi
+++ b/doc/ffplay.texi
@@ -134,8 +134,20 @@ Exit when video is done playing.
 Exit if any key is pressed.
 @item -exitonmousedown
 Exit if any mouse button is pressed.
- at item -codec:@var{stream_type}
-Force a specific decoder implementation
+
+ at item -codec:@var{media_specifier} @var{codec_name}
+Force a specific decoder implementation for the stream identified by
+ at var{media_specifier}, which can assume the values @code{a} (audio),
+ at code{v} (video), and @code{s} subtitle.
+
+ at item -acodec @var{codec_name}
+Force a specific audio decoder.
+
+ at item -vcodec @var{codec_name}
+Force a specific video decoder.
+
+ at item -scodec @var{codec_name}
+Force a specific subtitle decoder.
 @end table
 
 @section While playing
diff --git a/ffplay.c b/ffplay.c
index d6b17c2..3384c6c 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -3147,14 +3147,24 @@ static void opt_input_file(void *optctx, const char *filename)
     input_filename = filename;
 }
 
-static int opt_codec(void *o, const char *opt, const char *arg)
+static int opt_codec(void *optctx, const char *opt, const char *arg)
 {
-    switch(opt[strlen(opt)-1]){
-    case 'a' :    audio_codec_name = arg; break;
-    case 's' : subtitle_codec_name = arg; break;
-    case 'v' :    video_codec_name = arg; break;
-    }
-    return 0;
+   const char *spec = strchr(opt, ':');
+   if (!spec) {
+       fprintf(stderr, "No media specifier was specified in '%s' in option '%s'\n",
+               arg, opt);
+       return AVERROR(EINVAL);
+   }
+   spec++;
+   switch (spec[0]) {
+   case 'a' :    audio_codec_name = arg; break;
+   case 's' : subtitle_codec_name = arg; break;
+   case 'v' :    video_codec_name = arg; break;
+   default:
+       fprintf(stderr, "Invalid media specifier '%s' in option '%s'\n", spec, opt);
+       return AVERROR(EINVAL);
+   }
+   return 0;
 }
 
 static int dummy;
@@ -3202,7 +3212,10 @@ static const OptionDef options[] = {
     { "showmode", HAS_ARG, { .func_arg = opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT)", "mode" },
     { "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, { .func_arg = opt_default }, "generic catch all option", "" },
     { "i", OPT_BOOL, { &dummy}, "read specified file", "input_file"},
-    { "codec", HAS_ARG, { .func_arg = opt_codec}, "force decoder", "decoder" },
+    { "codec", HAS_ARG, { .func_arg = opt_codec}, "force decoder", "decoder_name" },
+    { "acodec", HAS_ARG | OPT_STRING | OPT_EXPERT, {    &audio_codec_name }, "force audio decoder",    "decoder_name" },
+    { "scodec", HAS_ARG | OPT_STRING | OPT_EXPERT, { &subtitle_codec_name }, "force subtitle decoder", "decoder_name" },
+    { "vcodec", HAS_ARG | OPT_STRING | OPT_EXPERT, {    &video_codec_name }, "force video decoder",    "decoder_name" },
     { NULL, },
 };
 



More information about the ffmpeg-cvslog mailing list