[FFmpeg-cvslog] r19208 - trunk/ffmpeg.c

stefano subversion
Wed Jun 17 01:02:54 CEST 2009


Author: stefano
Date: Wed Jun 17 01:02:53 2009
New Revision: 19208

Log:
Make ffmpeg able to set the loglevel option using strings
corresponding to the various log levels.

Patch by Ramiro.

Modified:
   trunk/ffmpeg.c

Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c	Tue Jun 16 23:50:36 2009	(r19207)
+++ trunk/ffmpeg.c	Wed Jun 17 01:02:53 2009	(r19208)
@@ -2356,7 +2356,35 @@ static int opt_me_threshold(const char *
 
 static int opt_loglevel(const char *opt, const char *arg)
 {
-    int level = parse_number_or_die(opt, arg, OPT_INT, INT_MIN, INT_MAX);
+    const struct { const char *name; int level; } const log_levels[] = {
+        { "quiet"  , AV_LOG_QUIET   },
+        { "panic"  , AV_LOG_PANIC   },
+        { "fatal"  , AV_LOG_FATAL   },
+        { "error"  , AV_LOG_ERROR   },
+        { "warning", AV_LOG_WARNING },
+        { "info"   , AV_LOG_INFO    },
+        { "verbose", AV_LOG_VERBOSE },
+        { "debug"  , AV_LOG_DEBUG   },
+    };
+    char *tail;
+    int level;
+    int i;
+
+    for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
+        if (!strcmp(log_levels[i].name, arg)) {
+            av_log_set_level(log_levels[i].level);
+            return 0;
+        }
+    }
+
+    level = strtol(arg, &tail, 10);
+    if (*tail) {
+        fprintf(stderr, "Invalid loglevel \"%s\". "
+                        "Possible levels are numbers or:\n", arg);
+        for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
+            fprintf(stderr, "\"%s\"\n", log_levels[i].name);
+        av_exit(1);
+    }
     av_log_set_level(level);
     return 0;
 }
@@ -3800,7 +3828,7 @@ static const OptionDef options[] = {
     { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" },
     { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" },
     { "v", HAS_ARG | OPT_FUNC2, {(void*)opt_verbose}, "set ffmpeg verbosity level", "number" },
-    { "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "number" },
+    { "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "logging level number or string" },
     { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" },
     { "threads", OPT_FUNC2 | HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" },
     { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" },



More information about the ffmpeg-cvslog mailing list