[Libav-user] BGR24 - crash during encoding

Влад Гапчич gavlig at gmail.com
Wed Jun 20 23:36:08 CEST 2012


Hello everyone!

I'm writing an application which cuts videos in pieces with transcoding.
Generally it works, but sometimes it crashes on some certain files with
BGR24 pix_fmt when i transcode them into mpeg4 with YUV420p.
I tracked down that crash and it leaded me to ff_MPV_encode_picture
-> load_input_picture, and sigsegv occurres in this loop:

for (i = 0; i < 3; i++) {

....

int src_stride = pic_arg->linesize[i];

uint8_t *src = pic_arg->data[i];

....

    .....

    else {

        while (h--) {

            memcpy(dst, src, w); //<-----HERE

            dst += dst_stride;

            src += src_stride;

        }

    }

}

because src is NULL.


Everything was ok when i == 0, but on the next iteration *src* pointer
moves to another pic_arg->data[i] which is 0x0... I've noticed that
not only pic_arg->data[i], but linesize also contains only one

value(-2160) and that confused me a lot.


Could anyone tell me how can I fix that? I undestand that frame->data
and frame->linesize should contain at least three values, but they
contain only one after decoding.

At first i though that i need to convert frames from BGR24 to YUV420p,
but that doesn't help

here is the code of conversation BGR24->YUV420p:


AVFrame *

Videocut::convertFrameToYUV420(

    AVCodecContext *aCtx,

    AVFrame *aFrame

)

{

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

        return NULL;

        /* NOTREACHED */

    }


    SwsContext *imgConvertCtx = NULL;

    AVFrame *tempFrame = 0;

    /* as we only generate a YUV420P picture, we must convert it

       to the codec pixel format if needed */

    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

    );

    avcodec_get_frame_defaults(tempFrame);

    sws_scale(imgConvertCtx,

        aFrame->data,

        aFrame->linesize,

        0,

        aCtx->height,

        tempFrame->data,

        tempFrame->linesize

    );

    av_freep(aFrame);

    sws_freeContext(imgConvertCtx);

   return tempFrame;

}


I can show you all the code where i decode and encode, but it's all
huge and I don't want to make a book from this letter,

So you can find it here http://www.pasteall.org/33080/cpp


Btw, video has not common size 720x280, i don't if that could help.


Any help would be much appreciated!

Thank you guys in advance!


Best regards,

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


More information about the Libav-user mailing list