[x264-devel] Encoding frames with libavcodec

Dolevo Jay cmst at live.com
Tue Nov 27 13:34:28 CET 2012


Hello all,

I am trying to encode captured frames with libavcodec. My target is to encode couple of frames together but in the code below I try to encode only one image. My image is in RGB format and reachable by bits[0] pointer.The code runs but doesn't generate any encoded data. According to the return values that I give below, the code runs ok till avcodec_encode_video which returns zero. I see no change in encoded_buf after calling avcodec_encode_video. Could you please guide me to find the mistake? 

Here are some return values from the functions so that you can have some ideas.
ret1=5760000, ret2=2160000, ret3=900, ret4=0

Thank you,
-----------------------------------------------------------------
           AVCodec *codec;
    int encoded_buf_size;
    uint8_t *encoded_buf, *yuvoutbuffer;
    AVFrame* YUVframe;
    AVFrame *RGBframe;
    int ret1=0, ret2=0, ret3=0, ret4=0, ret5=0;


    YUVframe = avcodec_alloc_frame();
    RGBframe = avcodec_alloc_frame();


    c = mfSetContextParameters(c, aWidth, aHeight, mvGOPsize);


    codec = avcodec_find_encoder(CODEC_ID_H264);
    if (!codec) {gpLogDebug("Video codec not found."); return;}
    if (avcodec_open(c, codec) < 0) {gpLogDebug("Could not open codec."); return;}


    int nbytes = avpicture_get_size(PIX_FMT_YUV420P, c->width, c->height);
    yuvoutbuffer=(uint8_t *) av_malloc(nbytes);


    ret1=avpicture_fill((AVPicture*)RGBframe, (uint8_t *) bits[0], PIX_FMT_RGB32, c->width, c->height);
    ret2=avpicture_fill((AVPicture*)YUVframe, yuvoutbuffer, PIX_FMT_YUV420P, c->width, c->height);


    struct SwsContext* fooContext = sws_getContext(c->width, c->height,
                                      PIX_FMT_RGB32,
                                      c->width, c->height,
                                      PIX_FMT_YUV420P,
                                      SWS_FAST_BILINEAR, NULL, NULL, NULL);




    //perform the conversion
    ret3=sws_scale(fooContext, RGBframe->data, RGBframe->linesize, 0, c->height, YUVframe->data, YUVframe->linesize);
    YUVframe->pts = 0;

    encoded_buf_size = 150000;
    encoded_buf = (uint8_t *) malloc(encoded_buf_size);
    *encoded_buf = NULL;
    ret4 = avcodec_encode_video(c, encoded_buf, encoded_buf_size, YUVframe);
    //Here, I don't get any change in encoded_buf.
----------------

    c= avcodec_alloc_context();
    c->bit_rate = 512000;
    c->width = aWidth;
    c->height = aHeight;
    c->time_base.num = 1;
    c->time_base.den = 30;
    c->gop_size = 1;
    c->max_b_frames=0;
    c->bit_rate_tolerance= 40000;
    c->pix_fmt = PIX_FMT_YUV420P;
    c->me_range = 16;
    c->max_qdiff = 1;
    c->qmin = 1;
    c->qmax = 30;
    c->qcompress = 0.6;
    c->keyint_min = 120;
    c->refs = 3;
    c->trellis =1;
    c->rtp_payload_size = 500;
    c->level=13; //Level 1.3
    c->me_method=7;
    c->qblur=0.5;
    c->profile=66;//Baseline
    c->thread_count=1;


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20121127/2ec6f00d/attachment-0001.html>


More information about the x264-devel mailing list