diff -uNrp c/Makefile b/Makefile --- c/Makefile 2010-03-29 12:32:02 +0300 +++ b/Makefile 2010-03-29 12:32:47 +0300 @@ -15,7 +15,7 @@ SRCS = common/mc.c common/predict.c comm SRCCLI = x264.c input/timecode.c \ input/yuv.c input/y4m.c output/raw.c \ output/matroska.c output/matroska_ebml.c \ - output/flv.c output/flv_bytestream.c + output/flv.c output/flv_bytestream.c extras/x264loger.c SRCSO = diff -uNrp c/common/common.c b/common/common.c --- c/common/common.c 2010-03-29 12:31:59 +0300 +++ b/common/common.c 2010-03-29 12:34:18 +0300 @@ -30,8 +30,10 @@ #ifdef HAVE_MALLOC_H #include #endif +#include "extras/x264loger.h" static void x264_log_default( void *, int, const char *, va_list ); +static void x264_log_default_file( void *, int, const char *, va_list ); /**************************************************************************** * x264_param_default: @@ -117,6 +119,7 @@ void x264_param_default( x264_param_t *p 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; @@ -777,6 +780,13 @@ int x264_param_parse( x264_param_t *p, c } OPT("log") p->i_log_level = atoi(value); + OPT("log-file") + { + p->psz_log_file = strdup(value); + x264_log_init( p->psz_log_file ); + } + 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); @@ -961,6 +971,39 @@ void x264_log( x264_t *h, int i_level, c h->param.pf_log( h->param.p_log_private, i_level, psz_fmt, arg ); va_end( arg ); } + + if( !h || i_level <= h->param.i_log_file_level ) + { + va_list arg; + va_start( arg, psz_fmt ); + x264_log_default_file( NULL, i_level, psz_fmt, arg ); + va_end( arg ); + } +} + +static void x264_log_default_file( void *p_unused, 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; + } + x264_fprintf_file( stderr, "x264 [%s]: ", psz_prefix ); + x264_vfprintf_file( stderr, psz_fmt, arg ); } static void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg ) diff -uNrp c/extras/x264loger.c b/extras/x264loger.c --- c/extras/x264loger.c 1970-01-01 02:00:00 +0200 +++ b/extras/x264loger.c 2010-03-29 12:34:52 +0300 @@ -0,0 +1,81 @@ +/***************************************************************************** + * x264loger: x264 CLI full logging system + ***************************************************************************** + * Copyright (C) 2009 x264 project + * + * Authors: Alexander Prikhodko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. + *****************************************************************************/ + +#include "extras/x264loger.h" + +static char *psz_log_file = NULL; + +void x264_log_init( const char *file_name ) +{ + x264_log_done(); + psz_log_file = strdup( file_name ); +} + +void x264_log_done() +{ + if( psz_log_file ) free( psz_log_file ); + psz_log_file = NULL; +} + +int x264_vfprintf_file( FILE *f, const char *psz_fmt, va_list args ) +{ + int ret = 0; + + if( (f == stderr) && psz_log_file && *psz_log_file ) + { + FILE *f_log_file = fopen( psz_log_file, "ab" ); + vfprintf( f_log_file, psz_fmt, args ); + fclose( f_log_file ); + } + return ret; +} + +int x264_fprintf_file( FILE *f, const char *psz_fmt, ... ) +{ + va_list args; + va_start( args, psz_fmt ); + + int ret = x264_vfprintf_file( f, psz_fmt, args ); + + va_end( args ); + return ret; +} + +int x264_vfprintf( FILE *f, const char *psz_fmt, va_list args ) +{ + int ret = vfprintf( f, psz_fmt, args ); + + x264_vfprintf_file( f, psz_fmt, args ); + + return ret; +} + +int x264_fprintf( FILE *f, const char *psz_fmt, ... ) +{ + va_list args; + va_start( args, psz_fmt ); + + int ret = x264_vfprintf( f, psz_fmt, args ); + + va_end( args ); + return ret; +} diff -uNrp c/extras/x264loger.h b/extras/x264loger.h --- c/extras/x264loger.h 1970-01-01 02:00:00 +0200 +++ b/extras/x264loger.h 2010-03-29 12:35:10 +0300 @@ -0,0 +1,35 @@ +/***************************************************************************** + * x264loger: x264 CLI full logging system + ***************************************************************************** + * Copyright (C) 2009 x264 project + * + * Authors: Alexander Prikhodko + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. + *****************************************************************************/ + +#ifndef X264LOGER_H +#define X264LOGER_H + +#include "common/common.h" + +void x264_log_init( const char *file_name ); +void x264_log_done(); +int x264_vfprintf_file( FILE *f, const char *psz_fmt, va_list args ); +int x264_fprintf_file( FILE *f, const char *psz_fmt, ... ); +int x264_vfprintf( FILE *f, const char *psz_fmt, va_list args ); +int x264_fprintf( FILE *f, const char *psz_fmt, ... ); + +#endif /* X264LOGER_H */ diff -uNrp c/x264.c b/x264.c --- c/x264.c 2010-03-29 12:32:02 +0300 +++ b/x264.c 2010-03-29 12:36:48 +0300 @@ -40,6 +40,7 @@ #else #define SetConsoleTitle(t) #endif +#include "extras/x264loger.h" /* Ctrl-C handler */ static int b_ctrl_c = 0; @@ -177,6 +178,7 @@ int main( int argc, char **argv ) pthread_win32_process_detach_np(); #endif + x264_log_done(); return ret; } @@ -568,6 +570,9 @@ static void Help( x264_param_t *defaults 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" ); H2( " --sliced-threads Low-latency but lower-efficiency threading\n" ); H2( " --thread-input Run Avisynth in its own thread\n" ); @@ -723,6 +728,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 -uNrp c/x264.h b/x264.h --- c/x264.h 2010-03-29 11:48:52 +0300 +++ b/x264.h 2010-03-29 12:37:36 +0300 @@ -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 */