av_log 怎么使用?

来源:互联网 发布:java课程内容 编辑:程序博客网 时间:2024/04/29 06:16

我们使用ffmpeg的开发包进行开发时,可能会过多过少的使用 av_log ,同时也想观测下SDK API的日志情况,

这个时候,我们可以设置日志等级:

av_log_set_level
可是我们仍然发现,没有日志被显示?why ?
我们来看看 log.h 
/**
 * Send the specified message to the log if the level is less than or equal
 * to the current av_log_level. By default, all logging messages are sent to
 * stderr. This behavior can be altered by setting a different logging callback
 * function.
 * @see av_log_set_callback
 *
 * @param avcl A pointer to an arbitrary struct of which the first field is a
 *        pointer to an AVClass struct.
 * @param level The importance level of the message expressed using a @ref
 *        lavu_log_constants "Logging Constant".
 * @param fmt The format string (printf-compatible) that specifies how
 *        subsequent arguments are converted to output.
 */
void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
默认的情况下,所有的日志被送到了 stderr。如果我们设置一个回调函数,则可以把日志回调到我们自定义的函数里。
我们来看看  av_log_set_callback
/**
 * Set the logging callback
 *
 * @note The callback must be thread safe, even if the application does not use
 *       threads itself as some codecs are multithreaded.
 *
 * @see av_log_default_callback
 *
 * @param callback A logging function with a compatible signature.
 */
void av_log_set_callback(void (*callback)(void*, int, const char*, va_list));

也就是说,我们只需要设置一个线程安全的日志回调函数即可。
void logFF(void *, int level, const char *fmt, va_list ap)
{
    
}

av_log_set_callback(&logFF);

这样就可以了,不信你试试?^_^

0 0