ffmpeg中AVFrame解码linesize确定

一 测试环境

机型:Intel(R) Xeon(R) Gold 5218

ffmpeg版本4.3-dev

解码视频分辨率 720x1280 , 解码后 AVFrame linesize 768

解码视频分辨率 480x640, 解码后AVFrame linesize 512

二 linesize计算过程

avcodec_default_get_buffer2

-->update_frame_pool()

-->video_get_buffer()

video_get_buffer()-->

for (i = 0; i < 4 && pool->poolsi; i++) {

pic->linesizei = pool->linesizei;

由上面代码可见,AVFrame的linesize源自于 pool的linesize

pool linesize计算过程

update_frame_pool()

case AVMEDIA_TYPE_VIDEO: {

int linesize4;

int w = frame->width;

int h = frame->height;

int unaligned;

ptrdiff_t linesize14;

size_t size4;

avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);

do {

// NOTE: do not align linesizes individually, this breaks e.g. assumptions

// that linesize0 == 2*linesize1 in the MPEG-encoder for 4:2:2

ret = av_image_fill_linesizes(linesize, avctx->pix_fmt, w);

if (ret < 0)

goto fail;

// increase alignment of w for next try (rhs gives the lowest bit set in w)

w += w & ~(w - 1);

unaligned = 0;

for (i = 0; i < 4; i++)

unaligned |= linesizei % pool->stride_aligni;

} while (unaligned);

for (i = 0; i < 4; i++)

linesize1i = linesizei;

ret = av_image_fill_plane_sizes(size, avctx->pix_fmt, h, linesize1);

if (ret < 0)

goto fail;

for (i = 0; i < 4; i++) {

pool->linesizei = linesizei; //这里赋值给pool的linesize

linesize列表 通过 av_image_fill_linesizes获取,基本就是等于 width。

循环中

w += w & ~(w - 1); //每次将最低有效二进制位+1,这样做的目的,比如当前是16的整数倍,调整为32的整数倍。然后64的整数倍。

直到最终对 stride_aligni取余为0.

avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);

函数获取 stride_align

for (i = 0; i < 4; i++)

linesize_aligni = STRIDE_ALIGN;

#if HAVE_SIMD_ALIGN_64

define STRIDE_ALIGN 64 /* AVX-512 */

#elif HAVE_SIMD_ALIGN_32

define STRIDE_ALIGN 32

#elif HAVE_SIMD_ALIGN_16

define STRIDE_ALIGN 16

#else

define STRIDE_ALIGN 8

#endif

当机器支持avx512, STRIDE_ALIGN 64.

总结:ffmpeg的AVFrame linesize对齐方式和机器支持的simd有关,avx512就是64字节,avx256就是32字节

相关推荐
小鹿软件办公17 小时前
巧用 Adobe Audition 中置声道提取,轻松分离人声与背景音乐
adobe·ffmpeg·简鹿人声分离
2023自学中3 天前
imx6ull开发板 移植 ffmpeg 4.2.11 + x264 视频编码库
linux·ffmpeg·音视频·嵌入式·开发板
feibaoqq3 天前
光电视频监控技术(GB28181/ONVIF/私有协议)
ffmpeg·音视频·低空安防
feiyangqingyun4 天前
使用ffmpeg播放不同节目/实时切换节目并推流/推流不同的节目流
ffmpeg·推节目流·广播节目
左直拳5 天前
利用海康CVR实现视频流历史回放
ffmpeg·cvr·视频回放·历史视频
MR.欻6 天前
ZLMediaKit 源码分析(四):RTP/RTCP 协议栈实现分析
c++·人工智能·vscode·ffmpeg·音视频
晓py6 天前
音视频基础概念入门_FFmpeg学习笔记
学习·ffmpeg·音视频
daqinzl6 天前
Mpegts.js+FFmpeg+WebSocket+Node实时视频流实现方案
websocket·ffmpeg·node·mpegts.js
qq_369224337 天前
打开剪辑/直播/播放器提示ffmpeg.dll丢失?专属场景修复方法汇总
ffmpeg·dll·dll修复·dll错误
愿天垂怜7 天前
【C++脚手架】ffmpeg 库的介绍与使用
linux·服务器·开发语言·c++·ide·git·ffmpeg