
# 自定义视频采集和渲染
 #### setExternalVideoCapture
```
- (int)setExternalVideoCapture:(BOOL)enabled format:(HWRtcVideoImageFormat)format;
```
【**功能说明**】
设置是否开启外部视频采集。需要在加入房间前调用。
【**请求参数**】
- enable：YES表示开启，NO表示关闭。默认为NO。
- format：设置外部采集的视频格式，默认为I420（即yuv420P）。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HWRtcErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0080.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 加入房间前调用，不支持房间内切换。
- 视频支持格式：默认为I420，format可选格式为yuv420p、rgba和texture2d，如果需要外部传入texture2d编码的数据，需要设置format为texture2d，否则传入yuv420p或者rgba。
- 如果使用外部输入视频数据，需要在加入房间后，按照一定时间间隔调用[pushExternalVideoFrame]接口输入视频数据。
 
 #### pushExternalVideoFrame
```
- (int)pushExternalVideoFrame:(HWRtcVideoFrame* _Nonnull)videoFrame;
```
【**功能说明**】
推送外部视频数据。
【**请求参数**】
videoFrame：视频自采集数据格式 ，具体请参见[HWRtcVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0082.html#rtc_05_0082__section199816620273)。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HWRtcErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0080.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 此方法调用前，需要先调用[setExternalVideoCapture]设置开启外部视频采集。
- 数据输入周期：同视频周期，1/帧率。
 
 #### setExternalMediaFrameOutput
```
- (int)setExternalMediaFrameOutput:(HWRtcMediaType)mediaType remoteEnable:(BOOL)remoteEnable localEnable:(BOOL)localEnable;
```
【**功能说明**】
设置是否开启视频流自渲染。开启后，回调[onRenderExternalVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0065.html#rtc_05_0065__section149653186316)中会有视频帧数据上报。
【**请求参数** 】
- mediaType："audio"表示设置音频，"video"表示设置视频 ，具体请参见[HWRtcMediaType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0082.html#rtc_05_0082__section322515347408)。
- remoteEnable：YES表示开启远端自渲染， NO表示关闭远端自渲染。默认为NO。
- localEnable：YES表示开启本地自渲染，NO表示关闭本地自渲染。默认为NO。
 
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HWRtcErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0080.html)。
 
 #### setExternalVideoFrameOutputWithFormat
```
- (int)setExternalVideoFrameOutputWithFormat:(HwRtcImageBufferFormat)format remoteEnable:(BOOL)remoteEnable localEnable:(BOOL)localEnable;
```
【**功能说明**】
设置是否开启视频流自渲染，指定Format参数。开启后，回调[onRenderExternalVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0065.html#rtc_05_0065__section149653186316)中会有视频帧数据上报。
【**请求参数** 】
- format ：指定输出视频内容帧格式，具体请参见[HwRtcImageBufferFormat](https://support.huaweicloud.com/csdk-rtc/rtc_05_0082.html#rtc_05_0082__section6612112412309)。
- remoteEnable：YES表示开启远端自渲染， NO表示关闭远端自渲染。默认为NO。
- localEnable：YES表示开启本地自渲染，NO表示关闭本地自渲染。默认为NO。
 
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HWRtcErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0080.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
在[onRenderExternalVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0065.html#rtc_05_0065__section149653186316)回调参数**videoFrame.format** 中体现设置的**format**参数。
 #### pushAuxExternalVideoFrame
```
- (int)pushAuxExternalVideoFrame:(HWRtcVideoFrame * _Nonnull)dataFrame;
```
【**功能说明**】
辅流输入外部视频数据。
【**请求参数**】
videoFrame：视频数据，具体请参考[HWRtcVideoFrame](https://support.huaweicloud.com/csdk-rtc/rtc_05_0082.html#rtc_05_0082__section199816620273)。
【**返回参数**】
- 0：成功。
- \> 0：失败。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 此接口与屏幕采集功能互斥。
- 如果需要传输texture2d编码流，需要设置setAuxExternalVideoCapture videoEnable参数为true，format设置为texture2d。
 
