VideoSink.OnSample 中的字节流看起来如何?
在 Silverlight 中,VideoSink.OnSample
方法用于获取原始网络摄像头数据。函数签名如下:
protected abstract void OnSample(
long sampleTimeInHundredNanoseconds,
long frameDurationInHundredNanoseconds,
byte[] sampleData
)
sampleData
的文档说
包含视频数据的字节流。根据相关视频格式信息将字节流处理成样本。
转到 VideoFormat
类,进入 视频格式。 PixelFormat
属性根据 文档:
- 未知 - 格式未知。
- Format32bppArgb - 该格式每个像素使用 32 位颜色信息,并使用 Alpha、红色、蓝色和绿色通道报告颜色信息。
我想了解 VideoSink.OnSample
方法看起来像。它只是像下面这样的像素数组吗?
sampleData[0] = image[x = 0, y = 0].R;
sampleData[1] = image[x = 0, y = 0].G;
sampleData[2] = image[x = 0, y = 0].B;
sampleData[3] = image[x = 0, y = 0].A;
sampleData[4 to 7] = image[x = 0, y = 1];
sampleData[8 to 11] = image[x = 0, y = 2];
sampleData[4*Height-4 to 4*Height-1] = image[x = 0, y = Height];
sampleData[4*Height to 4*Height+3] = image[x = 1, y = 0];
// ...
如果这么简单:顺序正确吗?
- 对于每个像素,R 先于 G,先于 B,先于 A
- ,第一列的所有像素,第二列的所有像素,依此类推
In Silverlight, the VideoSink.OnSample
method is used to get raw webcam data. The function signature is as follows:
protected abstract void OnSample(
long sampleTimeInHundredNanoseconds,
long frameDurationInHundredNanoseconds,
byte[] sampleData
)
Documentation for sampleData
says
A byte stream that contains video data. The byte stream should be processed into samples according to the relevant video format information.
Going to the documentation of the VideoFormat
class, one gets to the VideoFormat.PixelFormat
property which can only have two possible values according to the documentation:
- Unknown - The format is unknown.
- Format32bppArgb - The format uses 32 bits of color information per pixel and reports color information by using alpha, red, blue, and green channels.
I want to understand how the sampleData
parameter for the VideoSink.OnSample
method looks like. Is it simply an array of pixels like the following?
sampleData[0] = image[x = 0, y = 0].R;
sampleData[1] = image[x = 0, y = 0].G;
sampleData[2] = image[x = 0, y = 0].B;
sampleData[3] = image[x = 0, y = 0].A;
sampleData[4 to 7] = image[x = 0, y = 1];
sampleData[8 to 11] = image[x = 0, y = 2];
sampleData[4*Height-4 to 4*Height-1] = image[x = 0, y = Height];
sampleData[4*Height to 4*Height+3] = image[x = 1, y = 0];
// ...
If it is that easy: Is the ordering correct?
- R before G before B before A for each pixel
- All pixels of first column before all pixels of second column and so on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Format32bppArgb 像素格式,字节流如下所示:
因此,它是逐行存储的。
对于以字节 i 到 i+3 存储的每个像素,信息如下:
所有通道都存储为 [0; 范围内的整数]。 255] 其中 255 表示颜色通道的最大强度,并且表示 Alpha 通道的不透明。因此,除了排序之外,它的工作原理与预期一致。
The byte stream looks as follows for the Format32bppArgb pixel format:
So, it is stored row by row.
For each pixel which is stored in bytes i to i+3 the information comes as follows:
All channels are stored as an integer in the range [0; 255] where 255 indicates the maximum intensity for the color channels and opaque for the alpha channel. So, besides the ordering it works like expected.