ffmpeg AVFrame获取完整的解码数据为char * [英] ffmpeg AVFrame get full decoded data to char*

查看:1049
本文介绍了ffmpeg AVFrame获取完整的解码数据为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到帧的循环和解码它与ffmpeg获得AVFrame作为其结果。

I get Frames in loop and decode it with ffmpeg getting AVFrame as e result of it.

所以我必须获取帧的必要的像素数据到char *作为回调函数的参数。那么我怎么能generete这样的char *数组?在互联网我看到一些例子,如:

So I must get neccessary pixel data of frame into char* and give as a callback function's parameter. So how I can generete such char* array? In internet I saw some examples such as:

for(y = 0; y< height; y ++)
{
fwrite(pFrame-> data [0] + y * pFrame-> linesize [0],1,width * 3,pFile);}

或类似这样的东西。是真的吗?和哪个大小会是我的char *?正如我看到的,我们写宽度* 3 *高度字节?

or something like this. Is it true? And which size would be my char* ? As I see we write width*3 *height bytes?

推荐答案

for(y=0; y<height; y++) { 
    fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
}

是的,是正确的。

这是写一行来自AVFrame->数据指针的3字节/像素(可能是RGB)。

Yes that's correct.
This is writing a line of 3byte/pixel (presumably RGB) from the AVFrame->data pointer.

ps。这样做的原因是每行数据的开始在一个新的4字节的存储器边界上 - 计算机以32位(4字节)的倍数访问存储器更有效。
所以如果你的像素大小(3bytes)和宽度不是4的倍数,那么你需要这样做而不是简单地复制 width * height * 3 bytes的数据。

ps. The reason for doing it like this is that the start of each row of data begins on a new 4byte memory boundary - the computer is more efficent at accessing memory in multiples of 32bits (4bytes). So if your pixel size (3bytes) and width aren't a multiple of 4 then you need to do this rather than simply copy width*height*3 bytes of data.

这篇关于ffmpeg AVFrame获取完整的解码数据为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆