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

ssshukla26 ssshukla26 at gmail.com
Wed Aug 24 09:56:18 EEST 2016


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");
            }



--
View this message in context: http://libav-users.943685.n4.nabble.com/Libav-user-Suggest-how-to-propery-fill-incomming-AVFrame-pointer-in-a-decoder-tp4662417p4662464.html
Sent from the libav-users mailing list archive at Nabble.com.


More information about the Libav-user mailing list