X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=x264.c;h=b296cf102975d34d2a80112fa753ebd140654507;hb=277d2da8958b5e08d119c0068a54842bc5c3af71;hp=f68755d91528deee0056da304f506e10d77cd3f1;hpb=8d09ebe2e862688ce213d3f098ce7eca719fea23;p=x264 diff --git a/x264.c b/x264.c index f68755d9..b296cf10 100644 --- a/x264.c +++ b/x264.c @@ -1,10 +1,10 @@ /***************************************************************************** * x264: h264 encoder testing program. ***************************************************************************** - * Copyright (C) 2003 Laurent Aimar - * $Id: x264.c,v 1.1 2004/06/03 19:24:12 fenrir Exp $ + * Copyright (C) 2003-2008 x264 project * - * Authors: Laurent Aimar + * Authors: Loren Merritt + * Laurent Aimar * * 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 @@ -18,7 +18,7 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. *****************************************************************************/ #include @@ -29,6 +29,7 @@ #include #include "common/common.h" +#include "common/cpu.h" #include "x264.h" #include "muxers.h" @@ -89,7 +90,7 @@ int main( int argc, char **argv ) pthread_win32_thread_attach_np(); #endif -#ifdef _MSC_VER +#ifdef _WIN32 _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); #endif @@ -187,13 +188,20 @@ static void Help( x264_param_t *defaults, int b_longhelp ) H0( " --ipratio QP factor between I and P [%.2f]\n", defaults->rc.f_ip_factor ); H0( " --pbratio QP factor between P and B [%.2f]\n", defaults->rc.f_pb_factor ); H1( " --chroma-qp-offset QP difference between chroma and luma [%d]\n", defaults->analyse.i_chroma_qp_offset ); + H0( " --aq-mode How AQ distributes bits [%d]\n" + " - 0: Disabled\n" + " - 1: Avoid moving bits between frames\n" + " - 2: Move bits between frames\n", defaults->rc.i_aq_mode ); + H0( " --aq-strength Reduces blocking and blurring in flat and\n" + " textured areas. [%.1f]\n" + " - 0.5: weak AQ\n" + " - 1.5: strong AQ\n", defaults->rc.f_aq_strength ); H0( "\n" ); H0( " -p, --pass <1|2|3> Enable multipass ratecontrol\n" " - 1: First pass, creates stats file\n" " - 2: Last pass, does not overwrite stats file\n" " - 3: Nth pass, overwrites stats file\n" ); H0( " --stats Filename for 2 pass stats [\"%s\"]\n", defaults->rc.psz_stat_out ); - H1( " --rceq Ratecontrol equation [\"%s\"]\n", defaults->rc.psz_rc_eq ); H0( " --qcomp QP curve compression: 0.0 => CBR, 1.0 => CQP [%.2f]\n", defaults->rc.f_qcompress ); H1( " --cplxblur Reduce fluctuations in QP (before curve compression) [%.1f]\n", defaults->rc.f_complexity_blur ); H1( " --qblur Reduce fluctuations in QP (after curve compression) [%.1f]\n", defaults->rc.f_qblur ); @@ -307,8 +315,10 @@ static void Help( x264_param_t *defaults, int b_longhelp ) H0( " --threads Parallel encoding\n" ); H0( " --thread-input Run Avisynth in its own thread\n" ); H1( " --non-deterministic Slightly improve quality of SMP, at the cost of repeatability\n" ); + H1( " --asm Override CPU detection\n" ); H1( " --no-asm Disable all CPU optimizations\n" ); H1( " --visualize Show MB types overlayed on the encoded video\n" ); + H1( " --dump-yuv Save reconstructed frames\n" ); H1( " --sps-id Set SPS and PPS id numbers [%d]\n", defaults->i_sps_id ); H1( " --aud Use access unit delimiters\n" ); H0( "\n" ); @@ -383,6 +393,7 @@ static int Parse( int argc, char **argv, { "qpstep", required_argument, NULL, 0 }, { "crf", required_argument, NULL, 0 }, { "ref", required_argument, NULL, 'r' }, + { "asm", required_argument, NULL, 0 }, { "no-asm", no_argument, NULL, 0 }, { "sar", required_argument, NULL, 0 }, { "fps", required_argument, NULL, 0 }, @@ -407,6 +418,8 @@ static int Parse( int argc, char **argv, { "trellis", required_argument, NULL, 't' }, { "no-fast-pskip", no_argument, NULL, 0 }, { "no-dct-decimate", no_argument, NULL, 0 }, + { "aq-strength", required_argument, NULL, 0 }, + { "aq-mode", required_argument, NULL, 0 }, { "deadzone-inter", required_argument, NULL, '0' }, { "deadzone-intra", required_argument, NULL, '0' }, { "level", required_argument, NULL, 0 }, @@ -419,7 +432,6 @@ static int Parse( int argc, char **argv, { "chroma-qp-offset", required_argument, NULL, 0 }, { "pass", required_argument, NULL, 'p' }, { "stats", required_argument, NULL, 0 }, - { "rceq", required_argument, NULL, 0 }, { "qcomp", required_argument, NULL, 0 }, { "qblur", required_argument, NULL, 0 }, { "cplxblur",required_argument, NULL, 0 }, @@ -434,6 +446,7 @@ static int Parse( int argc, char **argv, { "verbose", no_argument, NULL, 'v' }, { "progress",no_argument, NULL, OPT_PROGRESS }, { "visualize",no_argument, NULL, OPT_VISUALIZE }, + { "dump-yuv",required_argument, NULL, 0 }, { "sps-id", required_argument, NULL, 0 }, { "aud", no_argument, NULL, 0 }, { "nr", required_argument, NULL, 0 }, @@ -617,7 +630,7 @@ static int Parse( int argc, char **argv, sscanf( argv[optind++], "%ux%u", ¶m->i_width, ¶m->i_height ); } } - + if( !(b_avis || b_y4m) && ( !param->i_width || !param->i_height ) ) { fprintf( stderr, "x264 [error]: Rawyuv input requires a resolution.\n" ); @@ -654,7 +667,8 @@ static int Parse( int argc, char **argv, } #ifdef HAVE_PTHREAD - if( b_thread_input || param->i_threads > 1 ) + if( b_thread_input || param->i_threads > 1 + || (param->i_threads == 0 && x264_cpu_num_processors() > 1) ) { if( open_file_thread( NULL, &opt->hin, param ) ) { @@ -675,11 +689,20 @@ static int Parse( int argc, char **argv, static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame ) { - int num = -1, qp; + int num = -1, qp, ret; char type; + uint64_t file_pos; while( num < i_frame ) { - int ret = fscanf( opt->qpfile, "%d %c %d\n", &num, &type, &qp ); + file_pos = ftell( opt->qpfile ); + ret = fscanf( opt->qpfile, "%d %c %d\n", &num, &type, &qp ); + if( num > i_frame || ret == EOF ) + { + pic->i_type = X264_TYPE_AUTO; + pic->i_qpplus1 = 0; + fseek( opt->qpfile , file_pos , SEEK_SET ); + break; + } if( num < i_frame ) continue; pic->i_qpplus1 = qp+1; @@ -689,7 +712,7 @@ static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame ) else if( type == 'B' ) pic->i_type = X264_TYPE_BREF; else if( type == 'b' ) pic->i_type = X264_TYPE_B; else ret = 0; - if( ret != 3 || qp < 0 || qp > 51 || num > i_frame ) + if( ret != 3 || qp < -1 || qp > 51 ) { fprintf( stderr, "x264 [error]: can't parse qpfile for frame %d\n", i_frame ); fclose( opt->qpfile ); @@ -747,20 +770,21 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) int64_t i_start, i_end; int64_t i_file; int i_frame_size; - int i_progress; + int i_update_interval; + opt->b_progress &= param->i_log_level < X264_LOG_DEBUG; i_frame_total = p_get_frame_total( opt->hin ); i_frame_total -= opt->i_seek; if( ( i_frame_total == 0 || param->i_frame_total < i_frame_total ) && param->i_frame_total > 0 ) i_frame_total = param->i_frame_total; param->i_frame_total = i_frame_total; + i_update_interval = i_frame_total ? x264_clip3( i_frame_total / 1000, 1, 10 ) : 10; if( ( h = x264_encoder_open( param ) ) == NULL ) { fprintf( stderr, "x264 [error]: x264_encoder_open failed\n" ); p_close_infile( opt->hin ); - p_close_outfile( opt->hout ); return -1; } @@ -778,8 +802,7 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) i_start = x264_mdate(); /* Encode frames */ - for( i_frame = 0, i_file = 0, i_progress = 0; - b_ctrl_c == 0 && (i_frame < i_frame_total || i_frame_total == 0); ) + for( i_frame = 0, i_file = 0; b_ctrl_c == 0 && (i_frame < i_frame_total || i_frame_total == 0); ) { if( p_read_frame( &pic, opt->hin, i_frame + opt->i_seek ) ) break; @@ -800,18 +823,16 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) i_frame++; /* update status line (up to 1000 times per input file) */ - if( opt->b_progress && param->i_log_level < X264_LOG_DEBUG && - ( i_frame_total ? i_frame * 1000 / i_frame_total > i_progress - : i_frame % 10 == 0 ) ) + if( opt->b_progress && i_frame % i_update_interval == 0 ) { int64_t i_elapsed = x264_mdate() - i_start; double fps = i_elapsed > 0 ? i_frame * 1000000. / i_elapsed : 0; if( i_frame_total ) { int eta = i_elapsed * (i_frame_total - i_frame) / ((int64_t)i_frame * 1000000); - i_progress = i_frame * 1000 / i_frame_total; - fprintf( stderr, "encoded frames: %d/%d (%.1f%%), %.2f fps, eta %d:%02d:%02d \r", - i_frame, i_frame_total, (float)i_progress / 10, fps, + fprintf( stderr, "encoded frames: %d/%d (%.1f%%), %.2f fps, %.2f kb/s, eta %d:%02d:%02d \r", + i_frame, i_frame_total, 100. * i_frame / i_frame_total, fps, + (double) i_file * 8 * param->i_fps_num / ( (double) param->i_fps_den * i_frame * 1000 ), eta/3600, (eta/60)%60, eta%60 ); } else @@ -827,7 +848,11 @@ static int Encode( x264_param_t *param, cli_opt_t *opt ) i_end = x264_mdate(); x264_picture_clean( &pic ); + /* Erase progress indicator before printing encoding stats. */ + if( opt->b_progress ) + fprintf( stderr, " \r" ); x264_encoder_close( h ); + x264_free( mux_buffer ); fprintf( stderr, "\n" ); if( b_ctrl_c )