From: Anton Mitrofanov Date: Thu, 13 Nov 2014 19:52:00 +0000 (+0300) Subject: Simplify libx264 API usage example X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06882793b260824bc578d0530f64e7f30f2a9f39;p=libx264 Simplify libx264 API usage example --- diff --git a/example.c b/example.c index 385e3c6a..6f683662 100644 --- a/example.c +++ b/example.c @@ -24,26 +24,14 @@ *****************************************************************************/ #ifdef _WIN32 -/* The following two defines must be located before the inclusion of any system header files. */ -#define WINVER 0x0500 -#define _WIN32_WINNT 0x0500 -#include #include /* _setmode() */ #include /* _O_BINARY */ #endif #include #include -#include #include -/* Ctrl-C handler */ -static volatile int b_ctrl_c = 0; -static void sigint_handler( int a ) -{ - b_ctrl_c = 1; -} - #define FAIL_IF_ERROR( cond, ... )\ do\ {\ @@ -72,9 +60,6 @@ int main( int argc, char **argv ) _setmode( _fileno( stderr ), _O_BINARY ); #endif - /* Control-C handler */ - signal( SIGINT, sigint_handler ); - 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" ); @@ -105,17 +90,17 @@ int main( int argc, char **argv ) #undef fail #define fail fail3 + int luma_size = width * height; + int chroma_size = luma_size / 4; /* Encode frames */ - for( ; !b_ctrl_c; i_frame++ ) + for( ;; i_frame++ ) { /* Read input frame */ - int plane_size = width * height; - if( fread( pic.img.plane[0], 1, plane_size, stdin ) != plane_size ) + if( fread( pic.img.plane[0], 1, luma_size, stdin ) != luma_size ) break; - plane_size = ((width + 1) >> 1) * ((height + 1) >> 1); - if( fread( pic.img.plane[1], 1, plane_size, stdin ) != plane_size ) + if( fread( pic.img.plane[1], 1, chroma_size, stdin ) != chroma_size ) break; - if( fread( pic.img.plane[2], 1, plane_size, stdin ) != plane_size ) + if( fread( pic.img.plane[2], 1, chroma_size, stdin ) != chroma_size ) break; pic.i_pts = i_frame; @@ -129,7 +114,7 @@ int main( int argc, char **argv ) } } /* Flush delayed frames */ - while( !b_ctrl_c && x264_encoder_delayed_frames( h ) ) + while( x264_encoder_delayed_frames( h ) ) { i_frame_size = x264_encoder_encode( h, &nal, &i_nal, NULL, &pic_out ); if( i_frame_size < 0 )