ffmpeg # 利用loglevel控制打印日志的信息

cmdutil.c中:

int opt_loglevel(void *optctx, const char *opt, const char *arg)
{
    const struct { const char *name; int level; } 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   },
        { "trace"  , AV_LOG_TRACE   },
    };

...
}

对应的宏的详细说明:

/**
 * @addtogroup lavu_log
 *
 * @{
 *
 * @defgroup lavu_log_constants Logging Constants
 *
 * @{
 */

/**
 * Print no output.
 */
#define AV_LOG_QUIET    -8

/**
 * Something went really wrong and we will crash now.
 */
#define AV_LOG_PANIC     0

/**
 * Something went wrong and recovery is not possible.
 * For example, no header was found for a format which depends
 * on headers or an illegal combination of parameters is used.
 */
#define AV_LOG_FATAL     8

/**
 * Something went wrong and cannot losslessly be recovered.
 * However, not all future data is affected.
 */
#define AV_LOG_ERROR    16

/**
 * Something somehow does not look correct. This may or may not
 * lead to problems. An example would be the use of '-vstrict -2'.
 */
#define AV_LOG_WARNING  24

/**
 * Standard information.
 */
#define AV_LOG_INFO     32

/**
 * Detailed information.
 */
#define AV_LOG_VERBOSE  40

/**
 * Stuff which is only useful for libav* developers.
 */
#define AV_LOG_DEBUG    48

/**
 * Extremely verbose debugging, useful for libav* development.
 */
#define AV_LOG_TRACE    56

从定义中可以看出来,随着严重程度逐渐下降,一共包含如下级别:
AV_LOG_PANIC,
AV_LOG_FATAL,
AV_LOG_ERROR,
AV_LOG_WARNING,
AV_LOG_INFO,
AV_LOG_VERBOSE,
AV_LOG_DEBUG。
每个级别定义的数值代表了严重程度,数值越小代表越严重。
默认的级别是AV_LOG_INFO
此外,还有一个级别不输出任何信息,即AV_LOG_QUIET。

当前系统存在着一个“Log级别”。
所有严重程度高于该级别的Log信息都会输出出来
例如当前的Log级别是AV_LOG_WARNING,则会输出AV_LOG_PANIC,AV_LOG_FATAL,AV_LOG_ERROR,AV_LOG_WARNING级别的信息,而不会输出AV_LOG_INFO级别的信息。
可以通过av_log_get_level()获得当前Log的级别,通过另一个函数av_log_set_level()设置当前的Log级别。

  • 命令行中 指定
ffmpeg -loglevel error -i sample.mp4 output.mkv
  • 代码中写日志:
av_log(NULL, AV_LOG_ERROR, "Error while filtering: %s\n", errbuf);


...
int64_t seek_timestamp = timestamp;
...
av_log(NULL, AV_LOG_INFO, "seek_timestamp : %"PRId64"\n",seek_timestamp);

...
uint64_t total_packets = 0, total_size = 0;
...
av_log(NULL, AV_LOG_VERBOSE, "  Total: %"PRIu64" packets (%"PRIu64" bytes) demuxed\n",
               total_packets, total_size);

References:

https://blog.csdn.net/openswc/article/details/54694477
https://blog.csdn.net/leixiaohua1020/article/details/44243155

你可能感兴趣的:(ffmpeg # 利用loglevel控制打印日志的信息)