大网数据广告活动
Web 标准与前端开发

VideoFrame: allocationSize() method

· 52CE 我爱测

The **`allocationSize()`** method of the VideoFrame interface returns the number of bytes required to hold the video as filtered by options passed into the method.

Web Codecs APIwindow_and_dedicated

The allocationSize() method of the VideoFrame interface returns the number of bytes required to hold the video as filtered by options passed into the method.

Syntax

allocationSize()
allocationSize(options)

Parameters

  • options
    • : An object containing the following:
      • rect
        • : The rectangle of pixels to copy from the VideoFrame. If unspecified the VideoFrame.visibleRect will be used. This is in the format of a dictionary object containing:
          • x: The x-coordinate.
          • y: The y-coordinate.
          • width: The width of the frame.
          • height: The height of the frame.
      • layout
        • : A list containing the following values for each plane in the VideoFrame. Planes may not overlap. If unspecified the planes will be tightly packed:
          • offset
            • : An integer representing the offset in bytes where the given plane begins.
          • stride
            • : An integer representing the number of bytes, including padding, used by each row of the plane.
      • format
        • : A pixel format for the pixel data in the destination. Can be set to "RGBA", "RGBX", "BGRA", "BGRX". If unspecified, the VideoFrame.format will be used.
      • colorSpace
        • : Specifies the color space of the pixel data in the destination. Can be set to "srgb" for the sRGB color space or "display-p3" for the display-p3 color space. Only applicable for RGB pixel formats. If unspecified, "srgb will be used.

Return value

An integer containing the number of bytes needed to hold the frame as specified by options.

Examples

In the following example the allocationSize is returned for the rectangle at top left with dimensions of 800 by 600.

const videoRect = {
  x: 0,
  y: 0,
  width: 800,
  height: 600,
};
let size = VideoFrame.allocationSize({ rect: videoRect });

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。