Commit f1ae384f authored by Fiona Glaser's avatar Fiona Glaser

Improve update interval of x264cli progress information

Now updates every 0.25s instead of every N frames.
parent 3fa4f5d2
......@@ -45,12 +45,18 @@ typedef struct
int reduce_pts;
int vfr_input;
int num_frames;
int64_t time;
} ffms_hnd_t;
static int FFMS_CC update_progress( int64_t current, int64_t total, void *private )
{
if( current % 10 )
int64_t *time = private;
int64_t oldtime = *time;
int64_t newtime = x264_mdate();
if( oldtime && newtime - oldtime < UPDATE_INTERVAL )
return 0;
*time = newtime;
char buf[200];
sprintf( buf, "ffms [info]: indexing input file [%.1f%%]", 100.0 * current / total );
fprintf( stderr, "%s \r", buf+5 );
......@@ -79,7 +85,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
}
if( !idx )
{
idx = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, update_progress, NULL, &e );
idx = FFMS_MakeIndex( psz_filename, 0, 0, NULL, NULL, 0, update_progress, &h->time, &e );
fprintf( stderr, " \r" );
FAIL_IF_ERROR( !idx, "could not create index\n" )
if( opt->index_file && FFMS_WriteIndex( opt->index_file, idx, &e ) )
......
......@@ -1574,10 +1574,13 @@ static int encode_frame( x264_t *h, hnd_t hout, x264_picture_t *pic, int64_t *la
return i_frame_size;
}
static void print_status( int64_t i_start, int i_frame, int i_frame_total, int64_t i_file, x264_param_t *param, int64_t last_ts )
static int64_t print_status( int64_t i_start, int64_t i_previous, int i_frame, int i_frame_total, int64_t i_file, x264_param_t *param, int64_t last_ts )
{
char buf[200];
int64_t i_elapsed = x264_mdate() - i_start;
int64_t i_time = x264_mdate();
if( i_previous && i_time - i_previous < UPDATE_INTERVAL )
return i_previous;
int64_t i_elapsed = i_time - i_start;
double fps = i_elapsed > 0 ? i_frame * 1000000. / i_elapsed : 0;
double bitrate;
if( last_ts )
......@@ -1598,6 +1601,7 @@ static void print_status( int64_t i_start, int i_frame, int i_frame_total, int64
fprintf( stderr, "%s \r", buf+5 );
SetConsoleTitle( buf );
fflush( stderr ); // needed in windows
return i_time;
}
static void convert_cli_to_lib_pic( x264_picture_t *lib, cli_pic_t *cli )
......@@ -1626,10 +1630,9 @@ static int encode( x264_param_t *param, cli_opt_t *opt )
int i_frame = 0;
int i_frame_output = 0;
int64_t i_end, i_start = 0;
int64_t i_end, i_previous = 0, i_start = 0;
int64_t i_file = 0;
int i_frame_size;
int i_update_interval;
int64_t last_dts = 0;
int64_t prev_dts = 0;
int64_t first_dts = 0;
......@@ -1646,7 +1649,6 @@ static int encode( x264_param_t *param, cli_opt_t *opt )
GetConsoleTitle( originalCTitle, sizeof(originalCTitle) );
opt->b_progress &= param->i_log_level < X264_LOG_DEBUG;
i_update_interval = param->i_frame_total ? x264_clip3( param->i_frame_total / 1000, 1, 10 ) : 10;
/* set up pulldown */
if( opt->i_pulldown && !param->b_vfr_input )
......@@ -1668,6 +1670,7 @@ static int encode( x264_param_t *param, cli_opt_t *opt )
FAIL_IF_ERROR2( output.set_param( opt->hout, param ), "can't set outfile param\n" );
i_start = x264_mdate();
/* ticks/frame = ticks/second / frames/second */
ticks_per_frame = (int64_t)param->i_timebase_den * param->i_fps_den / param->i_timebase_num / param->i_fps_num;
FAIL_IF_ERROR2( ticks_per_frame < 1 && !param->b_vfr_input, "ticks_per_frame invalid: %"PRId64"\n", ticks_per_frame )
......@@ -1744,8 +1747,8 @@ static int encode( x264_param_t *param, cli_opt_t *opt )
break;
/* update status line (up to 1000 times per input file) */
if( opt->b_progress && i_frame_output % i_update_interval == 0 && i_frame_output )
print_status( i_start, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts );
if( opt->b_progress && i_frame_output )
i_previous = print_status( i_start, i_previous, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts );
}
/* Flush delayed frames */
while( !b_ctrl_c && x264_encoder_delayed_frames( h ) )
......@@ -1764,8 +1767,8 @@ static int encode( x264_param_t *param, cli_opt_t *opt )
if( i_frame_output == 1 )
first_dts = prev_dts = last_dts;
}
if( opt->b_progress && i_frame_output % i_update_interval == 0 && i_frame_output )
print_status( i_start, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts );
if( opt->b_progress && i_frame_output )
i_previous = print_status( i_start, i_previous, i_frame_output, param->i_frame_total, i_file, param, 2 * last_dts - prev_dts - first_dts );
}
fail:
if( pts_warning_cnt >= MAX_PTS_WARNING && cli_log_level < X264_LOG_DEBUG )
......
......@@ -29,6 +29,9 @@
#include "common/common.h"
/* In microseconds */
#define UPDATE_INTERVAL 250000
typedef void *hnd_t;
static inline int64_t gcd( int64_t a, int64_t b )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment