From 119525e612dc0635ebfa3b02468524a7a7272d99 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sun, 7 Mar 2010 10:45:15 +0100 Subject: [PATCH] Add a logger callback for FFmpeg log messages --- src/logger.c | 22 ++++++++++++++++++++++ src/logger.h | 3 +++ src/main.c | 2 ++ 3 files changed, 27 insertions(+) diff --git a/src/logger.c b/src/logger.c index 4895ee41..9bf61693 100644 --- a/src/logger.c +++ b/src/logger.c @@ -29,6 +29,8 @@ #include +#include + #include "logger.h" @@ -130,6 +132,26 @@ DPRINTF(int severity, int domain, const char *fmt, ...) va_end(ap); } +void +logger_ffmpeg(void *ptr, int level, const char *fmt, va_list ap) +{ + int severity; + + /* Can't use a switch() because some definitions have the same value */ + if ((level == AV_LOG_FATAL) || (level == AV_LOG_ERROR)) + severity = E_LOG; + else if ((level == AV_LOG_WARNING) || (level == AV_LOG_INFO) || (level == AV_LOG_VERBOSE)) + severity = E_WARN; + else if (level == AV_LOG_DEBUG) + severity = E_DBG; + else if (level == AV_LOG_QUIET) + severity = E_SPAM; + else + severity = E_LOG; + + vlogger(severity, L_FFMPEG, fmt, ap); +} + void logger_libevent(int severity, const char *msg) { diff --git a/src/logger.h b/src/logger.h index 932108df..7002e6db 100644 --- a/src/logger.h +++ b/src/logger.h @@ -38,6 +38,9 @@ vlogger(int severity, int domain, const char *fmt, va_list args); void DPRINTF(int severity, int domain, const char *fmt, ...) __attribute__((format(printf, 3, 4))); +void +logger_ffmpeg(void *ptr, int level, const char *fmt, va_list ap); + void logger_libevent(int severity, const char *msg); diff --git a/src/main.c b/src/main.c index 2ac11c49..f7c2a49f 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -555,6 +556,7 @@ main(int argc, char **argv) /* Initialize ffmpeg */ av_register_all(); + av_log_set_callback(logger_ffmpeg); /* Initialize libgcrypt */ gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);