首页 前端知识 FFmpeg源代码:av_image_get_buffer_size&av_image_copy_to_buffer

FFmpeg源代码:av_image_get_buffer_size&av_image_copy_to_buffer

2024-02-29 12:02:11 前端知识 前端哥 451 250 我要收藏
1. av_image_get_buffer_size 接口声明位于libavutil/imgutils.h
/**
 * Return the size in bytes of the amount of data required to store an
 * image with the given parameters.
 *
 * @param pix_fmt  the pixel format of the image
 * @param width    the width of the image in pixels
 * @param height   the height of the image in pixels
 * @param align    the assumed linesize alignment
 * @return the buffer size in bytes, a negative error code in case of failure
 */
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);

根据像素格式、宽、高、linesize 对其方式来计算所需的内存大小。

重点说明一个参数align:此参数是设定内存对齐的对齐数,也就是按多大的字节进行内存对齐。比如设置为1,表示按1字节对齐,那么得到的结果就是与实际的内存大小一样。再比如设置为4,表示按4字节对齐。也就是内存的起始地址必须是4的整倍数

2. av_image_copy_to_buffer:将图像数据拷贝到指定缓冲区

/**
 * Copy image data from an image into a buffer.
 *
 * av_image_get_buffer_size() can be used to compute the required size
 * for the buffer to fill.
 *
 * @param dst           a buffer into which picture data will be copied
 * @param dst_size      the size in bytes of dst
 * @param src_data      pointers containing the source image data
 * @param src_linesize  linesizes for the image in src_data
 * @param pix_fmt       the pixel format of the source image
 * @param width         the width of the source image in pixels
 * @param height        the height of the source image in pixels
 * @param align         the assumed linesize alignment for dst
 * @return the number of bytes written to dst, or a negative value
 * (error code) on error
 */
int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
                            const uint8_t * const src_data[4], const int src_linesize[4],
                            enum AVPixelFormat pix_fmt, int width, int height, int align);

转载请注明出处或者链接地址:https://www.qianduange.cn//article/2944.html
标签
评论
会员中心 联系我 留言建议 回顶部
复制成功!