IVideoFrameObserver

The IVideoFrameObserver class.

You can call RegisterVideoFrameObserver to register or unregister an IVideoFrameObserver object.

OnCaptureVideoFrame

Occurs each time the SDK receives a video frame captured by local devices.

public virtual bool OnCaptureVideoFrame(VIDEO_SOURCE_TYPE sourceType, VideoFrame videoFrame)

After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. In this callback, you can get the video data captured by local devices. You can then pre-process the data according to your scenarios.

Once the pre-processing is complete, you can directly modify videoFrame in this callback, and set the return value to true to send the modified video data to the SDK.

Attention:
  • The video data that this callback gets has not been pre-processed such as watermarking, cropping, and rotating.
  • If the video data type you get is RGBA, the SDK does not support processing the data of the alpha channel.

Parameters

sourceType
Video source types, including cameras, screens, or media player. See VIDEO_SOURCE_TYPE.
videoFrame
The video frame. See VideoFrame.
Note: The default value of the video frame data format obtained through this callback is as follows:
  • Android: I420 or RGB (GLES20.GL_TEXTURE_2D)
  • iOS: I420 or CVPixelBufferRef
  • macOS: I420 or CVPixelBufferRef
  • Windows: YUV420

Returns

  • true: Sets the SDK to receive the video frame.
  • false: Sets the SDK to discard the video frame.

OnPreEncodeVideoFrame

Occurs each time the SDK receives a video frame before encoding.

public virtual bool OnPreEncodeVideoFrame(VIDEO_SOURCE_TYPE sourceType, VideoFrame videoFrame)

After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. In this callback, you can get the video data before encoding and then process the data according to your particular scenarios.

After processing, you can send the processed video data back to the SDK in this callback.

Attention:
  • To get the video data captured from the second screen before encoding, you need to set POSITION_PRE_ENCODER (1 << 2) as a frame position through the position parameter of the RegisterVideoFrameObserver method.
  • The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.

Parameters

sourceType

The type of the video source. See VIDEO_SOURCE_TYPE.

videoFrame
The video frame. See VideoFrame.
Note: The default value of the video frame data format obtained through this callback is as follows:
  • Android: I420 or RGB (GLES20.GL_TEXTURE_2D)
  • iOS: I420 or CVPixelBufferRef
  • macOS: I420 or CVPixelBufferRef
  • Windows: YUV420

Returns

  • true: Sets the SDK to receive the video frame.
  • false: Sets the SDK to discard the video frame.

OnRenderVideoFrame

Occurs each time the SDK receives a video frame sent by the remote user.

public virtual bool OnRenderVideoFrame(string channelId, uint remoteUid, VideoFrame videoFrame)

After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. In this callback, you can get the video data sent from the remote end before rendering, and then process it according to the particular scenarios.

Note: If you use Unity for development, Agora only supports sending video data in YUV format to SDK. Ensure that you set mode as INTPTR when you call the RegisterVideoFrameObserver method to register a video frame observer.

Parameters

remoteUid
The user ID of the remote user who sends the current video frame.
videoFrame
The video frame. See VideoFrame.
Note: The default value of the video frame data format obtained through this callback is as follows:
  • Android: I420 or RGB (GLES20.GL_TEXTURE_2D)
  • iOS: I420 or CVPixelBufferRef
  • macOS: I420 or CVPixelBufferRef
  • Windows: YUV420
channelId
The channel ID.

Returns

  • true: Sets the SDK to receive the video frame.
  • false: Sets the SDK to discard the video frame.