[Libav-user] Suggest how to propery fill incomming AVFrame pointer in a decoder !

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Suggest how to propery fill incomming AVFrame pointer in a decoder !

ssshukla26
My video decoder is decoding both mp4 files and h264 files. I just wanted to make sure that the way am filling incoming AVFrame pointer is proper or not, code snippet as shown below.

int qhw_decode_frame (AVCodecContext *avctx, void *pFrame, int *got_frame, AVPacket *avpkt)
{
...
    AVFrame *avframe = (AVFrame *) pFrame;
    avframe->width  = avctx->width; //width is1920
    avframe->height = avctx->height; //height is 1080
    avframe->format = AV_PIX_FMT_YUV420P;

    if(!(av_frame_get_buffer(avframe,1) < 0))
    {
         //Copy decoded data to avframe->data pointer.
    }
...
}


The above is the only a snippet of the code. I just want to understand that using av_frame_get_buffer is correct way to get data buffers to fill decoded data ?

I am copying decoded data in data buffer of avframe pointer, is that correct ?

The reason am asking this question is with ffmpeg my above code is working but when I integrate my ffmpeg with chromium, its crashing when I copy decoded data to avframe data pointers !
Regards, Sunny.
Reply | Threaded
Open this post in threaded view
|

Re: [Libav-user] Suggest how to propery fill incomming AVFrame pointer in a decoder !

ssshukla26
What is the difference between av_frame_get_buffer and av_image_alloc function ?

Cause using anyone of 'em, I am getting the same output !
Regards, Sunny.
Reply | Threaded
Open this post in threaded view
|

Re: [Libav-user] Suggest how to propery fill incomming AVFrame pointer in a decoder !

ssshukla26
Hi, I am able to fill incoming AVFrame pointers. Can anyone suggest how to wrap buf[] array of the avframe pointers ! I am too much stuck at this point .

Below the code, where decoder->dst_data[] array consist of Y, U and V buffers of image. And decoder->dst_linesize[] array consist of respective line sizes.

            AVFrame *avframe_src = NULL;

            if(NULL != (avframe_src = av_frame_alloc()))
            {
                avframe_src->width  = decoder->video_resolution.frame_width;
                avframe_src->height = decoder->video_resolution.frame_height;
                avframe_src->format = AV_PIX_FMT_YUV420P;

                //Allocate data array of avframe pointer
                if(av_image_alloc(avframe_src->data, avframe_src->linesize,
                            decoder->video_resolution.frame_width,
                            decoder->video_resolution.frame_height,
                            AV_PIX_FMT_YUV420P, 1) < 0)
                {
                    ERROR("Error : Allocating AVFRAME data\n");
                }
                else
                {
                    //Fill data array of avframe pointer with data from dst_data[0]
                    if(av_image_fill_arrays(avframe_src->data, avframe_src->linesize, decoder->dst_data[0],
                                avframe_src->format, avframe_src->width, avframe_src->height, 1) > 0)
                    {
                        //This is done to make sure that incoming avframe pointer's buf[0]
                        //has proper referenced buffer and YUV data
                        AVFrame *avframe_dst = (AVFrame *) pFrame;
                        if(0 == av_frame_ref(avframe_dst,avframe_src))
                        {
                            //av_buffer_create is used to make sure that
                            //buf array of avframe has wrapped data array
                            //such that its opaque value is set to the
                            //incoming opaque pointer
                            avframe_dst->buf[0] = av_buffer_create(avframe_dst->data[0], avframe_dst->linesize[0], NULL, opaque, 0);
                            avframe_dst->buf[1] = av_buffer_create(avframe_dst->data[1], avframe_dst->linesize[1], NULL, opaque, 0);
                            avframe_dst->buf[2] = av_buffer_create(avframe_dst->data[2], avframe_dst->linesize[2], NULL, opaque, 0);
                            if((NULL != avframe_dst->buf[0]) &&
                                    (NULL != avframe_dst->buf[1]) &&
                                    (NULL != avframe_dst->buf[2]))
                            {
                                ret = 1;
                            }
                        }
                    }
                    av_frame_unref(avframe_src);
                }
                av_frame_free(&avframe_src);
            }
            else
            {
                ERROR("Error : Not able to allocate avframe source pointer\n");
            }
Regards, Sunny.