X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=x264.c;h=959626adc327042d6f5d05135ccee62a64596adc;hb=b1c4cf9841beb88229da07ed60d7f1f394dfe341;hp=cf194ef90704bf2254e2d946dbadf985651ddb3a;hpb=7b4f6a1fd95c7e0ab479e116fe59e66e5d1fd107;p=x264 diff --git a/x264.c b/x264.c index cf194ef9..959626ad 100644 --- a/x264.c +++ b/x264.c @@ -1,10 +1,12 @@ /***************************************************************************** * 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 + * Steven Walters + * Kieran Kunhya * * 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,36 +20,26 @@ * * 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. *****************************************************************************/ -#define _LARGEFILE_SOURCE -#define _FILE_OFFSET_BITS 64 - #include -#include -#include #include #include #define _GNU_SOURCE #include -#ifdef _MSC_VER -#include /* _setmode() */ -#include /* _O_BINARY */ -#endif - -#ifndef _MSC_VER -#include "config.h" -#endif - #include "common/common.h" +#include "common/cpu.h" #include "x264.h" #include "muxers.h" -#define DATA_MAX 3000000 -uint8_t data[DATA_MAX]; +#ifdef _WIN32 +#include +#else +#define SetConsoleTitle(t) +#endif /* Ctrl-C handler */ static int b_ctrl_c = 0; @@ -67,24 +59,43 @@ typedef struct { FILE *qpfile; } cli_opt_t; -/* input file operation function pointers */ -int (*p_open_infile)( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); -int (*p_get_frame_total)( hnd_t handle ); -int (*p_read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame ); -int (*p_close_infile)( hnd_t handle ); +/* i/o file operation function pointer structs */ +cli_input_t input; +static cli_output_t output; + +static const char * const demuxer_names[] = +{ + "auto", + "yuv", + "y4m", +#ifdef AVS_INPUT + "avs", +#endif +#ifdef LAVF_INPUT + "lavf", +#endif +#ifdef FFMS_INPUT + "ffms", +#endif + 0 +}; -/* output file operation function pointers */ -static int (*p_open_outfile)( char *psz_filename, hnd_t *p_handle ); -static int (*p_set_outfile_param)( hnd_t handle, x264_param_t *p_param ); -static int (*p_write_nalu)( hnd_t handle, uint8_t *p_nal, int i_size ); -static int (*p_set_eop)( hnd_t handle, x264_picture_t *p_picture ); -static int (*p_close_outfile)( hnd_t handle ); +static const char * const muxer_names[] = +{ + "auto", + "raw", + "mkv", + "flv", +#ifdef MP4_OUTPUT + "mp4", +#endif + 0 +}; -static void Help( x264_param_t *defaults, int b_longhelp ); +static void Help( x264_param_t *defaults, int longhelp ); static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt ); static int Encode( x264_param_t *param, cli_opt_t *opt ); - /**************************************************************************** * main: ****************************************************************************/ @@ -92,8 +103,14 @@ int main( int argc, char **argv ) { x264_param_t param; cli_opt_t opt; + int ret; + +#ifdef PTW32_STATIC_LIB + pthread_win32_process_attach_np(); + pthread_win32_thread_attach_np(); +#endif -#ifdef _MSC_VER +#ifdef _WIN32 _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); #endif @@ -107,7 +124,14 @@ int main( int argc, char **argv ) /* Control-C handler */ signal( SIGINT, SigIntHandler ); - return Encode( ¶m, &opt ); + ret = Encode( ¶m, &opt ); + +#ifdef PTW32_STATIC_LIB + pthread_win32_thread_detach_np(); + pthread_win32_process_detach_np(); +#endif + + return ret; } static char const *strtable_lookup( const char * const table[], int index ) @@ -116,31 +140,59 @@ static char const *strtable_lookup( const char * const table[], int index ) return ( ( index >= 0 && index < i ) ? table[ index ] : "???" ); } +static char *stringify_names( char *buf, const char * const names[] ) +{ + int i = 0; + char *p = buf; + for( p[0] = 0; names[i]; i++ ) + { + p += sprintf( p, "%s", names[i] ); + if( names[i+1] ) + p += sprintf( p, ", " ); + } + return buf; +} + /***************************************************************************** * Help: *****************************************************************************/ -static void Help( x264_param_t *defaults, int b_longhelp ) +static void Help( x264_param_t *defaults, int longhelp ) { + char buf[50]; #define H0 printf -#define H1 if(b_longhelp) printf +#define H1 if(longhelp>=1) printf +#define H2 if(longhelp==2) printf H0( "x264 core:%d%s\n" "Syntax: x264 [options] -o outfile infile [widthxheight]\n" "\n" "Infile can be raw YUV 4:2:0 (in which case resolution is required),\n" " or YUV4MPEG 4:2:0 (*.y4m),\n" - " or AVI or Avisynth if compiled with AVIS support (%s).\n" + " or Avisynth if compiled with support (%s).\n" + " or libav* formats if compiled with lavf support (%s) or ffms support (%s).\n" "Outfile type is selected by filename:\n" " .264 -> Raw bytestream\n" " .mkv -> Matroska\n" + " .flv -> Flash Video\n" " .mp4 -> MP4 if compiled with GPAC support (%s)\n" "\n" "Options:\n" "\n" - " -h, --help List the more commonly used options\n" - " --longhelp List all options\n" + " -h, --help List basic options\n" + " --longhelp List more options\n" + " --fullhelp List all options\n" "\n", X264_BUILD, X264_VERSION, -#ifdef AVIS_INPUT +#ifdef AVS_INPUT + "yes", +#else + "no", +#endif +#ifdef LAVF_INPUT + "yes", +#else + "no", +#endif +#ifdef FFMS_INPUT "yes", #else "no", @@ -151,312 +203,839 @@ static void Help( x264_param_t *defaults, int b_longhelp ) "no" #endif ); + H0( "Example usage:\n" ); + H0( "\n" ); + H0( " Constant quality mode:\n" ); + H0( " x264 --crf 24 -o \n" ); + H0( "\n" ); + H0( " Two-pass with a bitrate of 1000kbps:\n" ); + H0( " x264 --pass 1 --bitrate 1000 -o \n" ); + H0( " x264 --pass 2 --bitrate 1000 -o \n" ); + H0( "\n" ); + H0( " Lossless:\n" ); + H0( " x264 --crf 0 -o \n" ); + H0( "\n" ); + H0( " Maximum PSNR at the cost of speed and visual quality:\n" ); + H0( " x264 --preset placebo --tune psnr -o \n" ); + H0( "\n" ); + H0( " Constant bitrate at 1000kbps with a 2 second-buffer:\n"); + H0( " x264 --vbv-bufsize 2000 --bitrate 1000 -o \n" ); + H0( "\n" ); + H0( "Presets:\n" ); + H0( "\n" ); + H0( " --profile Force the limits of an H.264 profile [high]\n" + " Overrides all settings.\n" ); + H2( " - baseline:\n" + " --no-8x8dct --bframes 0 --no-cabac\n" + " --cqm flat --weightp 0 No interlaced\n" + " No lossless\n" + " - main:\n" + " --no-8x8dct --cqm flat No lossless\n" + " - high:\n" + " No lossless\n" ); + else H0( " - baseline,main,high\n" ); + H0( " --preset Use a preset to select encoding settings [medium]\n" + " Overridden by user settings.\n" ); + H2( " - ultrafast:\n" + " --no-8x8dct --aq-mode 0 --b-adapt 0\n" + " --bframes 0 --no-cabac --no-deblock\n" + " --no-mbtree --me dia --no-mixed-refs\n" + " --partitions none --ref 1 --scenecut 0\n" + " --subme 0 --trellis 0 --no-weightb\n" + " --weightp 0\n" + " - veryfast:\n" + " --no-mbtree --me dia --no-mixed-refs\n" + " --partitions i8x8,i4x4 --ref 1\n" + " --subme 1 --trellis 0 --weightp 0\n" + " - faster:\n" + " --no-mbtree --no-mixed-refs --ref 2\n" + " --subme 4 --weightp 1\n" + " - fast:\n" + " --rc-lookahead 30 --ref 2 --subme 6\n" + " - medium:\n" + " Default settings apply.\n" + " - slow:\n" + " --b-adapt 2 --direct auto --me umh\n" + " --rc-lookahead 50 --ref 5 --subme 8\n" + " - slower:\n" + " --b-adapt 2 --direct auto --me umh\n" + " --partitions all --rc-lookahead 60\n" + " --ref 8 --subme 9 --trellis 2\n" + " - veryslow:\n" + " --b-adapt 2 --bframes 8 --direct auto\n" + " --me umh --merange 24 --partitions all\n" + " --ref 16 --subme 10 --trellis 2\n" + " --rc-lookahead 60\n" + " - placebo:\n" + " --bframes 16 --b-adapt 2 --direct auto\n" + " --slow-firstpass --no-fast-pskip\n" + " --me tesa --merange 24 --partitions all\n" + " --rc-lookahead 60 --ref 16 --subme 10\n" + " --trellis 2\n" ); + else H0( " - ultrafast,veryfast,faster,fast,medium\n" + " - slow,slower,veryslow,placebo\n" ); + H0( " --tune Tune the settings for a particular type of source\n" + " or situation\n" + " Overridden by user settings.\n" + " Multiple tunings are separated by commas.\n" + " Only one psy tuning can be used at a time.\n" ); + H2( " - film (psy tuning):\n" + " --deblock -1:-1 --psy-rd :0.15\n" + " - animation (psy tuning):\n" + " --bframes {+2} --deblock 1:1\n" + " --psy-rd 0.4: --aq-strength 0.6\n" + " --ref {Double if >1 else 1}\n" + " - grain (psy tuning):\n" + " --aq-strength 0.5 --no-dct-decimate\n" + " --deadzone-inter 6 --deadzone-intra 6\n" + " --deblock -2:-2 --ipratio 1.1 \n" + " --pbratio 1.1 --psy-rd :0.25\n" + " --qcomp 0.8\n" + " - psnr (psy tuning):\n" + " --aq-mode 0 --no-psy\n" + " - ssim (psy tuning):\n" + " --aq-mode 2 --no-psy\n" + " - fastdecode:\n" + " --no-cabac --no-deblock --no-weightb\n" + " --weightp 0\n" + " - zerolatency:\n" + " --bframes 0 --rc-lookahead 0\n" + " --sync-lookahead 0 --sliced-threads\n" ); + else H0( " - psy tunings: film,animation,grain,psnr,ssim\n" + " - other tunings: fastdecode,zerolatency\n" ); + H1( " --slow-firstpass Don't use faster settings with --pass 1\n" ); + H0( "\n" ); H0( "Frame-type options:\n" ); H0( "\n" ); H0( " -I, --keyint Maximum GOP size [%d]\n", defaults->i_keyint_max ); - H1( " -i, --min-keyint Minimum GOP size [%d]\n", defaults->i_keyint_min ); - H1( " --scenecut How aggressively to insert extra I-frames [%d]\n", defaults->i_scenecut_threshold ); - H1( " --pre-scenecut Faster, less precise scenecut detection.\n" - " Required and implied by multi-threading.\n" ); - H0( " -b, --bframes Number of B-frames between I and P [%d]\n", defaults->i_bframe ); - H1( " --no-b-adapt Disable adaptive B-frame decision\n" ); - H1( " --b-bias Influences how often B-frames are used [%d]\n", defaults->i_bframe_bias ); - H0( " --b-pyramid Keep some B-frames as references\n" ); - H0( " --no-cabac Disable CABAC\n" ); - H0( " -r, --ref Number of reference frames [%d]\n", defaults->i_frame_reference ); + H2( " -i, --min-keyint Minimum GOP size [%d]\n", defaults->i_keyint_min ); + H2( " --no-scenecut Disable adaptive I-frame decision\n" ); + H2( " --scenecut How aggressively to insert extra I-frames [%d]\n", defaults->i_scenecut_threshold ); + H2( " --intra-refresh Use Periodic Intra Refresh instead of IDR frames\n" ); + H1( " -b, --bframes Number of B-frames between I and P [%d]\n", defaults->i_bframe ); + H1( " --b-adapt Adaptive B-frame decision method [%d]\n" + " Higher values may lower threading efficiency.\n" + " - 0: Disabled\n" + " - 1: Fast\n" + " - 2: Optimal (slow with high --bframes)\n", defaults->i_bframe_adaptive ); + H2( " --b-bias Influences how often B-frames are used [%d]\n", defaults->i_bframe_bias ); + H1( " --b-pyramid Keep some B-frames as references [%s]\n" + " - none: Disabled\n" + " - strict: Strictly hierarchical pyramid\n" + " - normal: Non-strict (not Blu-ray compatible)\n", + strtable_lookup( x264_b_pyramid_names, defaults->i_bframe_pyramid ) ); + H1( " --no-cabac Disable CABAC\n" ); + H1( " -r, --ref Number of reference frames [%d]\n", defaults->i_frame_reference ); H1( " --no-deblock Disable loop filter\n" ); - H0( " -f, --deblock Loop filter AlphaC0 and Beta parameters [%d:%d]\n", + H1( " -f, --deblock Loop filter parameters [%d:%d]\n", defaults->i_deblocking_filter_alphac0, defaults->i_deblocking_filter_beta ); + H2( " --slices Number of slices per frame; forces rectangular\n" + " slices and is overridden by other slicing options\n" ); + else H1( " --slices Number of slices per frame\n" ); + H2( " --slice-max-size Limit the size of each slice in bytes\n"); + H2( " --slice-max-mbs Limit the size of each slice in macroblocks\n"); H0( " --interlaced Enable pure-interlaced mode\n" ); + H2( " --constrained-intra Enable constrained intra prediction.\n" ); H0( "\n" ); H0( "Ratecontrol:\n" ); H0( "\n" ); - H0( " -q, --qp Set QP (0=lossless) [%d]\n", defaults->rc.i_qp_constant ); + H1( " -q, --qp Force constant QP (0-51, 0=lossless)\n" ); H0( " -B, --bitrate Set bitrate (kbit/s)\n" ); - H0( " --crf Quality-based VBR (nominal QP)\n" ); - H1( " --vbv-maxrate Max local bitrate (kbit/s) [%d]\n", defaults->rc.i_vbv_max_bitrate ); - H0( " --vbv-bufsize Enable CBR and set size of the VBV buffer (kbit) [%d]\n", defaults->rc.i_vbv_buffer_size ); - H1( " --vbv-init Initial VBV buffer occupancy [%.1f]\n", defaults->rc.f_vbv_buffer_init ); - H1( " --qpmin Set min QP [%d]\n", defaults->rc.i_qp_min ); - H1( " --qpmax Set max QP [%d]\n", defaults->rc.i_qp_max ); - H1( " --qpstep Set max QP step [%d]\n", defaults->rc.i_qp_step ); - H0( " --ratetol Allowed variance of average bitrate [%.1f]\n", defaults->rc.f_rate_tolerance ); - 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( "\n" ); - H0( " -p, --pass <1|2|3> Enable multipass ratecontrol\n" + H0( " --crf Quality-based VBR (0-51, 0=lossless) [%.1f]\n", defaults->rc.f_rf_constant ); + H1( " --rc-lookahead Number of frames for frametype lookahead [%d]\n", defaults->rc.i_lookahead ); + H0( " --vbv-maxrate Max local bitrate (kbit/s) [%d]\n", defaults->rc.i_vbv_max_bitrate ); + H0( " --vbv-bufsize Set size of the VBV buffer (kbit) [%d]\n", defaults->rc.i_vbv_buffer_size ); + H2( " --vbv-init Initial VBV buffer occupancy [%.1f]\n", defaults->rc.f_vbv_buffer_init ); + H2( " --qpmin Set min QP [%d]\n", defaults->rc.i_qp_min ); + H2( " --qpmax Set max QP [%d]\n", defaults->rc.i_qp_max ); + H2( " --qpstep Set max QP step [%d]\n", defaults->rc.i_qp_step ); + H2( " --ratetol Tolerance of ABR ratecontrol and VBV [%.1f]\n", defaults->rc.f_rate_tolerance ); + H2( " --ipratio QP factor between I and P [%.2f]\n", defaults->rc.f_ip_factor ); + H2( " --pbratio QP factor between P and B [%.2f]\n", defaults->rc.f_pb_factor ); + H2( " --chroma-qp-offset QP difference between chroma and luma [%d]\n", defaults->analyse.i_chroma_qp_offset ); + H2( " --aq-mode AQ method [%d]\n" + " - 0: Disabled\n" + " - 1: Variance AQ (complexity mask)\n" + " - 2: Auto-variance AQ (experimental)\n", defaults->rc.i_aq_mode ); + H1( " --aq-strength Reduces blocking and blurring in flat and\n" + " textured areas. [%.1f]\n", defaults->rc.f_aq_strength ); + H1( "\n" ); + H0( " -p, --pass 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 ); - H0( " --zones //... Tweak the bitrate of some regions of the video\n" ); - H1( " Each zone is of the form\n" + " - 2: Last pass, does not overwrite stats file\n" ); + H2( " - 3: Nth pass, overwrites stats file\n" ); + H1( " --stats Filename for 2 pass stats [\"%s\"]\n", defaults->rc.psz_stat_out ); + H2( " --no-mbtree Disable mb-tree ratecontrol.\n"); + H2( " --qcomp QP curve compression [%.2f]\n", defaults->rc.f_qcompress ); + H2( " --cplxblur Reduce fluctuations in QP (before curve compression) [%.1f]\n", defaults->rc.f_complexity_blur ); + H2( " --qblur Reduce fluctuations in QP (after curve compression) [%.1f]\n", defaults->rc.f_qblur ); + H2( " --zones //... Tweak the bitrate of regions of the video\n" ); + H2( " Each zone is of the form\n" " ,,