资源简介
Ubuntu交叉编译OpenCV时需要安装的x264库,亲测可用。
代码片段和文件信息
/*****************************************************************************
* example.c: libx264 API usage example
*****************************************************************************
* Copyright (C) 2014-2017 x264 project
*
* Authors: Anton Mitrofanov
*
* 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. 51 Franklin Street Fifth Floor Boston MA 02111 USA.
*
* This program is also available under a commercial proprietary license.
* For more information contact us at licensing@x264.com.
*****************************************************************************/
#ifdef _WIN32
#include /* _setmode() */
#include /* _O_BINARY */
#endif
#include
#include
#include
#define FAIL_IF_ERROR( cond ... )\
do\
{\
if( cond )\
{\
fprintf( stderr __VA_ARGS__ );\
goto fail;\
}\
} while( 0 )
int main( int argc char **argv )
{
int width height;
x264_param_t param;
x264_picture_t pic;
x264_picture_t pic_out;
x264_t *h;
int i_frame = 0;
int i_frame_size;
x264_nal_t *nal;
int i_nal;
#ifdef _WIN32
_setmode( _fileno( stdin ) _O_BINARY );
_setmode( _fileno( stdout ) _O_BINARY );
_setmode( _fileno( stderr ) _O_BINARY );
#endif
FAIL_IF_ERROR( !(argc > 1) “Example usage: example 352x288 output.h264\n“ );
FAIL_IF_ERROR( 2 != sscanf( argv[1] “%dx%d“ &width &height ) “resolution not specified or incorrect\n“ );
/* Get default params for preset/tuning */
if( x264_param_default_preset( ¶m “medium“ NULL ) < 0 )
goto fail;
/* Configure non-default params */
param.i_csp = X264_CSP_I420;
param.i_width = width;
param.i_height = height;
param.b_vfr_input = 0;
param.b_repeat_headers = 1;
param.b_annexb = 1;
/* Apply profile restrictions. */
if( x264_param_apply_profile( ¶m “high“ ) < 0 )
goto fail;
if( x264_picture_alloc( &pic param.i_csp param.i_width param.i_height ) < 0 )
goto fail;
#undef fail
#define fail fail2
h = x264_encoder_open( ¶m );
if( !h )
goto fail;
#undef fail
#define fail fail3
int luma_size = width * height;
int chroma_size = luma_size / 4;
/* Encode frames */
for( ;; i_frame++ )
{
/* Read input frame */
if( fre
评论
共有 条评论