⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x264.c.svn-base

📁 H.264 source codes
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * x264: h264 encoder/decoder testing program. ***************************************************************************** * Copyright (C) 2003 Laurent Aimar * $Id: x264.c,v 1.1 2004/06/03 19:24:12 fenrir Exp $ * * Authors: Laurent Aimar <fenrir@via.ecp.fr> * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * 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. *****************************************************************************/#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include <signal.h>#define _GNU_SOURCE#include <getopt.h>#ifdef _MSC_VER#include <io.h>     /* _setmode() */#include <fcntl.h>  /* _O_BINARY */#endif#ifdef AVIS_INPUT#include <windows.h>#include <vfw.h>#endif#ifdef MP4_OUTPUT#include <gpac/m4_author.h>#endif#include "common/common.h"#include "x264.h"#ifndef _MSC_VER#include "config.h"#endif#define DATA_MAX 3000000uint8_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;static void    SigIntHandler( int a ){    if( b_exit_on_ctrl_c )        exit(0);    b_ctrl_c = 1;}typedef struct {    int b_decompress;    int b_progress;    int i_maxframes;    int i_seek;    hnd_t hin;    hnd_t hout;} 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_INPUTstatic 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 );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_OUTPUTstatic 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 );#endifstatic void Help( x264_param_t *defaults );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: ****************************************************************************/int main( int argc, char **argv ){    x264_param_t param;    cli_opt_t opt;#ifdef _MSC_VER    _setmode(_fileno(stdin), _O_BINARY);    /* thanks to Marcos Morais <morais at dee.ufcg.edu.br> */    _setmode(_fileno(stdout), _O_BINARY);#endif    x264_param_default( &param );    /* Parse command line */    if( Parse( argc, argv, &param, &opt ) < 0 )        return -1;    /* Control-C handler */    signal( SIGINT, SigIntHandler );    return Encode( &param, &opt );}/***************************************************************************** * 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"             " .mp4 -> MP4 if compiled with GPAC support (%s)\n"             "\n"             "Options:\n"             "\n"             "  -h, --help                  Print this help\n"             "\n"             "  -I, --keyint <integer>      Maximum GOP size [%d]\n"             "  -i, --min-keyint <integer>  Minimum GOP size [%d]\n"             "      --scenecut <integer>    How aggressively to insert extra I-frames [%d]\n"             "  -b, --bframes <integer>     Number of B-frames between I and P [%d]\n"             "      --no-b-adapt            Disable adaptive B-frame decision\n"             "      --b-bias <integer>      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 <integer>         Number of reference frames [%d]\n"             "      --nf                    Disable loop filter\n"             "  -f, --filter <alpha:beta>   Loop filter AlphaC0 and Beta parameters [%d:%d]\n"             "\n"             "  -q, --qp <integer>          Set QP [%d]\n"             "  -B, --bitrate <integer>     Set bitrate\n"             "      --qpmin <integer>       Set min QP [%d]\n"             "      --qpmax <integer>       Set max QP [%d]\n"             "      --qpstep <integer>      Set max QP step [%d]\n"             "      --ratetol <float>       Allowed variance of average bitrate [%.1f]\n"             "      --vbv-maxrate <integer> Max local bitrate [%d]\n"             "      --vbv-bufsize <integer> Size of VBV buffer [%d]\n"             "      --vbv-init <float>      Initial VBV buffer occupancy [%.1f]\n"             "\n"             "      --ipratio <float>       QP factor between I and P [%.2f]\n"             "      --pbratio <float>       QP factor between P and B [%.2f]\n"             "      --chroma-qp-offset <integer>  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 <string>        Filename for 2 pass stats [\"%s\"]\n"             "      --rceq <string>         Ratecontrol equation [\"%s\"]\n"             "      --qcomp <float>         QP curve compression: 0.0 => CBR, 1.0 => CQP [%.2f]\n"             "      --cplxblur <float>      Reduce fluctuations in QP (before curve compression) [%.1f]\n"             "      --qblur <float>         Reduce fluctuations in QP (after curve compression) [%.1f]\n"             "\n"             "  -A, --analyse <string>      Analyse options: [\"i4x4,p8x8,b8x8\"]\n"             "                                  - i4x4\n"             "                                  - p8x8, p4x4, b8x8\n"             "                                  - none, all\n"             "      --direct <string>       Direct MV prediction mode [\"temporal\"]\n"             "                                  - none, spatial, temporal\n"             "  -w, --weightb               Weighted prediction for B-frames\n"             "      --me <string>           Integer pixel motion estimation method [\"%s\"]\n"             "                                  - dia: diamond search, radius 1 (fast)\n"             "                                  - hex: hexagonal search, radius 2\n"             "                                  - esa: exhaustive search algorithm (slow)\n"             "      --merange <integer>     Maximum motion vector search range [%d]\n"             "  -m, --subme <integer>       Subpixel motion estimation quality: 1=fast, 5=best. [%d]\n"             "      --no-chroma-me          Ignore chroma in motion estimation\n"             "\n"             "      --level <integer>       Specify level (as defined by Annex A)\n"             "      --sar width:height      Specify Sample Aspect Ratio\n"             "      --fps <float|rational>  Specify framerate\n"             "      --seek <integer>        First frame to encode\n"             "      --frames <integer>      Maximum number of frames to encode\n"             "  -o, --output                Specify output file\n"             "\n"             "      --no-asm                Disable all CPU optimizations\n"             "      --no-psnr               Disable PSNR computation\n"             "      --quiet                 Quiet Mode\n"             "  -v, --verbose               Print stats for each frame\n"             "      --progress              Show a progress indicator while encoding\n"             "      --visualize             Show MB types overlayed on the encoded video\n"             "      --aud                   Use access unit delimiters\n"             "\n",            X264_BUILD, X264_VERSION,#ifdef AVIS_INPUT            "yes",#else            "no",#endif#ifdef MP4_OUTPUT            "yes",#else            "no",#endif            defaults->i_keyint_max,            defaults->i_keyint_min,            defaults->i_scenecut_threshold,            defaults->i_bframe,            defaults->i_bframe_bias,            defaults->i_frame_reference,            defaults->i_deblocking_filter_alphac0,            defaults->i_deblocking_filter_beta,            defaults->rc.i_qp_constant,            defaults->rc.i_qp_min,            defaults->rc.i_qp_max,            defaults->rc.i_qp_step,            defaults->rc.f_rate_tolerance,            defaults->rc.i_vbv_max_bitrate,            defaults->rc.i_vbv_buffer_size,            defaults->rc.f_vbv_buffer_init,            defaults->rc.f_ip_factor,            defaults->rc.f_pb_factor,            defaults->analyse.i_chroma_qp_offset,            defaults->rc.psz_stat_out,            defaults->rc.psz_rc_eq,            defaults->rc.f_qcompress,            defaults->rc.f_complexity_blur,            defaults->rc.f_qblur,            defaults->analyse.i_me_method==X264_ME_DIA ? "dia"            : defaults->analyse.i_me_method==X264_ME_HEX ? "hex"            : defaults->analyse.i_me_method==X264_ME_ESA ? "esa" : NULL,            defaults->analyse.i_me_range,            defaults->analyse.i_subpel_refine           );}/***************************************************************************** * Parse: *****************************************************************************/static int  Parse( int argc, char **argv,                   x264_param_t *param, cli_opt_t *opt ){    char *psz_filename = NULL;    x264_param_t defaults = *param;    char *psz;    char b_avis = 0;    memset( opt, 0, sizeof(cli_opt_t) );    /* Default input file driver */    p_open_infile = open_file_yuv;    p_get_frame_total = get_frame_total_yuv;    p_read_frame = read_frame_yuv;    p_close_infile = close_file_yuv;    /* Default output file driver */    p_open_outfile = open_file_bsf;    p_set_outfile_param = set_param_bsf;    p_write_nalu = write_nalu_bsf;    p_set_eop = set_eop_bsf;    p_close_outfile = close_file_bsf;    /* Parse command line options */    opterr = 0; // no error message    for( ;; )    {        int long_options_index;#define OPT_QPMIN 256#define OPT_QPMAX 257#define OPT_QPSTEP 258#define OPT_IPRATIO 260#define OPT_PBRATIO 261#define OPT_RATETOL 262#define OPT_RCSTATS 264#define OPT_RCEQ 265#define OPT_QCOMP 266#define OPT_NOPSNR 267#define OPT_QUIET 268#define OPT_SCENECUT 270#define OPT_QBLUR 271#define OPT_CPLXBLUR 272#define OPT_FRAMES 273#define OPT_FPS 274#define OPT_DIRECT 275#define OPT_LEVEL 276#define OPT_NOBADAPT 277#define OPT_BBIAS 278#define OPT_BPYRAMID 279#define OPT_CHROMA_QP 280#define OPT_NO_CHROMA_ME 281#define OPT_NO_CABAC 282#define OPT_AUD 283#define OPT_PROGRESS 284#define OPT_ME 285#define OPT_MERANGE 286#define OPT_VBVMAXRATE 287#define OPT_VBVBUFSIZE 288#define OPT_VBVINIT 289#define OPT_VISUALIZE 290#define OPT_SEEK 291        static struct option long_options[] =        {            { "help",    no_argument,       NULL, 'h' },            { "bitrate", required_argument, NULL, 'B' },            { "bframes", required_argument, NULL, 'b' },            { "no-b-adapt", no_argument,    NULL, OPT_NOBADAPT },            { "b-bias",  required_argument, NULL, OPT_BBIAS },            { "b-pyramid", no_argument,     NULL, OPT_BPYRAMID },            { "min-keyint",required_argument,NULL,'i' },            { "keyint",  required_argument, NULL, 'I' },            { "scenecut",required_argument, NULL, OPT_SCENECUT },            { "nf",      no_argument,       NULL, 'n' },            { "filter",  required_argument, NULL, 'f' },            { "no-cabac",no_argument,       NULL, OPT_NO_CABAC },            { "qp",      required_argument, NULL, 'q' },            { "qpmin",   required_argument, NULL, OPT_QPMIN },

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -