X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=x264.c;h=74d5e2645a01b5d696aac1b79aac1f9fe82f57d9;hb=485172deeb75ca1eb88ac24b6ab6719b8a16825b;hp=50f503f7403060b00cfc5708bb7e7377409dcfdd;hpb=6fe92323b2e007e3a31714fb5b090b732fc24e62;p=x264 diff --git a/x264.c b/x264.c index 50f503f7..74d5e264 100644 --- a/x264.c +++ b/x264.c @@ -1,5 +1,5 @@ /***************************************************************************** - * x264: h264 encoder/decoder testing program. + * x264: h264 encoder testing program. ***************************************************************************** * Copyright (C) 2003 Laurent Aimar * $Id: x264.c,v 1.1 2004/06/03 19:24:12 fenrir Exp $ @@ -21,10 +21,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************/ +#define _LARGEFILE_SOURCE +#define _FILE_OFFSET_BITS 64 + #include #include #include - #include #include @@ -36,30 +38,17 @@ #include /* _O_BINARY */ #endif -#ifdef AVIS_INPUT -#include -#include -#endif - -#ifdef MP4_OUTPUT -#include -#endif - - -#include "common/common.h" -#include "x264.h" - #ifndef _MSC_VER #include "config.h" #endif -#include "matroska.h" +#include "common/common.h" +#include "x264.h" +#include "muxers.h" #define DATA_MAX 3000000 uint8_t data[DATA_MAX]; -typedef void *hnd_t; - /* Ctrl-C handler */ static int b_ctrl_c = 0; static int b_exit_on_ctrl_c = 0; @@ -71,30 +60,18 @@ static void SigIntHandler( int a ) } typedef struct { - int b_decompress; int b_progress; int i_seek; hnd_t hin; hnd_t hout; + FILE *qpfile; } cli_opt_t; /* input file operation function pointers */ -static int (*p_open_infile)( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); -static int (*p_get_frame_total)( hnd_t handle, int i_width, int i_height ); -static int (*p_read_frame)( x264_picture_t *p_pic, hnd_t handle, int i_frame, int i_width, int i_height ); -static int (*p_close_infile)( hnd_t handle ); - -static int open_file_yuv( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); -static int get_frame_total_yuv( hnd_t handle, int i_width, int i_height ); -static int read_frame_yuv( x264_picture_t *p_pic, hnd_t handle, int i_frame, int i_width, int i_height ); -static int close_file_yuv( hnd_t handle ); - -#ifdef AVIS_INPUT -static int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param ); -static int get_frame_total_avis( hnd_t handle, int i_width, int i_height ); -static int read_frame_avis( x264_picture_t *p_pic, hnd_t handle, int i_frame, int i_width, int i_height ); -static int close_file_avis( hnd_t handle ); -#endif +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 ); /* output file operation function pointers */ static int (*p_open_outfile)( char *psz_filename, hnd_t *p_handle ); @@ -103,27 +80,7 @@ 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 int open_file_bsf( char *psz_filename, hnd_t *p_handle ); -static int set_param_bsf( hnd_t handle, x264_param_t *p_param ); -static int write_nalu_bsf( hnd_t handle, uint8_t *p_nal, int i_size ); -static int set_eop_bsf( hnd_t handle, x264_picture_t *p_picture ); -static int close_file_bsf( hnd_t handle ); - -#ifdef MP4_OUTPUT -static int open_file_mp4( char *psz_filename, hnd_t *p_handle ); -static int set_param_mp4( hnd_t handle, x264_param_t *p_param ); -static int write_nalu_mp4( hnd_t handle, uint8_t *p_nal, int i_size ); -static int set_eop_mp4( hnd_t handle, x264_picture_t *p_picture ); -static int close_file_mp4( hnd_t handle ); -#endif - -static int open_file_mkv( char *psz_filename, hnd_t *p_handle ); -static int set_param_mkv( hnd_t handle, x264_param_t *p_param ); -static int write_nalu_mkv( hnd_t handle, uint8_t *p_nal, int i_size ); -static int set_eop_mkv( hnd_t handle, x264_picture_t *p_picture ); -static int close_file_mkv( hnd_t handle ); - -static void Help( x264_param_t *defaults ); +static void Help( x264_param_t *defaults, int b_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 ); @@ -137,7 +94,7 @@ int main( int argc, char **argv ) cli_opt_t opt; #ifdef _MSC_VER - _setmode(_fileno(stdin), _O_BINARY); /* thanks to Marcos Morais */ + _setmode(_fileno(stdin), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY); #endif @@ -153,13 +110,6 @@ int main( int argc, char **argv ) return Encode( ¶m, &opt ); } -static const char * const overscan_str[] = { "undef", "show", "crop", NULL }; -static const char * const vidformat_str[] = { "component", "pal", "ntsc", "secam", "mac", "undef", NULL }; -static const char * const fullrange_str[] = { "off", "on", NULL }; -static const char * const colorprim_str[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "film", NULL }; -static const char * const transfer_str[] = { "", "bt709", "undef", "", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100", "log316", NULL }; -static const char * const colmatrix_str[] = { "GBR", "bt709", "undef", "", "fcc", "bt470bg", "smpte170m", "smpte240m", "YCgCo", NULL }; - static char const *strtable_lookup( const char * const table[], int index ) { int i = 0; while( table[i] ) i++; @@ -169,223 +119,190 @@ static char const *strtable_lookup( const char * const table[], int index ) /***************************************************************************** * Help: *****************************************************************************/ -static void Help( x264_param_t *defaults ) -{ - fprintf( stderr, - "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 AVI or Avisynth if compiled with AVIS support (%s).\n" - "Outfile type is selected by filename:\n" - " .264 -> Raw bytestream\n" - " .mkv -> Matroska\n" - " .mp4 -> MP4 if compiled with GPAC support (%s)\n" - "\n" - "Options:\n" - "\n" - " -h, --help Print this help\n" - "\n" - "Frame-type options:\n" - "\n" - " -I, --keyint Maximum GOP size [%d]\n" - " -i, --min-keyint Minimum GOP size [%d]\n" - " --scenecut How aggressively to insert extra I-frames [%d]\n" - " -b, --bframes Number of B-frames between I and P [%d]\n" - " --no-b-adapt Disable adaptive B-frame decision\n" - " --b-bias Influences how often B-frames are used [%d]\n" - " --b-pyramid Keep some B-frames as references\n" - "\n" - " --no-cabac Disable CABAC\n" - " -r, --ref Number of reference frames [%d]\n" - " --nf Disable loop filter\n" - " -f, --filter Loop filter AlphaC0 and Beta parameters [%d:%d]\n" - "\n" - "Ratecontrol:\n" - "\n" - " -q, --qp Set QP (0=lossless) [%d]\n" - " -B, --bitrate Set bitrate\n" - " --crf Quality-based VBR (nominal QP)\n" - " --qpmin Set min QP [%d]\n" - " --qpmax Set max QP [%d]\n" - " --qpstep Set max QP step [%d]\n" - " --ratetol Allowed variance of average bitrate [%.1f]\n" - " --vbv-maxrate Max local bitrate [%d]\n" - " --vbv-bufsize Size of VBV buffer [%d]\n" - " --vbv-init Initial VBV buffer occupancy [%.1f]\n" - "\n" - " --ipratio QP factor between I and P [%.2f]\n" - " --pbratio QP factor between P and B [%.2f]\n" - " --chroma-qp-offset QP difference between chroma and luma [%d]\n" - "\n" - " -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" - " --stats Filename for 2 pass stats [\"%s\"]\n" - " --rceq Ratecontrol equation [\"%s\"]\n" - " --qcomp QP curve compression: 0.0 => CBR, 1.0 => CQP [%.2f]\n" - " --cplxblur Reduce fluctuations in QP (before curve compression) [%.1f]\n" - " --qblur Reduce fluctuations in QP (after curve compression) [%.1f]\n" - "\n" - " --zones //...\n" - " Tweak the bitrate of some regions of the video\n" - " Each zone is of the form\n" - " ,,