X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=x264.c;h=74d5e2645a01b5d696aac1b79aac1f9fe82f57d9;hb=485172deeb75ca1eb88ac24b6ab6719b8a16825b;hp=738d8db5e0a056a9ec33311a1926f913a86607ad;hpb=470e1b284f31e294119c7bc457a762488b34dd60;p=x264 diff --git a/x264.c b/x264.c index 738d8db5..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,26 +38,17 @@ #include /* _O_BINARY */ #endif -#ifdef AVIS_INPUT -#include -#include -#endif - -#ifdef MP4_OUTPUT -#include +#ifndef _MSC_VER +#include "config.h" #endif #include "common/common.h" #include "x264.h" -#ifndef _MSC_VER -#include "config.h" -#endif +#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; @@ -67,31 +60,18 @@ static void SigIntHandler( int a ) } typedef struct { - int b_decompress; int b_progress; - int i_maxframes; 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 ); @@ -100,21 +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 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 ); @@ -128,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 @@ -144,150 +110,199 @@ int main( int argc, char **argv ) return Encode( ¶m, &opt ); } +static char const *strtable_lookup( const char * const table[], int index ) +{ + int i = 0; while( table[i] ) i++; + return ( ( index >= 0 && index < i ) ? table[ index ] : "???" ); +} + /***************************************************************************** * Help: *****************************************************************************/ -static void Help( x264_param_t *defaults ) +static void Help( x264_param_t *defaults, int b_longhelp ) { - 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" - " .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 [%d]\n" - " -B, --bitrate Set bitrate\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" - " ,,