VideoSink.OnSample 中的字节流看起来如何?

发布于 2024-11-07 20:30:27 字数 1853 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤ぢ 2024-11-14 20:30:28

对于 Format32bppArgb 像素格式,字节流如下所示:

sampleData[0- 3] = image[x=0, y=0]
sampleData[4- 7] = image[x=1, y=0]
sampleData[8-11] = image[x=2, y=0]
      ...                ...
                   image[x=w, y=0]
                   image[x=0, y=1]
                         ...
                   image[x=w, y=h]

因此,它是逐行存储的。

对于以字节 ii+3 存储的每个像素,信息如下:

sampleData[i+0] = BLUE
sampleData[i+1] = GREEN
sampleData[i+2] = RED
sampleData[i+3] = ALPHA

所有通道都存储为 [0; 范围内的整数]。 255] 其中 255 表示颜色通道的最大强度,并且表示 Alpha 通道的不透明。因此,除了排序之外,它的工作原理与预期一致。

The byte stream looks as follows for the Format32bppArgb pixel format:

sampleData[0- 3] = image[x=0, y=0]
sampleData[4- 7] = image[x=1, y=0]
sampleData[8-11] = image[x=2, y=0]
      ...                ...
                   image[x=w, y=0]
                   image[x=0, y=1]
                         ...
                   image[x=w, y=h]

So, it is stored row by row.

For each pixel which is stored in bytes i to i+3 the information comes as follows:

sampleData[i+0] = BLUE
sampleData[i+1] = GREEN
sampleData[i+2] = RED
sampleData[i+3] = ALPHA

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文