Commit 43a43346 authored by Steven Walters's avatar Steven Walters Committed by Fiona Glaser

Centralize logging within x264cli

x264cli messages will now respect the log level they pertain to.
Slightly reduces binary size.
parent 899bf0fd
......@@ -20,8 +20,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "muxers.h"
#include "input.h"
#include <windows.h>
#define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "avs", __VA_ARGS__ )
/* the AVS interface currently uses __declspec to link function declarations to their definitions in the dll.
this has a side effect of preventing program execution if the avisynth dll is not found,
......@@ -131,27 +132,15 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
FILE *fh = fopen( psz_filename, "r" );
if( !fh )
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 );
return -1;
}
FAIL_IF_ERROR( !x264_is_regular_file( fh ), "AVS input is incompatible with non-regular file `%s'\n", psz_filename );
fclose( fh );
avs_hnd_t *h = malloc( sizeof(avs_hnd_t) );
if( !h )
return -1;
if( avs_load_library( h ) )
{
fprintf( stderr, "avs [error]: failed to load avisynth\n" );
return -1;
}
FAIL_IF_ERROR( avs_load_library( h ), "failed to load avisynth\n" )
h->env = h->func.avs_create_script_environment( AVS_INTERFACE_YV12 );
if( !h->env )
{
fprintf( stderr, "avs [error]: failed to initiate avisynth\n" );
return -1;
}
FAIL_IF_ERROR( !h->env, "failed to initiate avisynth\n" )
AVS_Value arg = avs_new_value_string( psz_filename );
AVS_Value res;
char *filename_ext = get_filename_extension( psz_filename );
......@@ -159,11 +148,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
if( !strcasecmp( filename_ext, "avs" ) )
{
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 ) );
return -1;
}
FAIL_IF_ERROR( avs_is_error( res ), "%s\n", avs_as_string( res ) )
/* check if the user is using a multi-threaded script and apply distributor if necessary.
adapted from avisynth's vfw interface */
AVS_Value mt_test = h->func.avs_invoke( h->env, "GetMTMode", avs_new_value_bool( 0 ), NULL );
......@@ -184,78 +169,55 @@ 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_cli_log( "avs", X264_LOG_INFO, "trying %s... ", filter[i] );
if( !h->func.avs_function_exists( h->env, filter[i] ) )
{
fprintf( stderr, "not found\n" );
x264_cli_printf( X264_LOG_INFO, "not found\n" );
continue;
}
if( !strncasecmp( filter[i], "FFmpegSource", 12 ) )
{
fprintf( stderr, "indexing... " );
x264_cli_printf( X264_LOG_INFO, "indexing... " );
fflush( stderr );
}
res = h->func.avs_invoke( h->env, filter[i], arg, NULL );
if( !avs_is_error( res ) )
{
fprintf( stderr, "succeeded\n" );
x264_cli_printf( X264_LOG_INFO, "succeeded\n" );
break;
}
fprintf( stderr, "failed\n" );
}
if( !filter[i] )
{
fprintf( stderr, "avs [error]: unable to find source filter to open `%s'\n", psz_filename );
return -1;
x264_cli_printf( X264_LOG_INFO, "failed\n" );
}
FAIL_IF_ERROR( !filter[i], "unable to find source filter to open `%s'\n", psz_filename )
}
if( !avs_is_clip( res ) )
{
fprintf( stderr, "avs [error]: `%s' didn't return a video clip\n", psz_filename );
return -1;
}
FAIL_IF_ERROR( !avs_is_clip( res ), "`%s' didn't return a video clip\n", psz_filename )
h->clip = h->func.avs_take_clip( res, h->env );
int avs_version = h->func.avs_get_version( h->clip );
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 );
return -1;
}
FAIL_IF_ERROR( !avs_has_video( vi ), "`%s' has no video data\n", psz_filename )
/* if the clip is made of fields instead of frames, call weave to make them frames */
if( avs_is_field_based( vi ) )
{
fprintf( stderr, "avs [warning]: detected fieldbased (separated) input, weaving to frames\n" );
x264_cli_log( "avs", X264_LOG_WARNING, "detected fieldbased (separated) input, weaving to frames\n" );
AVS_Value tmp = h->func.avs_invoke( h->env, "Weave", res, NULL );
if( avs_is_error( tmp ) )
{
fprintf( stderr, "avs [error]: couldn't weave fields into frames\n" );
return -1;
}
FAIL_IF_ERROR( avs_is_error( tmp ), "couldn't weave fields into frames\n" )
res = update_clip( h, &vi, tmp, res );
info->interlaced = 1;
info->tff = avs_is_tff( vi );
}
if( vi->width&1 || vi->height&1 )
{
fprintf( stderr, "avs [error]: input clip width or height not divisible by 2 (%dx%d)\n",
vi->width, vi->height );
return -1;
}
FAIL_IF_ERROR( vi->width&1 || vi->height&1, "input clip width or height not divisible by 2 (%dx%d)\n", vi->width, vi->height )
/* always call ConvertToYV12 to convert non YV12 planar colorspaces to YV12 when user's AVS supports them,
as all planar colorspaces are flagged as YV12. If it is already YV12 in this case, the call does nothing */
if( !avs_is_yv12( vi ) || avs_version >= AVS_INTERFACE_OTHER_PLANAR )
{
fprintf( stderr, "avs %s\n", !avs_is_yv12( vi ) ? "[warning]: converting input clip to YV12"
: "[info]: avisynth 2.6+ detected, forcing conversion to YV12" );
if( !avs_is_yv12( vi ) )
x264_cli_log( "avs", X264_LOG_WARNING, "converting input clip to YV12" );
else
x264_cli_log( "avs", X264_LOG_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" );
return -1;
}
FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert input clip to YV12\n" )
res = update_clip( h, &vi, res2, res );
}
h->func.avs_release_value( res );
......@@ -294,11 +256,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame )
return -1;
AVS_VideoFrame *frm = p_pic->opaque = h->func.avs_get_frame( h->clip, 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 );
return -1;
}
FAIL_IF_ERROR( err, "%s occurred while reading frame %d\n", err, i_frame )
for( int i = 0; i < 3; i++ )
{
/* explicitly cast away the const attribute to avoid a warning */
......
......@@ -21,8 +21,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "muxers.h"
#include "input.h"
#include <ffms.h>
#define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "ffms", __VA_ARGS__ )
#undef DECLARE_ALIGNED
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
......@@ -86,28 +88,16 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
{
idx = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, update_progress, NULL, &e );
fprintf( stderr, " \r" );
if( !idx )
{
fprintf( stderr, "ffms [error]: could not create index\n" );
return -1;
}
FAIL_IF_ERROR( !idx, "could not create index\n" )
if( opt->index_file && FFMS_WriteIndex( opt->index_file, idx, &e ) )
fprintf( stderr, "ffms [warning]: could not write index file\n" );
x264_cli_log( "ffms", X264_LOG_WARNING, "could not write index file\n" );
}
int trackno = FFMS_GetFirstTrackOfType( idx, FFMS_TYPE_VIDEO, &e );
if( trackno < 0 )
{
fprintf( stderr, "ffms [error]: could not find video track\n" );
return -1;
}
FAIL_IF_ERROR( trackno < 0, "could not find video track\n" )
h->video_source = FFMS_CreateVideoSource( psz_filename, trackno, idx, 1, seekmode, &e );
if( !h->video_source )
{
fprintf( stderr, "ffms [error]: could not create video source\n" );
return -1;
}
FAIL_IF_ERROR( !h->video_source, "could not create video source\n" )
h->track = FFMS_GetTrackFromVideo( h->video_source );
......@@ -121,11 +111,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
h->vfr_input = info->vfr;
const FFMS_Frame *frame = FFMS_GetFrame( h->video_source, 0, &e );
if( !frame )
{
fprintf( stderr, "ffms [error]: could not read frame 0\n" );
return -1;
}
FAIL_IF_ERROR( !frame, "could not read frame 0\n" )
h->init_width = h->cur_width = info->width = frame->EncodedWidth;
h->init_height = h->cur_height = info->height = frame->EncodedHeight;
......@@ -134,8 +120,8 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
info->tff = frame->TopFieldFirst;
if( h->cur_pix_fmt != PIX_FMT_YUV420P )
fprintf( stderr, "ffms [warning]: converting from %s to YV12\n",
avcodec_get_pix_fmt_name( h->cur_pix_fmt ) );
x264_cli_log( "ffms", X264_LOG_WARNING, "converting from %s to YV12\n",
avcodec_get_pix_fmt_name( h->cur_pix_fmt ) );
/* ffms timestamps are in milliseconds. ffms also uses int64_ts for timebase,
* so we need to reduce large timebases to prevent overflow */
......@@ -173,19 +159,15 @@ 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,
frame->EncodedHeight, avcodec_get_pix_fmt_name( frame->EncodedPixelFormat ), i_frame );
x264_cli_log( "ffms", X264_LOG_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;
h->cur_pix_fmt = frame->EncodedPixelFormat;
}
h->scaler = sws_getContext( h->cur_width, h->cur_height, h->cur_pix_fmt, h->init_width, h->init_height,
PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL );
if( !h->scaler )
{
fprintf( stderr, "ffms [error]: could not open swscale context\n" );
return -1;
}
FAIL_IF_ERROR( !h->scaler, "could not open swscale context\n" )
return 0;
}
......@@ -195,11 +177,7 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame )
FFMS_ErrorInfo e;
e.BufferSize = 0;
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 );
return -1;
}
FAIL_IF_ERROR( !frame, "could not read frame %d\n", i_frame )
if( check_swscale( h, frame, i_frame ) )
return -1;
......@@ -214,12 +192,8 @@ static int read_frame( x264_picture_t *p_pic, hnd_t handle, int i_frame )
if( h->vfr_input )
{
if( info->PTS == AV_NOPTS_VALUE )
{
fprintf( stderr, "ffms [error]: invalid timestamp. "
"Use --force-cfr and specify a framerate with --fps\n" );
return -1;
}
FAIL_IF_ERROR( info->PTS == AV_NOPTS_VALUE, "invalid timestamp. "
"Use --force-cfr and specify a framerate with --fps\n" )
if( !h->pts_offset_flag )
{
......
......@@ -25,6 +25,8 @@
#ifndef X264_INPUT_H
#define X264_INPUT_H
#include "x264cli.h"
/* options that are used by only some demuxers */
typedef struct
{
......
......@@ -21,7 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "muxers.h"
#include "input.h"
#define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "lavf", __VA_ARGS__ )
#undef DECLARE_ALIGNED
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
......@@ -59,19 +60,15 @@ 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",
c->width, c->height, avcodec_get_pix_fmt_name( c->pix_fmt ), i_frame );
x264_cli_log( "lavf", X264_LOG_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;
h->cur_pix_fmt = c->pix_fmt;
}
h->scaler = sws_getContext( h->cur_width, h->cur_height, h->cur_pix_fmt, h->init_width, h->init_height,
PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL );
if( !h->scaler )
{
fprintf( stderr, "lavf [error]: could not open swscale context\n" );
return -1;
}
FAIL_IF_ERROR( !h->scaler, "could not open swscale context\n" )
return 0;
}
......@@ -106,12 +103,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_cli_log( "lavf", X264_LOG_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_cli_log( "lavf", X264_LOG_WARNING, "video decoding failed on frame %d\n", h->next_frame );
if( !finished )
return -1;
}
......@@ -166,26 +163,13 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
if( !strcmp( psz_filename, "-" ) )
psz_filename = "pipe:";
if( av_open_input_file( &h->lavf, psz_filename, NULL, 0, NULL ) )
{
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" );
return -1;
}
FAIL_IF_ERROR( av_open_input_file( &h->lavf, psz_filename, NULL, 0, NULL ), "could not open input file\n" )
FAIL_IF_ERROR( av_find_stream_info( h->lavf ) < 0, "could not find input stream info\n" )
int i = 0;
while( i < h->lavf->nb_streams && h->lavf->streams[i]->codec->codec_type != CODEC_TYPE_VIDEO )
i++;
if( i == h->lavf->nb_streams )
{
fprintf( stderr, "lavf [error]: could not find video stream\n" );
return -1;
}
FAIL_IF_ERROR( i == h->lavf->nb_streams, "could not find video stream\n" )
h->stream_id = i;
h->next_frame = 0;
h->pts_offset_flag = 0;
......@@ -207,22 +191,15 @@ 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",
avcodec_get_pix_fmt_name( h->cur_pix_fmt ) );
if( avcodec_open( c, avcodec_find_decoder( c->codec_id ) ) )
{
fprintf( stderr, "lavf [error]: could not find decoder for video stream\n" );
return -1;
}
x264_cli_log( "lavf", X264_LOG_WARNING, "converting from %s to YV12\n",
avcodec_get_pix_fmt_name( h->cur_pix_fmt ) );
FAIL_IF_ERROR( avcodec_open( c, avcodec_find_decoder( c->codec_id ) ),
"could not find decoder for video stream\n" )
/* prefetch the first frame and set/confirm flags */
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" );
return -1;
}
FAIL_IF_ERROR( !h->first_pic || lavf_input.picture_alloc( h->first_pic, info->csp, info->width, info->height ),
"malloc failed\n" )
else if( read_frame_internal( h->first_pic, h, 0, info ) )
return -1;
......
......@@ -21,7 +21,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "muxers.h"
#include "input.h"
extern cli_input_t input;
......@@ -47,11 +47,8 @@ typedef struct thread_input_arg_t
static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
{
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" );
return -1;
}
FAIL_IF_ERR( !h || input.picture_alloc( &h->pic, info->csp, info->width, info->height ),
"x264", "malloc failed\n" )
h->input = input;
h->p_handle = *p_handle;
h->next_frame = -1;
......
......@@ -20,7 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
*****************************************************************************/
#include "muxers.h"
#include "input.h"
#define FAIL_IF_ERROR( cond, ... ) FAIL_IF_ERR( cond, "timecode", __VA_ARGS__ )
#include <math.h>
extern cli_input_t input;
......@@ -61,12 +62,8 @@ static double correct_fps( double fps, timecode_hnd_t *h )
{
fps_den = i * h->timebase_num;
fps_num = round( fps_den * fps_sig ) * exponent;
if( fps_num > UINT32_MAX )
{
fprintf( stderr, "timecode [error]: tcfile fps correction failed.\n"
" Specify an appropriate timebase manually or remake tcfile.\n" );
return -1;
}
FAIL_IF_ERROR( fps_num > UINT32_MAX, "tcfile fps correction failed.\n"
" Specify an appropriate timebase manually or remake tcfile.\n" )
if( fabs( ((double)fps_num / fps_den) / exponent - fps_sig ) < DOUBLE_EPSILON )
break;
++i;
......@@ -91,12 +88,8 @@ static int try_mkv_timebase_den( double *fpss, timecode_hnd_t *h, int loop_num )
double fps_sig = sigexp10( fpss[num], &exponent );
fps_den = round( MKV_TIMEBASE_DEN / fps_sig ) / exponent;
h->timebase_num = fps_den && h->timebase_num ? gcd( h->timebase_num, fps_den ) : fps_den;
if( h->timebase_num > UINT32_MAX || !h->timebase_num )
{
fprintf( stderr, "timecode [error]: automatic timebase generation failed.\n"
" Specify timebase manually.\n" );
return -1;
}
FAIL_IF_ERROR( h->timebase_num > UINT32_MAX || !h->timebase_num, "automatic timebase generation failed.\n"
" Specify timebase manually.\n" )
}
return 0;
}
......@@ -110,11 +103,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
double *fpss = NULL;
ret = fscanf( tcfile_in, "# timecode format v%d", &tcfv );
if( ret != 1 || (tcfv != 1 && tcfv != 2) )
{
fprintf( stderr, "timecode [error]: unsupported timecode format\n" );
return -1;
}
FAIL_IF_ERROR( ret != 1 || (tcfv != 1 && tcfv != 2), "unsupported timecode format\n" )
if( tcfv == 1 )
{
......@@ -128,18 +117,11 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
{
if( buff[0] == '#' || buff[0] == '\n' || buff[0] == '\r' )
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" );
return -1;
}
FAIL_IF_ERROR( sscanf( buff, "assume %lf", &h->assume_fps ) != 1 && sscanf( buff, "Assume %lf", &h->assume_fps ) != 1,
"tcfile parsing error: assumed fps not found\n" )
break;
}
if( h->assume_fps <= 0 )
{
fprintf( stderr, "timecode [error]: invalid assumed fps %.6f\n", h->assume_fps );
return -1;
}
FAIL_IF_ERROR( h->assume_fps <= 0, "invalid assumed fps %.6f\n", h->assume_fps )
file_pos = ftell( tcfile_in );
h->stored_pts_num = 0;
......@@ -152,16 +134,9 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
continue;
}
ret = sscanf( buff, "%d,%d,%lf", &start, &end, &seq_fps );
if( ret != 3 && ret != EOF )
{
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 );
return -1;
}
FAIL_IF_ERROR( ret != 3 && ret != EOF, "invalid input tcfile\n" )
FAIL_IF_ERROR( start > end || start <= prev_start || end <= prev_end || seq_fps <= 0,
"invalid input tcfile at line %d: %s\n", num, buff )
prev_start = start;
prev_end = end;
if( h->auto_timebase_den || h->auto_timebase_num )
......@@ -259,11 +234,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
++num;
}
timecodes_num = h->stored_pts_num + h->seek;
if( !timecodes_num )
{
fprintf( stderr, "timecode [error]: input tcfile doesn't have any timecodes!\n" );
return -1;
}
FAIL_IF_ERROR( !timecodes_num, "input tcfile doesn't have any timecodes!\n" )
fseek( tcfile_in, file_pos, SEEK_SET );
timecodes = malloc( timecodes_num * sizeof(double) );
......@@ -272,11 +243,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
fgets( buff, sizeof(buff), tcfile_in );
ret = sscanf( buff, "%lf", &timecodes[0] );
if( ret != 1 )
{
fprintf( stderr, "timecode [error]: invalid input tcfile for frame 0\n" );
goto fail;
}
FAIL_IF_ERROR( ret != 1, "invalid input tcfile for frame 0\n" )
for( num = 1; num < timecodes_num; )
{
fgets( buff, sizeof(buff), tcfile_in );
......@@ -284,11 +251,8 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
continue;
ret = sscanf( buff, "%lf", &timecodes[num] );
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 );
goto fail;
}
FAIL_IF_ERROR( ret != 1 || timecodes[num] <= timecodes[num - 1],
"invalid input tcfile for frame %d\n", num )
++num;
}
......@@ -342,14 +306,10 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
uint64_t i = gcd( h->timebase_num, h->timebase_den );
h->timebase_num /= i;
h->timebase_den /= i;
fprintf( stderr, "timecode [info]: automatic timebase generation %"PRIu64"/%"PRIu64"\n", h->timebase_num, h->timebase_den );
}
else if( h->timebase_den > UINT32_MAX || !h->timebase_den )
{
fprintf( stderr, "timecode [error]: automatic timebase generation failed.\n"
" Specify an appropriate timebase manually.\n" );
goto fail;
x264_cli_log( "timecode", X264_LOG_INFO, "automatic timebase generation %"PRIu64"/%"PRIu64"\n", h->timebase_num, h->timebase_den );
}
else FAIL_IF_ERROR( h->timebase_den > UINT32_MAX || !h->timebase_den, "automatic timebase generation failed.\n"
" Specify an appropriate timebase manually.\n" )
h->pts = malloc( h->stored_pts_num * sizeof(int64_t) );
if( !h->pts )
......@@ -360,11 +320,7 @@ static int parse_tcfile( FILE *tcfile_in, timecode_hnd_t *h, video_info_t *info
{
h->pts[num] = (int64_t)( timecodes[h->seek + num] * ((double)h->timebase_den / h->timebase_num) + 0.5 );
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 );
goto fail;
}
FAIL_IF_ERROR( h->pts[num] <= h->pts[num - 1], "invalid timebase or timecode for frame %d\n", num )
}
free( timecodes );
......@@ -386,11 +342,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
int ret = 0;
FILE *tcfile_in;
timecode_hnd_t *h = malloc( sizeof(timecode_hnd_t) );
if( !h )
{
fprintf( stderr, "timecode [error]: malloc failed\n" );
return -1;
}
FAIL_IF_ERROR( !h, "malloc failed\n" )
h->input = input;
h->p_handle = *p_handle;
h->frame_total = input.get_frame_total( h->p_handle );
......@@ -400,11 +352,8 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
ret = sscanf( opt->timebase, "%"SCNu64"/%"SCNu64, &h->timebase_num, &h->timebase_den );
if( ret == 1 )
h->timebase_num = strtoul( opt->timebase, NULL, 10 );
if( h->timebase_num > UINT32_MAX || h->timebase_den > UINT32_MAX )
{
fprintf( stderr, "timecode [error]: timebase you specified exceeds H.264 maximum\n" );
return -1;
}
FAIL_IF_ERROR( h->timebase_num > UINT32_MAX || h->timebase_den > UINT32_MAX,
"timebase you specified exceeds H.264 maximum\n" )
}
h->auto_timebase_num = !ret;
h->auto_timebase_den = ret < 2;
......@@ -418,14 +367,10 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
*p_handle = h;
tcfile_in = fopen( psz_filename, "rb" );
if( !tcfile_in )