[x264-devel] Improve update interval of x264cli progress information
Jason Garrett-Glaser
git at videolan.org
Mon Feb 7 06:31:32 CET 2011
x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Fri Feb 4 20:49:45 2011 -0800| [e6738f2074ac6a2d93e98b05c081d9d98562c48a] | committer: Jason Garrett-Glaser
Improve update interval of x264cli progress information
Now updates every 0.25s instead of every N frames.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=e6738f2074ac6a2d93e98b05c081d9d98562c48a
---
input/ffms.c | 10 ++++++++--
x264.c | 21 ++++++++++++---------
x264cli.h | 3 +++
3 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/input/ffms.c b/input/ffms.c
index 284047d..5b2af27 100644
--- a/input/ffms.c
+++ b/input/ffms.c
@@ -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 ) )
diff --git a/x264.c b/x264.c
index f6542a2..92695ab 100644
--- a/x264.c
+++ b/x264.c
@@ -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 )
diff --git a/x264cli.h b/x264cli.h
index 85c4829..50a9be3 100644
--- a/x264cli.h
+++ b/x264cli.h
@@ -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 )
More information about the x264-devel
mailing list