[Libav-user] Regarding decoding the video data

Alexandre Millette amillett at matrox.com
Tue Aug 7 14:53:13 CEST 2012


Mohd Arshad Saleem wrote:
> We are working on H264 decoder side in which we are trying to decode the
> video data by using avcodec_decode_video() API.

avcodec_decode_video() is deprecated, you should use 

> 1) Just wanted to know the size or length of decoded data which we are
> receiving and in which field of structure the decoded data is getting
> stored.

The second parameter of avcodec_decode_video2 is a pointer to a AVFrame 
structure which will be filled with the decoded data upon returning.
AVFrame.data is an array that contains the decoded data, separated by 
channels (data[0] would be the Y data in YUV).
Be sure to allocate the AVFrame first with avcodec_alloc_frame() and use 
sws_scale() if you wish to convert your decoded data from any format 
(usually YUV) to a more convenient (RGB) format.

As for the size of the decoded data, you can use:
int numBytes = avpicture_get_size( mpCodecCtx->pix_fmt,
    mpCodecCtx->width, mpCodecCtx->height);
Where mpCodecCtx is your AVCodecContext structure pointer.
Although this would return the total size of the data decoded by 
avcodec_decode_video2 and not the size of each channel. You could also 
use AVFrame.linesize[i] * AVCodecContext.height to get the size of the 
array reserved for the i channel.
Again, you can use sws_scale() to convert to a RGB format and simplify 
your processing (assuming you can afford the performance cost).

Hope this helps,
Alex M.

More information about the Libav-user mailing list