[Libav-user] BGR24 - crash during encoding - FIXED

Влад Гапчич gavlig at gmail.com
Thu Jun 21 13:50:40 CEST 2012


Hey everybody!

I've fixed my issue already :)
Yes, i needed to convert frames from BGR24 to YUV420p
and here how i do it:

AVFrame *

Videocut::convertFrameToYUV420(

    AVCodecContext *aCtx,

    AVFrame *aFrame

)

{

    if (NULL == aFrame || NULL == aCtx) {

        return NULL;

        /* NOTREACHED */

    }


    SwsContext *imgConvertCtx = NULL;

    AVFrame *tempFrame = 0;


    imgConvertCtx = sws_getContext(

        aCtx->width,

        aCtx->height,

        aCtx->pix_fmt,

        aCtx->width,

        aCtx->height,

        PIX_FMT_YUV420P,

        SWS_BICUBIC,

        NULL,

        NULL,

        NULL

    );

    if (NULL == imgConvertCtx) {

        cout << "\nCan not initialize the conversion context\n";

        return NULL;

        /* NOTREACHED */

    }


    tempFrame = avcodec_alloc_frame();

    if (NULL == tempFrame) {

        sws_freeContext(imgConvertCtx);

        return NULL;

        /* NOTREACHED */

    }


    int numBytes = avpicture_get_size(PIX_FMT_YUV420P, aCtx->width,
aCtx->height);

    uint8_t *buffer = new uint8_t[numBytes];

    avpicture_fill(

        (AVPicture *)tempFrame,

        buffer,

        PIX_FMT_YUV420P,

        aCtx->width,

        aCtx->height

    );


    sws_scale(imgConvertCtx,

        aFrame->data,

        aFrame->linesize,

        0,

        aCtx->height,

        tempFrame->data,

        tempFrame->linesize

    );


    av_free(aFrame);

    sws_freeContext(imgConvertCtx);


   return tempFrame;

}


Cheers!

gavlig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120621/dba684b3/attachment.html>


More information about the Libav-user mailing list