From fb4a78fcb73a8a97b3a4ab68989657d1302844e6 Mon Sep 17 00:00:00 2001 From: Alexander Prikhodko Date: Wed, 7 Apr 2010 12:36:28 +0300 Subject: [PATCH] Support x264_log ouputting to file --log-file and --log-file-level options --- common/common.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ x264.c | 5 +++++ x264.h | 2 ++ 3 files changed, 51 insertions(+), 0 deletions(-) diff --git a/common/common.c b/common/common.c index 6f287f6..06b2dc1 100644 --- a/common/common.c +++ b/common/common.c @@ -32,6 +32,7 @@ #endif static void x264_log_default( void *, int, const char *, va_list ); +static void x264_log_file( char *, int, const char *, va_list ); /**************************************************************************** * x264_param_default: @@ -117,6 +118,7 @@ void x264_param_default( x264_param_t *param ) param->pf_log = x264_log_default; param->p_log_private = NULL; param->i_log_level = X264_LOG_INFO; + param->i_log_file_level = X264_LOG_INFO; /* */ param->analyse.intra = X264_ANALYSE_I4x4 | X264_ANALYSE_I8x8; @@ -776,6 +778,10 @@ int x264_param_parse( x264_param_t *p, const char *name, const char *value ) } OPT("log") p->i_log_level = atoi(value); + OPT("log-file") + p->psz_log_file = strdup(value); + OPT("log-file-level") + p->i_log_file_level = x264_clip3( atoi(value), -1, 3 ); #ifdef HAVE_VISUALIZE OPT("visualize") p->b_visualize = atobool(value); @@ -960,6 +966,44 @@ void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... ) h->param.pf_log( h->param.p_log_private, i_level, psz_fmt, arg ); va_end( arg ); } + + if( h && h->param.psz_log_file && i_level <= h->param.i_log_file_level ) + { + va_list arg; + va_start( arg, psz_fmt ); + x264_log_file( h->param.psz_log_file, i_level, psz_fmt, arg ); + va_end( arg ); + } +} + +static void x264_log_file( char *p_file_name, int i_level, const char *psz_fmt, va_list arg ) +{ + char *psz_prefix; + switch( i_level ) + { + case X264_LOG_ERROR: + psz_prefix = "error"; + break; + case X264_LOG_WARNING: + psz_prefix = "warning"; + break; + case X264_LOG_INFO: + psz_prefix = "info"; + break; + case X264_LOG_DEBUG: + psz_prefix = "debug"; + break; + default: + psz_prefix = "unknown"; + break; + } + FILE *p_log_file = fopen( p_file_name, "ab" ); + if( p_log_file ) + { + fprintf( p_log_file, "x264 [%s]: ", psz_prefix ); + vfprintf( p_log_file, psz_fmt, arg ); + fclose( p_log_file ); + } } static void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg ) diff --git a/x264.c b/x264.c index 3c12f3c..1f890ef 100644 --- a/x264.c +++ b/x264.c @@ -568,6 +568,9 @@ static void Help( x264_param_t *defaults, int longhelp ) H0( " --quiet Quiet Mode\n" ); H1( " --psnr Enable PSNR computation\n" ); H1( " --ssim Enable SSIM computation\n" ); + H0( " --log-file Save log to file\n" ); + H1( " --log-file-level Log-file level information [%d]\n", + defaults->i_log_file_level ); H1( " --threads Force a specific number of threads\n" ); H1( " --demuxer-threads Force a specific number of threads for demuxer (lavf, ffms)\n" ); H2( " --sliced-threads Low-latency but lower-efficiency threading\n" ); @@ -726,6 +729,8 @@ static struct option long_options[] = { "ssim", no_argument, NULL, 0 }, { "quiet", no_argument, NULL, OPT_QUIET }, { "verbose", no_argument, NULL, 'v' }, + { "log-file", required_argument, NULL, 0 }, + { "log-file-level", required_argument, NULL, 0 }, { "no-progress", no_argument, NULL, OPT_NOPROGRESS }, { "visualize", no_argument, NULL, OPT_VISUALIZE }, { "dump-yuv", required_argument, NULL, 0 }, diff --git a/x264.h b/x264.h index 9157d76..d1c1035 100644 --- a/x264.h +++ b/x264.h @@ -245,6 +245,8 @@ typedef struct x264_param_t void (*pf_log)( void *, int i_level, const char *psz, va_list ); void *p_log_private; int i_log_level; + int i_log_file_level; + char *psz_log_file; int b_visualize; char *psz_dump_yuv; /* filename for reconstructed frames */ -- 1.7.0.2.msysgit.0