General Statement
In the previous article, we explained how to integrate the OPENH264 codec into the WEBRTC, but OPENH264 can only encode baseline H264 video, and in terms of encoding quality, X264 is the best, This article will explain how to integrate the X264 encoder into the WEBRTC, in order to achieve decoding, at the same time to use the ffmpeg. The overall process, as before, is divided into the re-encapsulation codec and the registration call two major steps, the registration call this step is not any different, mainly re-encapsulation this step is a big difference.re-encapsulate X264 encoding functionFirst of all, of course, download the X264 source code to compile the corresponding library for the call. Compile with MinGW under Windows, export the library using the Poxports tool, and finally get Libx264.dll and Libx264.lib, while X264.h and x264_ Config.h A total of four files are placed in the project directory and configured accordingly in the project properties.
The basic flow of video encoding using x264 is as follows[CPP] View plain copy #include <stdint.h> #include <stdio.h> #include <x264.h> 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; /* 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; &Nbsp; if ( x264_picture_alloc ( &pic, param.i_csp, param.i_width, param.i_height ) < 0 ) goto fail; h = x264_encoder_open ( ¶m); if ( !h ) goto fail; int luma_size = width * height; int chroma_size = luma_size / 4; /* Encode frames */ for ( ;; i_frame++ ) { /* Read input frame */ if ( fread ( pic.img.plane[0], 1, luma_size, stdin ) != luma_size ) break; if ( fread ( pic.img.plane[1], 1, chroma_size, stdin ) != chroma_size ) break; if ( fread ( pic.img.plane[2], 1, chroma_size, stdin ) != chroma_size ) break;