X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=x264.c;h=c4a740094d861198a6c4ecaf2b4f329d07d27274;hb=2b61248f4bcbb5f9df32d940732bc26d8feeda8c;hp=1a9cf963e470068266b9c63556cd88ec8da2acfc;hpb=9617e25c2ea08d029decb106fa7cf51a13a03706;p=x264 diff --git a/x264.c b/x264.c index 1a9cf963..c4a74009 100644 --- a/x264.c +++ b/x264.c @@ -1,10 +1,12 @@ /***************************************************************************** - * 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 $ + * 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,48 +20,27 @@ * * 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 -#include -#include - #include #include #define _GNU_SOURCE #include -#ifdef _MSC_VER -#include /* _setmode() */ -#include /* _O_BINARY */ -#endif - -#ifdef AVIS_INPUT -#include -#include -#endif - -#ifdef MP4_OUTPUT -#include -#endif - - #include "common/common.h" +#include "common/cpu.h" #include "x264.h" +#include "muxers.h" -#ifndef _MSC_VER -#include "config.h" +#ifdef _WIN32 +#include +#else +#define SetConsoleTitle(t) #endif -#include "matroska.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,63 +52,95 @@ static void SigIntHandler( int a ) } typedef struct { - int b_decompress; int b_progress; int i_seek; hnd_t hin; hnd_t hout; + FILE *qpfile; + FILE *tcfile_out; + double timebase_convert_multiplier; + int i_pulldown; } 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 - -/* 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 ); +/* i/o file operation function pointer structs */ +cli_input_t input; +static cli_output_t output; -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 ); +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 +}; +static const char * const muxer_names[] = +{ + "auto", + "raw", + "mkv", + "flv", #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 ); + "mp4", #endif + 0 +}; -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 const char * const pulldown_names[] = { "none", "22", "32", "64", "double", "triple", "euro", 0 }; -static void Help( x264_param_t *defaults ); +typedef struct{ + int mod; + uint8_t pattern[24]; + float fps_factor; +} cli_pulldown_t; + +enum pulldown_type_e +{ + X264_PULLDOWN_22 = 1, + X264_PULLDOWN_32, + X264_PULLDOWN_64, + X264_PULLDOWN_DOUBLE, + X264_PULLDOWN_TRIPLE, + X264_PULLDOWN_EURO +}; + +#define TB PIC_STRUCT_TOP_BOTTOM +#define BT PIC_STRUCT_BOTTOM_TOP +#define TBT PIC_STRUCT_TOP_BOTTOM_TOP +#define BTB PIC_STRUCT_BOTTOM_TOP_BOTTOM + +static const cli_pulldown_t pulldown_values[] = +{ + [X264_PULLDOWN_22] = {1, {TB}, 1.0}, + [X264_PULLDOWN_32] = {4, {TBT, BT, BTB, TB}, 1.25}, + [X264_PULLDOWN_64] = {2, {PIC_STRUCT_DOUBLE, PIC_STRUCT_TRIPLE}, 1.0}, + [X264_PULLDOWN_DOUBLE] = {1, {PIC_STRUCT_DOUBLE}, 2.0}, + [X264_PULLDOWN_TRIPLE] = {1, {PIC_STRUCT_TRIPLE}, 3.0}, + [X264_PULLDOWN_EURO] = {24, {TBT, BT, BT, BT, BT, BT, BT, BT, BT, BT, BT, BT, + BTB, TB, TB, TB, TB, TB, TB, TB, TB, TB, TB, TB}, 25.0/24.0} +}; + +#undef TB +#undef BT +#undef TBT +#undef BTB + +// indexed by pic_struct enum +static const float pulldown_frame_duration[10] = { 0.0, 1, 0.5, 0.5, 1, 1, 1.5, 1.5, 2, 3 }; + +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: ****************************************************************************/ @@ -135,13 +148,17 @@ int main( int argc, char **argv ) { x264_param_t param; cli_opt_t opt; + int ret; -#ifdef _MSC_VER - _setmode(_fileno(stdin), _O_BINARY); /* thanks to Marcos Morais */ - _setmode(_fileno(stdout), _O_BINARY); +#ifdef PTW32_STATIC_LIB + pthread_win32_process_attach_np(); + pthread_win32_thread_attach_np(); #endif - x264_param_default( ¶m ); +#ifdef _WIN32 + _setmode(_fileno(stdin), _O_BINARY); + _setmode(_fileno(stdout), _O_BINARY); +#endif /* Parse command line */ if( Parse( argc, argv, ¶m, &opt ) < 0 ) @@ -150,15 +167,15 @@ 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 -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 }; + return ret; +} static char const *strtable_lookup( const char * const table[], int index ) { @@ -166,395 +183,775 @@ 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 ) +static void Help( x264_param_t *defaults, int 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" - " .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" - " ,,