Allows to set the AV_LOG_PRINT_LEVEL and AV_LOG_SKIP_REPEATED flags using a distinct command-line option, similar to other flag options. Previously only the AV_LOG_SKIP_REPEATED flag was supported as a prefix to the "loglevel" option value.
Signed-off-by: Tobias Rapp <t.r...@noa-archive.com> --- doc/fftools-common-opts.texi | 13 +++++++++++++ fftools/cmdutils.c | 31 +++++++++++++++++++++++++++++++ fftools/cmdutils.h | 6 ++++++ 3 files changed, 50 insertions(+) diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi index 185ec21..dd69741 100644 --- a/doc/fftools-common-opts.texi +++ b/doc/fftools-common-opts.texi @@ -209,6 +209,19 @@ the environment variable @env{AV_LOG_FORCE_COLOR}. The use of the environment variable @env{NO_COLOR} is deprecated and will be dropped in a future FFmpeg version. +@item -logflags flags (@emph{global}) +Allows to set or clear logging flags. + +Possible flags for this option are: +@table @option +@item repeat +Repeated log output will not be compressed to the first line and the "Last +message repeated n times" line will be omitted. +@item level +Add a @code{[level]} prefix string to each log message. Can be used as an +alternative to log coloring e.g. when dumping the log to file. +@end table + @item -report Dump full command line and console output to a file named @code{@var{program}-@var{YYYYMMDD}-@var{HHMMSS}.log} in the current diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 0c7d13c..11fe69a 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -514,6 +514,9 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options) idx = locate_option(argc, argv, options, "v"); if (idx && argv[idx + 1]) opt_loglevel(NULL, "loglevel", argv[idx + 1]); + idx = locate_option(argc, argv, options, "logflags"); + if (idx && argv[idx + 1]) + opt_logflags(NULL, "logflags", argv[idx + 1]); idx = locate_option(argc, argv, options, "report"); if ((env = getenv("FFREPORT")) || idx) { init_report(env); @@ -918,6 +921,34 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg) return 0; } +int opt_logflags(void *optctx, const char *opt, const char *arg) +{ + static const AVOption logflags_opts[] = { + { "flags" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" }, + /* implement AV_LOG_SKIP_REPEATED using inverse logic for consistency with the -loglevel option */ + { "repeat", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_LOG_SKIP_REPEATED }, .unit = "flags" }, + { "level" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_LOG_PRINT_LEVEL }, .unit = "flags" }, + { NULL }, + }; + static const AVClass class = { + .class_name = "logflags", + .item_name = av_default_item_name, + .option = logflags_opts, + .version = LIBAVUTIL_VERSION_INT, + }; + const AVClass *pclass = &class; + int flags = av_log_get_flags(); + int ret; + + flags ^= AV_LOG_SKIP_REPEATED; + if ((ret = av_opt_eval_flags(&pclass, &logflags_opts[0], arg, &flags)) < 0) + return ret; + flags ^= AV_LOG_SKIP_REPEATED; + + av_log_set_flags(flags); + return 0; +} + static void expand_filename_template(AVBPrint *bp, const char *template, struct tm *tm) { diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 8724489..28735b2 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -99,6 +99,11 @@ int opt_default(void *optctx, const char *opt, const char *arg); */ int opt_loglevel(void *optctx, const char *opt, const char *arg); +/** + * Update the log flags of libav* libraries. + */ +int opt_logflags(void *optctx, const char *opt, const char *arg); + int opt_report(const char *opt); int opt_max_alloc(void *optctx, const char *opt, const char *arg); @@ -236,6 +241,7 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags, { "colors", OPT_EXIT, { .func_arg = show_colors }, "show available color names" }, \ { "loglevel", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \ { "v", HAS_ARG, { .func_arg = opt_loglevel }, "set logging level", "loglevel" }, \ + { "logflags", HAS_ARG, { .func_arg = opt_logflags }, "set logging flags", "flags" }, \ { "report", 0, { (void*)opt_report }, "generate a report" }, \ { "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \ { "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \ -- 2.7.4 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel