[FFmpeg-devel] [PATCH] ffmpeg: add -devices param

Lukasz Marek lukasz.m.luki2 at gmail.com
Fri May 23 19:59:53 CEST 2014


Ffmpeg mix devices and file formats when -formats option is used.
This commit removes devices from formats list.
Devices can be listed with -devices param.
---
 cmdutils.c                   |   35 ++++++++++++++++++++++++++++++++---
 cmdutils.h                   |    7 +++++++
 cmdutils_common_opts.h       |    1 +
 doc/fftools-common-opts.texi |   10 +++++-----
 doc/indevs.texi              |    4 ++--
 doc/outdevs.texi             |    4 ++--
 6 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index 1147bc3..bcb002d 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -1193,16 +1193,29 @@ int show_license(void *optctx, const char *opt, const char *arg)
     return 0;
 }
 
-int show_formats(void *optctx, const char *opt, const char *arg)
+static int is_device(const AVClass *avclass)
+{
+    if (!avclass)
+        return 0;
+    return avclass->category == AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT ||
+           avclass->category == AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT ||
+           avclass->category == AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT ||
+           avclass->category == AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT ||
+           avclass->category == AV_CLASS_CATEGORY_DEVICE_OUTPUT ||
+           avclass->category == AV_CLASS_CATEGORY_DEVICE_INPUT;
+}
+
+static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device)
 {
     AVInputFormat *ifmt  = NULL;
     AVOutputFormat *ofmt = NULL;
     const char *last_name;
+    int is_dev;
 
-    printf("File formats:\n"
+    printf("%s\n"
            " D. = Demuxing supported\n"
            " .E = Muxing supported\n"
-           " --\n");
+           " --\n", device ? "Devices:" : "File formats:");
     last_name = "000";
     for (;;) {
         int decode = 0;
@@ -1211,6 +1224,9 @@ int show_formats(void *optctx, const char *opt, const char *arg)
         const char *long_name = NULL;
 
         while ((ofmt = av_oformat_next(ofmt))) {
+            is_dev = is_device(ofmt->priv_class);
+            if ((is_dev && !device) || (!is_dev && device))
+                continue;
             if ((name == NULL || strcmp(ofmt->name, name) < 0) &&
                 strcmp(ofmt->name, last_name) > 0) {
                 name      = ofmt->name;
@@ -1219,6 +1235,9 @@ int show_formats(void *optctx, const char *opt, const char *arg)
             }
         }
         while ((ifmt = av_iformat_next(ifmt))) {
+            is_dev = is_device(ifmt->priv_class);
+            if ((is_dev && !device) || (!is_dev && device))
+                continue;
             if ((name == NULL || strcmp(ifmt->name, name) < 0) &&
                 strcmp(ifmt->name, last_name) > 0) {
                 name      = ifmt->name;
@@ -1241,6 +1260,16 @@ int show_formats(void *optctx, const char *opt, const char *arg)
     return 0;
 }
 
+int show_formats(void *optctx, const char *opt, const char *arg)
+{
+    return show_formats_devices(optctx, opt, arg, 0);
+}
+
+int show_devices(void *optctx, const char *opt, const char *arg)
+{
+    return show_formats_devices(optctx, opt, arg, 1);
+}
+
 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
     if (codec->field) {                                                      \
         const type *p = codec->field;                                        \
diff --git a/cmdutils.h b/cmdutils.h
index c4a16aa..ed11e65 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -437,6 +437,13 @@ int show_license(void *optctx, const char *opt, const char *arg);
 int show_formats(void *optctx, const char *opt, const char *arg);
 
 /**
+ * Print a listing containing all the devices supported by the
+ * program.
+ * This option processing function does not utilize the arguments.
+ */
+int show_devices(void *optctx, const char *opt, const char *arg);
+
+/**
  * Print a listing containing all the codecs supported by the
  * program.
  * This option processing function does not utilize the arguments.
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h
index 190dba6..49b5180 100644
--- a/cmdutils_common_opts.h
+++ b/cmdutils_common_opts.h
@@ -6,6 +6,7 @@
     { "version"    , OPT_EXIT, {.func_arg = show_version},      "show version" },
     { "buildconf"  , OPT_EXIT, {.func_arg = show_buildconf},    "show build configuration" },
     { "formats"    , OPT_EXIT, {.func_arg = show_formats  },    "show available formats" },
+    { "devices"    , OPT_EXIT, {.func_arg = show_devices  },    "show available devices" },
     { "codecs"     , OPT_EXIT, {.func_arg = show_codecs   },    "show available codecs" },
     { "decoders"   , OPT_EXIT, {.func_arg = show_decoders },    "show available decoders" },
     { "encoders"   , OPT_EXIT, {.func_arg = show_encoders },    "show available encoders" },
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index 6bc6852..a6dd3ca 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -69,7 +69,7 @@ Print advanced tool options in addition to the basic tool options.
 
 @item full
 Print complete list of options, including shared and private options
-for encoders, decoders, demuxers, muxers, filters, etc.
+for encoders, decoders, demuxers, muxers, devices, filters, etc.
 
 @item decoder=@var{decoder_name}
 Print detailed information about the decoder named @var{decoder_name}. Use the
@@ -80,12 +80,12 @@ Print detailed information about the encoder named @var{encoder_name}. Use the
 @option{-encoders} option to get a list of all encoders.
 
 @item demuxer=@var{demuxer_name}
-Print detailed information about the demuxer named @var{demuxer_name}. Use the
- at option{-formats} option to get a list of all demuxers and muxers.
+Print detailed information about the demuxer (or input device) named @var{demuxer_name}.
+Use the @option{-formats} or @option{-devices} option to get a list of all demuxers and muxers.
 
 @item muxer=@var{muxer_name}
-Print detailed information about the muxer named @var{muxer_name}. Use the
- at option{-formats} option to get a list of all muxers and demuxers.
+Print detailed information about the muxer (or output device) named @var{muxer_name}.
+Use the @option{-formats} or @option{-devices} option to get a list of all muxers and demuxers.
 
 @item filter=@var{filter_name}
 Print detailed information about the filter name @var{filter_name}. Use the
diff --git a/doc/indevs.texi b/doc/indevs.texi
index 7b94155..4ea82a4 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -13,8 +13,8 @@ You can disable all the input devices using the configure option
 option "--enable-indev=@var{INDEV}", or you can disable a particular
 input device using the option "--disable-indev=@var{INDEV}".
 
-The option "-formats" of the ff* tools will display the list of
-supported input devices (amongst the demuxers).
+The option "-devices" of the ff* tools will display the list of
+supported input devices.
 
 A description of the currently available input devices follows.
 
diff --git a/doc/outdevs.texi b/doc/outdevs.texi
index 488a1ad..e68653f 100644
--- a/doc/outdevs.texi
+++ b/doc/outdevs.texi
@@ -13,8 +13,8 @@ You can disable all the output devices using the configure option
 option "--enable-outdev=@var{OUTDEV}", or you can disable a particular
 input device using the option "--disable-outdev=@var{OUTDEV}".
 
-The option "-formats" of the ff* tools will display the list of
-enabled output devices (amongst the muxers).
+The option "-devices" of the ff* tools will display the list of
+enabled output devices.
 
 A description of the currently available output devices follows.
 
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list