Detailed codec libx264 libfdk_aac

First upgrade to use vs2015 compiler development program under the windows, because better c99 compatible syntax, do not change a lot of things.

libx264 compilation:

Indeed very easy in ubuntu, windows platform a little trouble, need to use MYSY2, now these open source projects, and some do not provide vs project, even if it offers cmake will do ah.

Find an older version of libx264 http://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20091006-2245.tar.bz2 vs the project with.

http://yasm.tortall.net/   need to install this, assembler, faster now.

Use vs 2015 Open the solution, libx264 successful compilation x264 test program will not do.

There are several functions that can not be found _x264_lookahead_init _x264_lookahead_is_empt _x264_lookahead_put_frame ....

Add encoder \ lookahead.c to lib, recompile success 2.

========== Rebuild All: 2 success, failure 0, 0 skipped ==========

1, RGB turn YUV 

ffmpeg method

 1 read_jpeg(file_image, &video_width, &video_height, &image_buff);
 2 
 3 uint8_t *indata[AV_NUM_DATA_POINTERS] = { 0 };
 4 indata[0] = (uint8_t *)image_buff;
 5 int inlinesize[AV_NUM_DATA_POINTERS] = { 0 };
 6 inlinesize[0] = frame->width * 3;
 7 
 8 ret = sws_scale(sws_ctx, indata, inlinesize, 0, frame->height, frame->data, frame->linesize);
 9 
10 for (int j = 0; j < 3; j++)
11 {
12     printf("j:%d linesize in:%d out:%d\n", j, inlinesize[j], frame->linesize[j]);
13 }

get_video_size: 480*272
file_image:img/image-00001.jpg
j:0 linesize in:1440 out:480
j:1 linesize in:0 out:256
j:2 linesize in:0 out:256

RGB YUV data is converted to an array, then how to get out of it?

 1 //方法1
 2 if (0 > x264_picture_alloc(&m_pic, m_param.i_csp, m_param.i_width, m_param.i_height*2))
 3 {
 4     printf("x264 [error]: malloc failed\n");
 5     return -1;
 6 }
 7 
 8 memcpy(m_pic.img.plane[0], frame->data[0], frame->linesize[0]*frame->height);
 9 m_pic.img.i_stride[0] = frame->linesize[0];
10 
11 memcpy(m_pic.img.plane[1], frame->data[1], frame->linesize[1]*frame->height/2);
12 m_pic.img.i_stride[1] = frame->linesize[1];
13 
14 memcpy(m_pic.img.plane[2], frame->data[2], frame->linesize[2]*frame->height/2);
15 m_pic.img.i_stride[2] = frame->linesize[2];
16 
17 //方法2
18 if (0 > x264_picture_alloc(&m_pic, m_param.i_csp, m_param.i_width, m_param.i_height))
19 {
20     printf("x264 [error]: malloc failed\n");
21     return -1;
22 }
23 sws_scale(sws_ctx, indata, inlinesize, 0, frame->height, m_pic.img.plane, m_pic.img.i_stride);

There are two ways, if you need to manually memcpy bigger picture memory applications, because of alignment issues, if ffmpeg incoming m_pic.img.plane, m_pic.img.i_stride do not need, it should be done inside ffmpeg realloc.

 

Reference example.c write test programs, x264_encoder_encode () i_nal been zero. So recompile the static libraries to facilitate debugging.

#x264-master# ./configure --prefix=/usr --disable-asm --enable-static --enable-shared --enable-debug

Compile the test program: g ++ encode_video.cpp -lavcodec -lavutil -lswscale -lswresample -lavformat -ljpeg libx264.a -lpthread -ldl

x264_encoder_encode () returns the problem has been zero, adjusting for several hours, like a variety of methods, change various parameters, to no avail, and finally found the problem turned out to be too little test YUV data.

 jpg image with the transfer of YUV encoded data appears after 40.

 1 x264 [debug]: frame=   0 QP=19.71 NAL=3 Slice:I Poc:0   I:396  P:0    SKIP:0    size=9052 bytes
 2 frame_size:9052
 3 file_image:img//image-00042.jpg
 4 Send frame 41
 5 x264 [debug]: frame=   1 QP=20.29 NAL=2 Slice:P Poc:2   I:6    P:140  SKIP:250  size=836 bytes
 6 frame_size:836
 7 file_image:img//image-00043.jpg
 8 Send frame 42
 9 x264 [debug]: frame=   2 QP=19.75 NAL=2 Slice:P Poc:4   I:0    P:43   SKIP:353  size=132 bytes
10 frame_size:132

Parameter settings, a key is generated every 10 I-frame, and B frame is disabled, because we do live broadcast, removed.

m_param.i_frame_reference = 10;
m_param.i_bframe = 0;

 

Guess you like

Origin www.cnblogs.com/ningci/p/12517789.html