# AgoraVideoFrame (/zh-CN/api-reference/rtc/ios/class-externalvideoframe)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

<a id="class_externalvideoframe__prototype"></a>

```objc
__attribute__((visibility("default"))) @interface AgoraVideoFrame : NSObject
@property(assign, nonatomic) NSInteger format;
@property(assign, nonatomic) CMTime time;
@property(assign, nonatomic) int stride DEPRECATED_MSG_ATTRIBUTE("use strideInPixels instead");
@property(assign, nonatomic) int strideInPixels;
@property(assign, nonatomic) int height;
@property(assign, nonatomic) CVPixelBufferRef _Nullable textureBuf;
@property(strong, nonatomic) IMAGE_CLASS * _Nullable image;
@property(strong, nonatomic) NSData *_Nullable dataBuf;
@property(strong, nonatomic) NSData *_Nullable alphaBuf;
@property(assign, nonatomic) AgoraAlphaStitchMode alphaStitchMode;
@property(assign, nonatomic) int cropLeft;
@property(assign, nonatomic) int cropTop;
@property(assign, nonatomic) int cropRight;
@property(assign, nonatomic) int cropBottom;
@property(assign, nonatomic) int rotation;
@property(strong, nonatomic) AgoraColorSpace *_Nullable colorSpace;
@end
```

<a id="class_externalvideoframe__detailed_desc"></a>

:::note
注：

1. `strideInPixels`：步幅单位为像素，而非字节。
2. 关于帧的宽度和高度：未定义 `width` 字段，但可以通过以下方式推导：

`croppedWidth = (strideInPixels - cropLeft - cropRight)``croppedHeight = (height - cropTop - cropBottom)`

1. 关于裁剪：如果缓冲区包含无效数据，可以通过裁剪去除。例如，帧大小为 360 x 640，缓冲区步幅为 368，即右侧多出 8 像素用于填充，此时可以设置：

`strideInPixels = 368;``height = 640;``cropRight = 8;``// cropLeft、cropTop、cropBottom 默认为 0。`
:::

<a id="class_externalvideoframe__parameters"></a>

## 属性 [#属性]

<ParameterList>
<a id="format"></a>
<Parameter name="format">

输入视频帧的格式。该参数必须指定为以下值之一：1：I420；2：BGRA；3：NV21；4：RGBA；5：IMC2；7：ARGB；8：NV12；12：iOS 纹理（`CVPixelBufferRef`）；16：I422。

</Parameter>
<a id="time"></a>
<Parameter name="time">

输入视频帧的时间戳（毫秒）。时间戳错误会导致帧丢失或音视频不同步。

</Parameter>
<a id="stride"></a>
<Parameter name="stride">

帧的行跨度，即相邻两行视频帧之间的像素数。单位为像素，而非字节。处理视频数据时，需根据此参数处理每行像素数据之间的偏移，否则可能导致图像失真。

:::note
注：

- 如果视频为纹理格式，请将此参数设置为纹理的宽度。
- 如果视频帧格式为 12，请勿使用此字段。
:::

</Parameter>
<a id="strideinpixels"></a>
<Parameter name="strideInPixels">

输入视频帧的行间距，单位为像素而非字节。对于纹理格式，该值为纹理的宽度。

:::note
注： 不适用于 iOS 纹理。
:::

</Parameter>
<a id="height"></a>
<Parameter name="height">

输入视频帧的高度（像素行数）。

:::note
注： 不适用于 iOS 纹理。
:::

</Parameter>
<a id="texturebuf"></a>
<Parameter name="textureBuf">

iOS 纹理的缓冲区。

</Parameter>
<a id="image"></a>
<Parameter name="image">

静态图像（iPhone 上为 `UIImage`，macOS 上为 `NSImage`）。

</Parameter>
<a id="databuf"></a>
<Parameter name="dataBuf">

原始数据缓冲区。

:::note
注： 不适用于 iOS 纹理。
:::

</Parameter>
<a id="alphabuf"></a>
<Parameter name="alphaBuf">

当前帧的 Alpha 通道，与视频帧的尺寸一致。每个像素的取值范围为 [0, 255]，其中 0 表示背景，255 表示前景。默认值为 nil。

</Parameter>
<a id="alphastitchmode"></a>
<Parameter name="alphaStitchMode">

Alpha 通道拼接模式，表示 `alphaBuf` 与视频帧的相对位置。详见 [AgoraAlphaStitchMode](/zh-CN/api-reference/rtc/ios/enum-alphastitchmode)。

</Parameter>
<a id="cropleft"></a>
<Parameter name="cropLeft">

左侧裁剪的像素数。默认值为 0。

</Parameter>
<a id="croptop"></a>
<Parameter name="cropTop">

顶部裁剪的像素数。默认值为 0。

</Parameter>
<a id="cropright"></a>
<Parameter name="cropRight">

右侧裁剪的像素数。默认值为 0。

</Parameter>
<a id="cropbottom"></a>
<Parameter name="cropBottom">

底部裁剪的像素数。默认值为 0。

</Parameter>
<a id="rotation"></a>
<Parameter name="rotation">

视频帧的顺时针旋转角度。可设置为 0、90、180 或 270。默认值为 0。

:::note
注： 详见文档中关于旋转的计算方式。
:::

</Parameter>
<a id="colorspace"></a>
<Parameter name="colorSpace">

视频帧的色彩空间配置。默认采用 Full Range 和 BT.709 标准。详见 [`VideoColorSpace`](https://developer.mozilla.org/en-US/docs/Web/API/VideoColorSpace)。

</Parameter>
</ParameterList>
