简体   繁体   English

帧数据如何存储在 libav 中?

[英]How is frame data stored in libav?

I am trying to learn to use libav.我正在尝试学习使用 libav。 I have followed the very first tutorial on dranger.com, but I got a little confused at one point.我已经按照 dranger.com 的第一个教程进行操作,但有一次我有点困惑。

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

This code clearly works, but I don't quite understand why, particulalry I don't understand how the frame data in pFrame->data stored, whether or not it depends on the format/codec in use, why pFrame->data and pFrame->linesize is always referenced at index 0, and why we are adding y to pFrame->data[0] .这段代码显然有效,但我不太明白为什么,特别是我不明白pFrame->data中的帧数据是如何存储的,它是否取决于使用的格式/编解码器,为什么pFrame->datapFrame->linesize总是在索引 0 处引用,以及为什么我们将 y 添加到pFrame->data[0]

In the tutorial it says在教程中它说

We're going to be kind of sketchy on the PPM format itself;我们将对 PPM 格式本身进行粗略的介绍; trust us, it works.相信我们,它有效。

I am not sure if writing it to the ppm format is what is causing this process to seem so strange to me.我不确定是否将其写入 ppm 格式是导致此过程对我来说如此奇怪的原因。 Any clarification on why this code is the way it is and how libav stores frame data would be very helpful.任何有关此代码为何如此以及 libav 如何存储帧数据的说明都将非常有帮助。 I am not very familiar with media encoding/decoding in general, thus why I am trying to learn.一般来说,我对媒体编码/解码不是很熟悉,因此我想学习。

particularly I don't understand how the frame data in pFrame->data stored, whether or not it depends on the format/codec in use特别是我不明白 pFrame->data 中的帧数据如何存储,它是否取决于使用的格式/编解码器

Yes, It depends on the pix_fmt value.是的,这取决于pix_fmt值。 Some formats are planar and others are not.有些格式是平面的,有些则不是。

why pFrame->data and pFrame->linesize is always referenced at index 0,为什么 pFrame->data 和 pFrame->linesize 总是在索引 0 处引用,

If you look at the struct, you will see that data is an array of pointers/a pointer to a pointer.如果您查看该结构,您将看到data是一个指针数组/一个指向指针的指针。 So pFrame->data[0] is a pointer to the data in the first "plane".所以pFrame->data[0]是指向第一个“平面”中数据的指针。 Some formats, like RGB have a singe plane, where all data is stored in one buffer.一些格式,如 RGB,有一个单一平面,所有数据都存储在一个缓冲区中。 Other formats like YUV, use a separate buffer for each plane. YUV 等其他格式对每个平面使用单独的缓冲区。 eg Y = pFrame->data[0], U = pFrame->data[1], pFrame->data[3] Audio may use one plane per channel, etc.例如Y = pFrame->data[0], U = pFrame->data[1], pFrame->data[3]音频每个通道可以使用一个平面,等等。

and why we are adding y to pFrame->data[0].以及为什么我们将 y 添加到 pFrame->data[0]。

Because the example is looping over an image line by line, top to bottom.因为该示例是从上到下逐行循环图像。 To get the pointer to the fist pixel of any line, you multiply the linesize by the line number then add it to the pointer.要获得指向任何行的第一个像素的指针,请将行号乘以行号,然后将其添加到指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM