'Determining size of data[0] in AVFrame of FFMPEG
I am trying to allocate AVFrame->data[0] of a video frame to uint8_t* buffer using the following lines of code :
size_t sizeOfFrameData = mpAVFrameInput->linesize[0] * mpAVFrameInput->height;
memcpy(mFrameData, mpAVFrameInput->data[0], sizeOfFrameData);
I would like to know if this is a correct way of copying frame data to uint8_t* variable in FFMPEG?
Solution 1:[1]
Given avpicture_get_size() is deprecated , this is possible with:
int numBytes = av_image_get_buffer_size(
enum AVPixelFormat
int width,
int height,
int align
);
note that for align value of 32 is usually used , I have seen posts using 1 bit might cause distortion on the frame;
Its possible however to fill frame buffer data (i.e without size information) with :
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4],
const uint8_t *src,
enum AVPixelFormat pix_fmt, int width, int height, int align);
Solution 2:[2]
The avpicture_* API is now deprecated. Instead, use av_image_fill_plane_sizes to get each plane's size (the size of data[0] array).
int av_image_fill_plane_sizes (
size_t size[4],
enum AVPixelFormat pix_fmt,
int height,
const ptrdiff_t linesizes[4]
)
Note that the linesizes should be converted to ptrdiff_t (long long*) first.
You can find more here: https://www.ffmpeg.org/doxygen/trunk/group__lavu__picture.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | genpfault |
| Solution 2 | Adrian Mole |
