[FFmpeg-cvslog] avtools: parse loglevel before all the other options.

Anton Khirnov git at videolan.org
Tue Sep 27 02:25:28 CEST 2011


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Sep 26 08:15:37 2011 +0200| [182cbe433aea20b0d9627d40de7c75713ec736db] | committer: Anton Khirnov

avtools: parse loglevel before all the other options.

This way it can be applied to cmdutils too -- e.g. showing the banner
and printing startup messages.

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

 avconv.c   |    1 +
 avplay.c   |    1 +
 avprobe.c  |    1 +
 avserver.c |    1 +
 cmdutils.c |   35 +++++++++++++++++++++++++++++++++++
 cmdutils.h |    5 +++++
 ffmpeg.c   |    1 +
 7 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/avconv.c b/avconv.c
index 9e2fac7..9d3eb7c 100644
--- a/avconv.c
+++ b/avconv.c
@@ -4019,6 +4019,7 @@ int main(int argc, char **argv)
     reset_options(&o);
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    parse_loglevel(argc, argv, options);
 
     avcodec_register_all();
 #if CONFIG_AVDEVICE
diff --git a/avplay.c b/avplay.c
index b95cba7..2eea5d7 100644
--- a/avplay.c
+++ b/avplay.c
@@ -3050,6 +3050,7 @@ int main(int argc, char **argv)
     int flags;
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    parse_loglevel(argc, argv, options);
 
     /* register all codecs, demux and protocols */
     avcodec_register_all();
diff --git a/avprobe.c b/avprobe.c
index 5e83916..ae22dac 100644
--- a/avprobe.c
+++ b/avprobe.c
@@ -399,6 +399,7 @@ int main(int argc, char **argv)
 {
     int ret;
 
+    parse_loglevel(argc, argv, options);
     av_register_all();
     init_opts();
 #if CONFIG_AVDEVICE
diff --git a/avserver.c b/avserver.c
index df9d07d..d0a14aa 100644
--- a/avserver.c
+++ b/avserver.c
@@ -4668,6 +4668,7 @@ int main(int argc, char **argv)
 {
     struct sigaction sigact;
 
+    parse_loglevel(argc, argv, options);
     av_register_all();
 
     show_banner();
diff --git a/cmdutils.c b/cmdutils.c
index b6ed475..2b2fea8 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -304,6 +304,41 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
     }
 }
 
+/*
+ * Return index of option opt in argv or 0 if not found.
+ */
+static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname)
+{
+    const OptionDef *po;
+    int i;
+
+    for (i = 1; i < argc; i++) {
+        const char *cur_opt = argv[i];
+
+        if (*cur_opt++ != '-')
+            continue;
+
+        po = find_option(options, cur_opt);
+        if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
+            po = find_option(options, cur_opt + 2);
+
+        if ((!po->name && !strcmp(cur_opt, optname)) ||
+             (po->name && !strcmp(optname, po->name)))
+            return i;
+
+        if (!po || po->flags & HAS_ARG)
+            i++;
+    }
+    return 0;
+}
+
+void parse_loglevel(int argc, char **argv, const OptionDef *options)
+{
+    int idx = locate_option(argc, argv, options, "loglevel");
+    if (idx && argv[idx + 1])
+        opt_loglevel("loglevel", argv[idx + 1]);
+}
+
 #define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0
 int opt_default(const char *opt, const char *arg)
 {
diff --git a/cmdutils.h b/cmdutils.h
index dc19486..a20b779 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -175,6 +175,11 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
 int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options);
 
 /**
+ * Find the '-loglevel' option in the commandline args and apply it.
+ */
+void parse_loglevel(int argc, char **argv, const OptionDef *options);
+
+/**
  * Check if the given stream matches a stream specifier.
  *
  * @param s  Corresponding format context.
diff --git a/ffmpeg.c b/ffmpeg.c
index 2a921d0..86b73b2 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4357,6 +4357,7 @@ int main(int argc, char **argv)
     int64_t ti;
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    parse_loglevel(argc, argv, options);
 
     avcodec_register_all();
 #if CONFIG_AVDEVICE



More information about the ffmpeg-cvslog mailing list