From 46745fd194396133a29d4737ea7177e652fea915 Mon Sep 17 00:00:00 2001 From: Alexander Prikhodko Date: Wed, 7 Apr 2010 13:14:10 +0300 Subject: [PATCH] Support log everything from CLI to file --- Makefile | 2 +- input/avs.c | 32 ++++++++++++------------ input/ffms.c | 20 +++++++------- input/lavf.c | 20 +++++++------- input/thread.c | 2 +- input/timecode.c | 34 +++++++++++++------------- input/y4m.c | 6 ++-- input/yuv.c | 2 +- muxers.h | 1 + output/avi.c | 2 +- output/flv.c | 4 +- output/mp4.c | 4 +- x264.c | 71 ++++++++++++++++++++++++++++------------------------- x264log_cli.c | 51 ++++++++++++++++++++++++++++++++++++++ x264log_cli.h | 12 +++++++++ 15 files changed, 165 insertions(+), 98 deletions(-) create mode 100644 x264log_cli.c create mode 100644 x264log_cli.h diff --git a/Makefile b/Makefile index 9deeb09..b094ad4 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \ 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 x264log_cli.c SRCSO = diff --git a/input/avs.c b/input/avs.c index 9e20665..4e932b6 100644 --- a/input/avs.c +++ b/input/avs.c @@ -124,7 +124,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c return -1; else if( !x264_is_regular_file( fh ) ) { - fprintf( stderr, "avs [error]: AVS input is incompatible with non-regular file `%s'\n", psz_filename ); + x264_fprintf( stderr, "avs [error]: AVS input is incompatible with non-regular file `%s'\n", psz_filename ); return -1; } fclose( fh ); @@ -134,13 +134,13 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c return -1; if( avs_load_library( h ) ) { - fprintf( stderr, "avs [error]: failed to load avisynth\n" ); + x264_fprintf( stderr, "avs [error]: failed to load avisynth\n" ); return -1; } h->env = h->func.avs_create_script_environment( AVS_INTERFACE_YV12 ); if( !h->env ) { - fprintf( stderr, "avs [error]: failed to initiate avisynth\n" ); + x264_fprintf( stderr, "avs [error]: failed to initiate avisynth\n" ); return -1; } AVS_Value arg = avs_new_value_string( psz_filename ); @@ -152,7 +152,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c res = h->func.avs_invoke( h->env, "Import", arg, NULL ); if( avs_is_error( res ) ) { - fprintf( stderr, "avs [error]: %s\n", avs_as_string( res ) ); + x264_fprintf( stderr, "avs [error]: %s\n", avs_as_string( res ) ); return -1; } /* check if the user is using a multi-threaded script and apply distributor if necessary. @@ -175,34 +175,34 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c int i; for( i = 0; filter[i]; i++ ) { - fprintf( stderr, "avs [info]: trying %s... ", filter[i] ); + x264_fprintf( stderr, "avs [info]: trying %s... ", filter[i] ); if( !h->func.avs_function_exists( h->env, filter[i] ) ) { - fprintf( stderr, "not found\n" ); + x264_fprintf( stderr, "not found\n" ); continue; } if( !strncasecmp( filter[i], "FFmpegSource", 12 ) ) { - fprintf( stderr, "indexing... " ); + x264_fprintf( stderr, "indexing... " ); fflush( stderr ); } res = h->func.avs_invoke( h->env, filter[i], arg, NULL ); if( !avs_is_error( res ) ) { - fprintf( stderr, "succeeded\n" ); + x264_fprintf( stderr, "succeeded\n" ); break; } - fprintf( stderr, "failed\n" ); + x264_fprintf( stderr, "failed\n" ); } if( !filter[i] ) { - fprintf( stderr, "avs [error]: unable to find source filter to open `%s'\n", psz_filename ); + x264_fprintf( stderr, "avs [error]: unable to find source filter to open `%s'\n", psz_filename ); return -1; } } if( !avs_is_clip( res ) ) { - fprintf( stderr, "avs [error]: `%s' didn't return a video clip\n", psz_filename ); + x264_fprintf( stderr, "avs [error]: `%s' didn't return a video clip\n", psz_filename ); return -1; } h->clip = h->func.avs_take_clip( res, h->env ); @@ -210,12 +210,12 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c const AVS_VideoInfo *vi = h->func.avs_get_video_info( h->clip ); if( !avs_has_video( vi ) ) { - fprintf( stderr, "avs [error]: `%s' has no video data\n", psz_filename ); + x264_fprintf( stderr, "avs [error]: `%s' has no video data\n", psz_filename ); return -1; } if( vi->width&1 || vi->height&1 ) { - fprintf( stderr, "avs [error]: input clip width or height not divisible by 2 (%dx%d)\n", + x264_fprintf( stderr, "avs [error]: input clip width or height not divisible by 2 (%dx%d)\n", vi->width, vi->height ); return -1; } @@ -224,14 +224,14 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c if( !avs_is_yv12( vi ) || avs_version >= AVS_INTERFACE_OTHER_PLANAR ) { h->func.avs_release_clip( h->clip ); - fprintf( stderr, "avs %s\n", !avs_is_yv12( vi ) ? "[warning]: converting input clip to YV12" + x264_fprintf( stderr, "avs %s\n", !avs_is_yv12( vi ) ? "[warning]: converting input clip to YV12" : "[info]: avisynth 2.6+ detected, forcing conversion to YV12" ); const char *arg_name[2] = { NULL, "interlaced" }; AVS_Value arg_arr[2] = { res, avs_new_value_bool( info->interlaced ) }; AVS_Value res2 = h->func.avs_invoke( h->env, "ConvertToYV12", avs_new_value_array( arg_arr, 2 ), arg_name ); if( avs_is_error( res2 ) ) { - fprintf( stderr, "avs [error]: couldn't convert input clip to YV12\n" ); + x264_fprintf( stderr, "avs [error]: couldn't convert input clip to YV12\n" ); return -1; } h->clip = h->func.avs_take_clip( res2, h->env ); @@ -277,7 +277,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) const char *err = h->func.avs_clip_get_error( h->clip ); if( err ) { - fprintf( stderr, "avs [error]: %s occurred while reading frame %d\n", err, i_frame ); + x264_fprintf( stderr, "avs [error]: %s occurred while reading frame %d\n", err, i_frame ); return -1; } for( int i = 0; i < 3; i++ ) diff --git a/input/ffms.c b/input/ffms.c index 6992678..0cbe7f1 100644 --- a/input/ffms.c +++ b/input/ffms.c @@ -88,24 +88,24 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c fprintf( stderr, " \r" ); if( !index ) { - fprintf( stderr, "ffms [error]: could not create index\n" ); + x264_fprintf( stderr, "ffms [error]: could not create index\n" ); return -1; } if( opt->index && FFMS_WriteIndex( opt->index, index, &e ) ) - fprintf( stderr, "ffms [warning]: could not write index file\n" ); + x264_fprintf( stderr, "ffms [warning]: could not write index file\n" ); } int trackno = FFMS_GetFirstTrackOfType( index, FFMS_TYPE_VIDEO, &e ); if( trackno < 0 ) { - fprintf( stderr, "ffms [error]: could not find video track\n" ); + x264_fprintf( stderr, "ffms [error]: could not find video track\n" ); return -1; } h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, index, opt->demuxer_threads, seekmode, &e ); if( !h->video_source ) { - fprintf( stderr, "ffms [error]: could not create video source\n" ); + x264_fprintf( stderr, "ffms [error]: could not create video source\n" ); return -1; } @@ -125,7 +125,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, 0, &e ); if( !frame ) { - fprintf( stderr, "ffms [error]: could not read frame 0\n" ); + x264_fprintf( stderr, "ffms [error]: could not read frame 0\n" ); return -1; } @@ -135,7 +135,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c info->interlaced = frame->InterlacedFrame; if( h->cur_pix_fmt != PIX_FMT_YUV420P ) - fprintf( stderr, "ffms [warning]: converting from %s to YV12\n", + x264_fprintf( stderr, "ffms [warning]: converting from %s to YV12\n", avcodec_get_pix_fmt_name( h->cur_pix_fmt ) ); /* ffms timestamps are in milliseconds. Increasing timebase denominator could cause integer overflow. @@ -173,7 +173,7 @@ static int check_swscale( ffms_hnd_t *h, const FFMS_Frame *frame, int i_frame ) if( h->scaler ) { sws_freeContext( h->scaler ); - fprintf( stderr, "ffms [warning]: stream properties changed to %dx%d, %s at frame %d \n", frame->EncodedWidth, + x264_fprintf( stderr, "ffms [warning]: stream properties changed to %dx%d, %s at frame %d \n", frame->EncodedWidth, frame->EncodedHeight, avcodec_get_pix_fmt_name( frame->EncodedPixelFormat ), i_frame ); h->cur_width = frame->EncodedWidth; h->cur_height = frame->EncodedHeight; @@ -183,7 +183,7 @@ static int check_swscale( ffms_hnd_t *h, const FFMS_Frame *frame, int i_frame ) PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL ); if( !h->scaler ) { - fprintf( stderr, "ffms [error]: could not open swscale context\n" ); + x264_fprintf( stderr, "ffms [error]: could not open swscale context\n" ); return -1; } return 0; @@ -197,7 +197,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, i_frame, &e ); if( !frame ) { - fprintf( stderr, "ffms [error]: could not read frame %d\n", i_frame ); + x264_fprintf( stderr, "ffms [error]: could not read frame %d\n", i_frame ); return -1; } @@ -216,7 +216,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) { if( info->PTS == AV_NOPTS_VALUE ) { - fprintf( stderr, "ffms [error]: invalid timestamp. " + x264_fprintf( stderr, "ffms [error]: invalid timestamp. " "Use --force-cfr and specify a framerate with --fps\n" ); return -1; } diff --git a/input/lavf.c b/input/lavf.c index 15d9e72..fab6eca 100644 --- a/input/lavf.c +++ b/input/lavf.c @@ -59,7 +59,7 @@ static int check_swscale( lavf_hnd_t *h, AVCodecContext *c, int i_frame ) if( h->scaler ) { sws_freeContext( h->scaler ); - fprintf( stderr, "lavf [warning]: stream properties changed to %dx%d, %s at frame %d \n", + x264_fprintf( stderr, "lavf [warning]: stream properties changed to %dx%d, %s at frame %d \n", c->width, c->height, avcodec_get_pix_fmt_name( c->pix_fmt ), i_frame ); h->cur_width = c->width; h->cur_height = c->height; @@ -69,7 +69,7 @@ static int check_swscale( lavf_hnd_t *h, AVCodecContext *c, int i_frame ) PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL ); if( !h->scaler ) { - fprintf( stderr, "lavf [error]: could not open swscale context\n" ); + x264_fprintf( stderr, "lavf [error]: could not open swscale context\n" ); return -1; } return 0; @@ -106,12 +106,12 @@ static int read_frame_internal( x264_picture_t *p_pic, lavf_hnd_t *h, int i_fram { c->reordered_opaque = pkt->pts; if( avcodec_decode_video2( c, frame, &finished, pkt ) < 0 ) - fprintf( stderr, "lavf [warning]: video decoding failed on frame %d\n", h->next_frame ); + x264_fprintf( stderr, "lavf [warning]: video decoding failed on frame %d\n", h->next_frame ); } if( !finished ) { if( avcodec_decode_video2( c, frame, &finished, pkt ) < 0 ) - fprintf( stderr, "lavf [warning]: video decoding failed on frame %d\n", h->next_frame ); + x264_fprintf( stderr, "lavf [warning]: video decoding failed on frame %d\n", h->next_frame ); if( !finished ) return -1; } @@ -165,13 +165,13 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c if( av_open_input_file( &h->lavf, psz_filename, NULL, 0, NULL ) ) { - fprintf( stderr, "lavf [error]: could not open input file\n" ); + x264_fprintf( stderr, "lavf [error]: could not open input file\n" ); return -1; } if( av_find_stream_info( h->lavf ) < 0 ) { - fprintf( stderr, "lavf [error]: could not find input stream info\n" ); + x264_fprintf( stderr, "lavf [error]: could not find input stream info\n" ); return -1; } @@ -180,7 +180,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c i++; if( i == h->lavf->nb_streams ) { - fprintf( stderr, "lavf [error]: could not find video stream\n" ); + x264_fprintf( stderr, "lavf [error]: could not find video stream\n" ); return -1; } h->stream_id = i; @@ -204,7 +204,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c info->csp |= X264_CSP_VFLIP; if( h->cur_pix_fmt != PIX_FMT_YUV420P ) - fprintf( stderr, "lavf [warning]: converting from %s to YV12\n", + x264_fprintf( stderr, "lavf [warning]: converting from %s to YV12\n", avcodec_get_pix_fmt_name( h->cur_pix_fmt ) ); if( opt->demuxer_threads > 1 ) @@ -213,7 +213,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c if( avcodec_open( c, avcodec_find_decoder( c->codec_id ) ) ) { - fprintf( stderr, "lavf [error]: could not find decoder for video stream\n" ); + x264_fprintf( stderr, "lavf [error]: could not find decoder for video stream\n" ); return -1; } @@ -221,7 +221,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c h->first_pic = malloc( sizeof(x264_picture_t) ); if( !h->first_pic || lavf_input.picture_alloc( h->first_pic, info->csp, info->width, info->height ) ) { - fprintf( stderr, "lavf [error]: malloc failed\n" ); + x264_fprintf( stderr, "lavf [error]: malloc failed\n" ); return -1; } else if( read_frame_internal( h->first_pic, h, 0, info ) ) diff --git a/input/thread.c b/input/thread.c index a88cfae..4272230 100644 --- a/input/thread.c +++ b/input/thread.c @@ -50,7 +50,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c thread_hnd_t *h = malloc( sizeof(thread_hnd_t) ); if( !h || input.picture_alloc( &h->pic, info->csp, info->width, info->height ) ) { - fprintf( stderr, "x264 [error]: malloc failed\n" ); + x264_fprintf( stderr, "x264 [error]: malloc failed\n" ); return -1; } h->input = input; diff --git a/input/timecode.c b/input/timecode.c index 4a369ee..0df7bea 100644 --- a/input/timecode.c +++ b/input/timecode.c @@ -63,7 +63,7 @@ static double correct_fps( double fps, timecode_hnd_t *h ) fps_num = round( fps_den * fps_sig ) * exponent; if( fps_num < 0 ) { - fprintf( stderr, "timecode [error]: tcfile fps correction failed.\n" + x264_fprintf( stderr, "timecode [error]: tcfile fps correction failed.\n" " Specify an appropriate timebase manually or remake tcfile.\n" ); return -1; } @@ -93,7 +93,7 @@ static int try_mkv_timebase_den( double *fpss, timecode_hnd_t *h, int loop_num ) h->timebase_num = fps_den > 0 && h->timebase_num ? gcd( h->timebase_num, fps_den ) : fps_den; if( h->timebase_num <= 0 ) { - fprintf( stderr, "timecode [error]: automatic timebase generation failed.\n" + x264_fprintf( stderr, "timecode [error]: automatic timebase generation failed.\n" " Specify timebase manually.\n" ); return -1; } @@ -112,7 +112,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info ret = fscanf( tcfile_in, "# timecode format v%d", &tcfv ); if( ret != 1 || (tcfv != 1 && tcfv != 2) ) { - fprintf( stderr, "timecode [error]: unsupported timecode format\n" ); + x264_fprintf( stderr, "timecode [error]: unsupported timecode format\n" ); return -1; } @@ -130,14 +130,14 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info continue; if( sscanf( buff, "assume %lf", &h->assume_fps ) != 1 && sscanf( buff, "Assume %lf", &h->assume_fps ) != 1 ) { - fprintf( stderr, "timecode [error]: tcfile parsing error: assumed fps not found\n" ); + x264_fprintf( stderr, "timecode [error]: tcfile parsing error: assumed fps not found\n" ); return -1; } break; } if( h->assume_fps <= 0 ) { - fprintf( stderr, "timecode [error]: invalid assumed fps %.6f\n", h->assume_fps ); + x264_fprintf( stderr, "timecode [error]: invalid assumed fps %.6f\n", h->assume_fps ); return -1; } @@ -154,12 +154,12 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info ret = sscanf( buff, "%d,%d,%lf", &start, &end, &seq_fps ); if( ret != 3 && ret != EOF ) { - fprintf( stderr, "timecode [error]: invalid input tcfile\n" ); + x264_fprintf( stderr, "timecode [error]: invalid input tcfile\n" ); return -1; } if( start > end || start <= prev_start || end <= prev_end || seq_fps <= 0 ) { - fprintf( stderr, "timecode [error]: invalid input tcfile at line %d: %s\n", num, buff ); + x264_fprintf( stderr, "timecode [error]: invalid input tcfile at line %d: %s\n", num, buff ); return -1; } prev_start = start; @@ -258,7 +258,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info timecodes_num = h->stored_pts_num + h->seek; if( !timecodes_num ) { - fprintf( stderr, "timecode [error]: input tcfile doesn't have any timecodes!\n" ); + x264_fprintf( stderr, "timecode [error]: input tcfile doesn't have any timecodes!\n" ); return -1; } fseek( tcfile_in, file_pos, SEEK_SET ); @@ -271,7 +271,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info ret = sscanf( buff, "%lf", &timecodes[0] ); if( ret != 1 ) { - fprintf( stderr, "timecode [error]: invalid input tcfile for frame 0\n" ); + x264_fprintf( stderr, "timecode [error]: invalid input tcfile for frame 0\n" ); goto fail; } for( num = 1; num < timecodes_num; ) @@ -283,7 +283,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info timecodes[num] *= 1e-3; /* Timecode format v2 is expressed in milliseconds. */ if( ret != 1 || timecodes[num] <= timecodes[num - 1] ) { - fprintf( stderr, "timecode [error]: invalid input tcfile for frame %d\n", num ); + x264_fprintf( stderr, "timecode [error]: invalid input tcfile for frame %d\n", num ); goto fail; } ++num; @@ -337,11 +337,11 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info if( h->auto_timebase_den || h->auto_timebase_num ) { x264_reduce_fraction( &h->timebase_num, &h->timebase_den ); - fprintf( stderr, "timecode [info]: automatic timebase generation %d/%d\n", h->timebase_num, h->timebase_den ); + x264_fprintf( stderr, "timecode [info]: automatic timebase generation %d/%d\n", h->timebase_num, h->timebase_den ); } else if( h->timebase_den <= 0 ) { - fprintf( stderr, "timecode [error]: automatic timebase generation failed.\n" + x264_fprintf( stderr, "timecode [error]: automatic timebase generation failed.\n" " Specify an appropriate timebase manually.\n" ); goto fail; } @@ -357,7 +357,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info h->pts[num] -= pts_seek_offset; if( h->pts[num] <= h->pts[num - 1] ) { - fprintf( stderr, "timecode [error]: invalid timebase or timecode for frame %d\n", num ); + x264_fprintf( stderr, "timecode [error]: invalid timebase or timecode for frame %d\n", num ); goto fail; } } @@ -383,7 +383,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c timecode_hnd_t *h = malloc( sizeof(timecode_hnd_t) ); if( !h ) { - fprintf( stderr, "timecode [error]: malloc failed\n" ); + x264_fprintf( stderr, "timecode [error]: malloc failed\n" ); return -1; } h->input = input; @@ -408,12 +408,12 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c tcfile_in = fopen( psz_filename, "rb" ); if( !tcfile_in ) { - fprintf( stderr, "timecode [error]: can't open `%s'\n", psz_filename ); + x264_fprintf( stderr, "timecode [error]: can't open `%s'\n", psz_filename ); return -1; } else if( !x264_is_regular_file( tcfile_in ) ) { - fprintf( stderr, "timecode [error]: tcfile input incompatible with non-regular file `%s'\n", psz_filename ); + x264_fprintf( stderr, "timecode [error]: tcfile input incompatible with non-regular file `%s'\n", psz_filename ); fclose( tcfile_in ); return -1; } @@ -454,7 +454,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame ) { if( h->pts ) { - fprintf( stderr, "timecode [info]: input timecode file missing data for frame %d and later\n" + x264_fprintf( stderr, "timecode [info]: input timecode file missing data for frame %d and later\n" " assuming constant fps %.6f\n", i_frame, h->assume_fps ); free( h->pts ); h->pts = NULL; diff --git a/input/y4m.c b/input/y4m.c index c34f264..1506bbc 100644 --- a/input/y4m.c +++ b/input/y4m.c @@ -155,7 +155,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c if( colorspace != X264_CSP_I420 ) { - fprintf( stderr, "y4m [error]: colorspace unhandled\n" ); + x264_fprintf( stderr, "y4m [error]: colorspace unhandled\n" ); return -1; } @@ -195,7 +195,7 @@ static int read_frame_internal( x264_picture_t *p_pic, y4m_hnd_t *h ) header[slen] = 0; if( strncmp( header, Y4M_FRAME_MAGIC, slen ) ) { - fprintf( stderr, "y4m [error]: bad header magic (%"PRIx32" <=> %s)\n", + x264_fprintf( stderr, "y4m [error]: bad header magic (%"PRIx32" <=> %s)\n", M32(header), header ); return -1; } @@ -205,7 +205,7 @@ static int read_frame_internal( x264_picture_t *p_pic, y4m_hnd_t *h ) i++; if( i == MAX_FRAME_HEADER ) { - fprintf( stderr, "y4m [error]: bad frame header!\n" ); + x264_fprintf( stderr, "y4m [error]: bad frame header!\n" ); return -1; } h->frame_header_len = i+slen+1; diff --git a/input/yuv.c b/input/yuv.c index cbed7fc..7c6b56d 100644 --- a/input/yuv.c +++ b/input/yuv.c @@ -47,7 +47,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c sscanf( opt->resolution, "%ux%u", &info->width, &info->height ); if( !info->width || !info->height ) { - fprintf( stderr, "yuv [error]: rawyuv input requires a resolution.\n" ); + x264_fprintf( stderr, "yuv [error]: rawyuv input requires a resolution.\n" ); return -1; } diff --git a/muxers.h b/muxers.h index b309320..4bae08b 100644 --- a/muxers.h +++ b/muxers.h @@ -55,6 +55,7 @@ static inline char *get_filename_extension( char *filename ) return ext; } +#include "x264log_cli.h" #include "input/input.h" #include "output/output.h" diff --git a/output/avi.c b/output/avi.c index f88291f..da7475c 100644 --- a/output/avi.c +++ b/output/avi.c @@ -79,7 +79,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle ) return -1; else if( !x264_is_regular_file( fh ) ) { - fprintf( stderr, "avi [error]: AVI output is incompatible with non-regular file `%s'\n", psz_filename ); + x264_fprintf( stderr, "avi [error]: AVI output is incompatible with non-regular file `%s'\n", psz_filename ); return -1; } fclose( fh ); diff --git a/output/flv.c b/output/flv.c index 04f4428..d024906 100644 --- a/output/flv.c +++ b/output/flv.c @@ -223,13 +223,13 @@ static int write_frame( hnd_t handle, uint8_t *p_nalu, int i_size, x264_picture_ if( prev_dts == dts ) { double fps = ((double)p_flv->i_timebase_den / p_flv->i_timebase_num) / (p_picture->i_dts - p_flv->i_prev_dts); - fprintf( stderr, "flv [warning]: duplicate DTS %"PRId64" generated by rounding\n" + x264_fprintf( stderr, "flv [warning]: duplicate DTS %"PRId64" generated by rounding\n" " current internal decoding framerate: %.6f fps\n", dts, fps ); } if( prev_cts == cts ) { double fps = ((double)p_flv->i_timebase_den / p_flv->i_timebase_num) / (p_picture->i_pts - p_flv->i_prev_pts); - fprintf( stderr, "flv [warning]: duplicate CTS %"PRId64" generated by rounding\n" + x264_fprintf( stderr, "flv [warning]: duplicate CTS %"PRId64" generated by rounding\n" " current internal composition framerate: %.6f fps\n", cts, fps ); } } diff --git a/output/mp4.c b/output/mp4.c index cbe9f5c..539ca35 100644 --- a/output/mp4.c +++ b/output/mp4.c @@ -66,7 +66,7 @@ static void recompute_bitrate_mp4( GF_ISOFile *p_file, int i_track ) GF_ISOSample *samp = gf_isom_get_sample_info( p_file, i_track, i+1, &di, &offset ); if( !samp ) { - fprintf( stderr, "mp4 [error]: failure reading back frame %u\n", i ); + x264_fprintf( stderr, "mp4 [error]: failure reading back frame %u\n", i ); break; } @@ -164,7 +164,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle ) return -1; else if( !x264_is_regular_file( fh ) ) { - fprintf( stderr, "mp4 [error]: MP4 output is incompatible with non-regular file `%s'\n", psz_filename ); + x264_fprintf( stderr, "mp4 [error]: MP4 output is incompatible with non-regular file `%s'\n", psz_filename ); return -1; } fclose( fh ); diff --git a/x264.c b/x264.c index 1f890ef..2a5986a 100644 --- a/x264.c +++ b/x264.c @@ -177,6 +177,7 @@ int main( int argc, char **argv ) pthread_win32_process_detach_np(); #endif + x264_log_done(); return ret; } @@ -781,11 +782,11 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param param->b_repeat_headers = 0; if( param->i_nal_hrd == X264_NAL_HRD_CBR ) { - fprintf( stderr, "x264 [warning]: cbr nal-hrd is not compatible with mp4\n" ); + x264_fprintf( stderr, "x264 [warning]: cbr nal-hrd is not compatible with mp4\n" ); param->i_nal_hrd = X264_NAL_HRD_VBR; } #else - fprintf( stderr, "x264 [error]: not compiled with MP4 output support\n" ); + x264_fprintf( stderr, "x264 [error]: not compiled with MP4 output support\n" ); return -1; #endif } @@ -812,11 +813,11 @@ static int select_output( const char *muxer, char *filename, x264_param_t *param param->b_repeat_headers = 1; if( param->b_vfr_input ) { - fprintf( stderr, "x264 [warning]: VFR is not compatible with AVI output\n" ); + x264_fprintf( stderr, "x264 [warning]: VFR is not compatible with AVI output\n" ); param->b_vfr_input = 0; } #else - fprintf( stderr, "x264 [error]: not compiled with AVI output support\n" ); + x264_fprintf( stderr, "x264 [error]: not compiled with AVI output support\n" ); return -1; #endif } @@ -850,7 +851,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename input = avs_input; module = "avs"; #else - fprintf( stderr, "x264 [error]: not compiled with AVS input support\n" ); + x264_fprintf( stderr, "x264 [error]: not compiled with AVS input support\n" ); return -1; #endif } @@ -896,7 +897,7 @@ static int select_input( const char *demuxer, char *used_demuxer, char *filename if( !(*p_handle) ) { - fprintf( stderr, "x264 [error]: could not open input file `%s' via any method!\n", filename ); + x264_fprintf( stderr, "x264 [error]: could not open input file `%s' via any method!\n", filename ); return -1; } } @@ -1036,12 +1037,12 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) opt->qpfile = fopen( optarg, "rb" ); if( !opt->qpfile ) { - fprintf( stderr, "x264 [error]: can't open qpfile `%s'\n", optarg ); + x264_fprintf( stderr, "x264 [error]: can't open qpfile `%s'\n", optarg ); return -1; } else if( !x264_is_regular_file( opt->qpfile ) ) { - fprintf( stderr, "x264 [error]: qpfile incompatible with non-regular file `%s'\n", optarg ); + x264_fprintf( stderr, "x264 [error]: qpfile incompatible with non-regular file `%s'\n", optarg ); fclose( opt->qpfile ); return -1; } @@ -1066,7 +1067,7 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) param->b_visualize = 1; b_exit_on_ctrl_c = 1; #else - fprintf( stderr, "x264 [warning]: not compiled with visualization support\n" ); + x264_fprintf( stderr, "x264 [warning]: not compiled with visualization support\n" ); #endif break; case OPT_TUNE: @@ -1095,7 +1096,7 @@ static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ) opt->tcfile_out = fopen( optarg, "wb" ); if( !opt->tcfile_out ) { - fprintf( stderr, "x264 [error]: can't open `%s'\n", optarg ); + x264_fprintf( stderr, "x264 [error]: can't open `%s'\n", optarg ); return -1; } break; @@ -1125,13 +1126,15 @@ generic_option: } b_error |= x264_param_parse( param, long_options[long_options_index].name, optarg ); + if( !strcmp( long_options[long_options_index].name, "log-file" ) ) + x264_log_init(optarg); } } if( b_error ) { const char *name = long_options_index > 0 ? long_options[long_options_index].name : argv[optind-2]; - fprintf( stderr, "x264 [error]: invalid argument: %s = %s\n", name, optarg ); + x264_fprintf( stderr, "x264 [error]: invalid argument: %s = %s\n", name, optarg ); return -1; } } @@ -1147,7 +1150,7 @@ generic_option: /* Get the file name */ if( optind > argc - 1 || !output_filename ) { - fprintf( stderr, "x264 [error]: No %s file. Run x264 --help for a list of options.\n", + x264_fprintf( stderr, "x264 [error]: No %s file. Run x264 --help for a list of options.\n", optind > argc - 1 ? "input" : "output" ); return -1; } @@ -1156,7 +1159,7 @@ generic_option: return -1; if( output.open_file( output_filename, &opt->hout ) ) { - fprintf( stderr, "x264 [error]: could not open output file `%s'\n", output_filename ); + x264_fprintf( stderr, "x264 [error]: could not open output file `%s'\n", output_filename ); return -1; } @@ -1180,14 +1183,14 @@ generic_option: if( !opt->hin && input.open_file( input_filename, &opt->hin, &info, &input_opt ) ) { - fprintf( stderr, "x264 [error]: could not open input file `%s'\n", input_filename ); + x264_fprintf( stderr, "x264 [error]: could not open input file `%s'\n", input_filename ); return -1; } x264_reduce_fraction( &info.sar_width, &info.sar_height ); x264_reduce_fraction( &info.fps_num, &info.fps_den ); if( param->i_log_level >= X264_LOG_INFO ) - fprintf( stderr, "%s [info]: %dx%d%c %d:%d @ %d/%d fps (%cfr)\n", demuxername, info.width, + x264_fprintf( stderr, "%s [info]: %dx%d%c %d:%d @ %d/%d fps (%cfr)\n", demuxername, info.width, info.height, info.interlaced ? 'i' : 'p', info.sar_width, info.sar_height, info.fps_num, info.fps_den, info.vfr ? 'v' : 'c' ); @@ -1195,12 +1198,12 @@ generic_option: { if( b_user_fps ) { - fprintf( stderr, "x264 [error]: --fps + --tcfile-in is incompatible.\n" ); + x264_fprintf( stderr, "x264 [error]: --fps + --tcfile-in is incompatible.\n" ); return -1; } if( timecode_input.open_file( tcfile_name, &opt->hin, &info, &input_opt ) ) { - fprintf( stderr, "x264 [error]: timecode input failed\n" ); + x264_fprintf( stderr, "x264 [error]: timecode input failed\n" ); return -1; } else @@ -1208,7 +1211,7 @@ generic_option: } else if( !info.vfr && input_opt.timebase ) { - fprintf( stderr, "x264 [error]: --timebase is incompatible with cfr input\n" ); + x264_fprintf( stderr, "x264 [error]: --timebase is incompatible with cfr input\n" ); return -1; } @@ -1219,7 +1222,7 @@ generic_option: param->i_width = info.width; if( !b_user_interlaced && info.interlaced ) { - fprintf( stderr, "x264 [warning]: input appears to be interlaced, enabling interlaced mode.\n" + x264_fprintf( stderr, "x264 [warning]: input appears to be interlaced, enabling interlaced mode.\n" " If you want otherwise, use --no-interlaced\n" ); param->b_interlaced = 1; } @@ -1245,7 +1248,7 @@ generic_option: int ret = sscanf( input_opt.timebase, "%d/%d", &i_user_timebase_num, &i_user_timebase_den ); if( !ret ) { - fprintf( stderr, "x264 [error]: invalid argument: timebase = %s\n", input_opt.timebase ); + x264_fprintf( stderr, "x264 [error]: invalid argument: timebase = %s\n", input_opt.timebase ); return -1; } else if( ret == 1 ) @@ -1271,7 +1274,7 @@ generic_option: { if( thread_input.open_file( NULL, &opt->hin, &info, NULL ) ) { - fprintf( stderr, "x264 [error]: threaded input failed\n" ); + x264_fprintf( stderr, "x264 [error]: threaded input failed\n" ); return -1; } else @@ -1328,7 +1331,7 @@ static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame ) else ret = 0; if( ret != 3 || qp < -1 || qp > 51 ) { - fprintf( stderr, "x264 [error]: can't parse qpfile for frame %d\n", i_frame ); + x264_fprintf( stderr, "x264 [error]: can't parse qpfile for frame %d\n", i_frame ); fclose( opt->qpfile ); opt->qpfile = NULL; pic->i_type = X264_TYPE_AUTO; @@ -1353,7 +1356,7 @@ static int Encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic, int64_t *l if( i_frame_size < 0 ) { - fprintf( stderr, "x264 [error]: x264_encoder_encode failed\n" ); + x264_fprintf( stderr, "x264 [error]: x264_encoder_encode failed\n" ); return -1; } @@ -1427,7 +1430,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) param->i_timebase_num = param->i_fps_den; if( fmod( param->i_fps_num * pulldown->fps_factor, 1 ) ) { - fprintf( stderr, "x264 [error]: unsupported framerate for chosen pulldown\n" ); + x264_fprintf( stderr, "x264 [error]: unsupported framerate for chosen pulldown\n" ); return -1; } param->i_timebase_den = param->i_fps_num * pulldown->fps_factor; @@ -1435,7 +1438,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) if( ( h = x264_encoder_open( param ) ) == NULL ) { - fprintf( stderr, "x264 [error]: x264_encoder_open failed\n" ); + x264_fprintf( stderr, "x264 [error]: x264_encoder_open failed\n" ); input.close_file( opt->hin ); return -1; } @@ -1446,7 +1449,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) if( output.set_param( opt->hout, param ) ) { - fprintf( stderr, "x264 [error]: can't set outfile param\n" ); + x264_fprintf( stderr, "x264 [error]: can't set outfile param\n" ); input.close_file( opt->hin ); output.close_file( opt->hout, largest_pts, second_largest_pts ); return -1; @@ -1455,7 +1458,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) /* Create a new pic */ if( input.picture_alloc( &pic, param->i_csp, param->i_width, param->i_height ) ) { - fprintf( stderr, "x264 [error]: malloc failed\n" ); + x264_fprintf( stderr, "x264 [error]: malloc failed\n" ); return -1; } @@ -1464,7 +1467,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) ticks_per_frame = (int64_t)param->i_timebase_den * param->i_fps_den / param->i_timebase_num / param->i_fps_num; if( ticks_per_frame < 1 ) { - fprintf( stderr, "x264 [error]: ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame ); + x264_fprintf( stderr, "x264 [error]: ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame ); return -1; } @@ -1476,7 +1479,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) if( x264_encoder_headers( h, &headers, &i_nal ) < 0 ) { - fprintf( stderr, "x264 [error]: x264_encoder_headers failed\n" ); + x264_fprintf( stderr, "x264 [error]: x264_encoder_headers failed\n" ); return -1; } @@ -1512,10 +1515,10 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) if( param->i_log_level >= X264_LOG_WARNING ) { if( param->i_log_level >= X264_LOG_DEBUG || pts_warning_cnt < MAX_PTS_WARNING ) - fprintf( stderr, "x264 [warning]: non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n", + x264_fprintf( stderr, "x264 [warning]: non-strictly-monotonic pts at frame %d (%"PRId64" <= %"PRId64")\n", i_frame, output_pts, largest_pts * dts_compress_multiplier ); else if( pts_warning_cnt == MAX_PTS_WARNING ) - fprintf( stderr, "x264 [warning]: too many nonmonotonic pts warnings, suppressing further ones\n" ); + x264_fprintf( stderr, "x264 [warning]: too many nonmonotonic pts warnings, suppressing further ones\n" ); pts_warning_cnt++; } pic.i_pts = largest_pts + ticks_per_frame; @@ -1565,7 +1568,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) Print_status( i_start, i_frame_output, i_frame_total, i_file, param, last_pts ); } if( pts_warning_cnt >= MAX_PTS_WARNING && param->i_log_level < X264_LOG_DEBUG ) - fprintf( stderr, "x264 [warning]: %d suppressed nonmonotonic pts warnings\n", pts_warning_cnt-MAX_PTS_WARNING ); + x264_fprintf( stderr, "x264 [warning]: %d suppressed nonmonotonic pts warnings\n", pts_warning_cnt-MAX_PTS_WARNING ); /* duration algorithm fails when only 1 frame is output */ if( i_frame_output == 1 ) @@ -1584,7 +1587,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) fprintf( stderr, "\n" ); if( b_ctrl_c ) - fprintf( stderr, "aborted at input frame %d, output frame %d\n", opt->i_seek + i_frame, i_frame_output ); + x264_fprintf( stderr, "aborted at input frame %d, output frame %d\n", opt->i_seek + i_frame, i_frame_output ); if( opt->tcfile_out ) { @@ -1600,7 +1603,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) double fps = (double)i_frame_output * (double)1000000 / (double)( i_end - i_start ); - fprintf( stderr, "encoded %d frames, %.2f fps, %.2f kb/s\n", i_frame_output, fps, + x264_fprintf( stderr, "encoded %d frames, %.2f fps, %.2f kb/s\n", i_frame_output, fps, (double) i_file * 8 / ( 1000 * duration ) ); } diff --git a/x264log_cli.c b/x264log_cli.c new file mode 100644 index 0000000..08600e9 --- /dev/null +++ b/x264log_cli.c @@ -0,0 +1,51 @@ +#include "x264log_cli.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" ); + if( f_log_file ) + { + vfprintf( f_log_file, psz_fmt, args ); + fclose( f_log_file ); + } + } + 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 --git a/x264log_cli.h b/x264log_cli.h new file mode 100644 index 0000000..b135981 --- /dev/null +++ b/x264log_cli.h @@ -0,0 +1,12 @@ +#ifndef X264LOG_CLI_H +#define X264LOG_CLI_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_vfprintf( FILE *f, const char *psz_fmt, va_list args ); +int x264_fprintf( FILE *f, const char *psz_fmt, ... ); + +#endif /* X264LOG_CLI_H */ -- 1.7.0.2.msysgit.0