[Libav-user] How to allocate memory to store the image data (when use av_frame_alloc) ?
wm4
nfxjfg at googlemail.com
Thu Feb 5 11:52:08 CET 2015
On Thu, 5 Feb 2015 16:52:27 +0800
林其益 <antony.lin at topviewcorp.com> wrote:
> Dear Libav:
>
>
>
> Sorry for my poor english first.
>
>
>
> When using avcode_alloc_frame with avcodec_decode_video2 to decode h264
> stream, I found out that the data pointer of AVFrame will change everytime i
> decode a new frame.
>
> So if i need to buffer the decoded frame, i must copy the image data to
> other place (which allocate to store the image data).
>
>
>
> Could I not to allocate memory to store the image data (decode frame),
> because it will cost me 10 ms every frame ( 8 M resolution picture)?
>
>
>
> If I just store the AVFrame 's data pointer for every frames, It only had
> three sets of data pointer, so frames will be overwrite if you decode more
> than three times before to use it (to display it on the screen).
>
> Three sets of data pointer(3 frames buffer) is not enough for my implement
> of buffering decoded frame, I want to buffer 10 frames (decode 10 frames
> before to display it to the screen). Because I frame of H264 ( 8M
> resolution) will recevie very slow (more than 100 ms) and decode very slow
> (more than 100 ms), so I need buffer 10 frames to let display the stream
> smoothly.
>
>
>
> My question is :
>
> 1. Could ffmpeg decode h264 use 10 sets of data pointer (not just three
> sets of data pointer)?
>
> or
>
> 2. Could I allocate my own memory to the data[] array to AVFrame (not
> allocate by the ffmpeg library)?
>
>
>
> ////////////////////////////////////////////////////////////////////////////
> ////////////////////////////////////////////////////////////////////////////
> ///
>
> example code is describe as follow:
>
> /* c code bellow */
>
> AVFrame * pFrame;
>
> pFrame = avcode_alloc_frame();
>
> while (still_has_h264_frame)
>
> {
>
> avcodec_decode_video2(avctx, pFrame,....);
>
> printf(" data pointer of pFrame: %d %d %d \n", pFrame->data[0],
> pFrame->data[1], pFrame->data[2]);
>
> }
>
>
>
> /* result print log */
>
>
>
> data pointer of pFrame: 396361792 395445504 401670240
>
> data pointer of pFrame: 405536832 402628512 402864768
>
> data pointer of pFrame: 430506048 431489120 431725376
>
> data pointer of pFrame: 396361792 395445504 401670240 <--- from here ,
> the data point is the same as 1'th frame
>
> data pointer of pFrame: 405536832 402628512 402864768 <--- from here ,
> the data point is the same as 2'th frame
>
> data pointer of pFrame: 430506048 431489120 431725376 <--- from here ,
> the data point is the same as 3'th frame
>
> ......
>
>
>
> Best Regards,
>
> Antony Lin
>
>
>
>
>
The decoder already uses a memory pool for AVFrame image data.
More information about the Libav-user
mailing list