human: 如何处理七牛云的实时音视频QNCameraVideoTrack

gpt: [实时音视频](https://developer.qiniu.com/rtc) > API 文档 > Android
>QNCameraVideoTrack

#  QNCameraVideoTrack

最近更新时间: 2023-10-20 15:07:02

本地视频相机 Track 类

Hierarchy

  * [QNTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8851/QNTrack-iOS)
    * [QNLocalTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8847/QNLocalTrack-iOS)
      * [QNLocalVideoTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8849/QNLocalVideoTrack-iOS)
        * QNCameraVideoTrack 
        * [QNScreenVideoTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8850/QNScreenVideoTrack-iOS)
        * [QNCustomVideoTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8853/QNCustomVideoTrack-iOS)
      * [QNLocalAudioTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8854/QNLocalAudioTrack-iOS)
        * [QNMicrophoneAudioTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8855/QNMicrophoneAudioTrack-iOS)
        * [QNCustomAudioTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8856/QNCustomAudioTrack-iOS)
    * [QNRemoteTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8857/QNRemoteTrack-iOS)
      * [QNRemoteVideoTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8858/QNRemoteVideoTrack-iOS)
      * [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8859/QNRemoteAudioTrack-iOS)

Index

Core Properties

  * userID
  * trackID
  * kind
  * tag
  * muted
  * delegate
  * cameraDelegate
  * captureDevicePosition
  * videoOrientation
  * torchOn
  * continuousAutofocusEnable
  * smoothAutoFocusEnabled
  * manualFocus
  * videoZoomFactor
  * supportedVideoFormats
  * videoActiveFormat
  * videoFormat
  * videoFrameRate
  * previewMirrorFrontFacing
  * previewMirrorRearFacing
  * encodeMirrorFrontFacing
  * encodeMirrorRearFacing

Core Methods

  * updateMute
  * destroy
  * sendSEI
  * sendSEIWithData
  * play
  * switchCamera[1/2]
  * switchCamera[2/2]
  * setBeautifyModeOn
  * setSmoothLevel
  * setWhiten
  * setRedden
  * setWaterMarkWithImage
  * clearWaterMark
  * pushImage
  * startCapture
  * stopCapture
  * setVideoEncoderConfig

Core Properties

userID

  * @property (nonatomic, readonly) NSString *userID;
  * 一路 Track 所属用户的唯一标识

trackID

  * @property (nonatomic, strong) NSString *trackID;
  * 一路 Track 在 Server 端的唯一标识

> 发布成功时由 SDK 自动生成，订阅/Mute 等操作依据此 trackID 来确定相应的 Track

kind

  * @property (nonatomic, readonly) [QNTrackKind](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/9254) kind;
  * 标识该路 Track 是音频还是视频

tag

  * @property (nonatomic, strong) NSString *tag;
  * Track 的 tag

> 当发布多路视频 Track 时，可用 tag 来作区分

muted

  * @property (nonatomic, assign, readonly) BOOL muted;
  * 标识 Track 是否为 mute 状态

delegate

  * @property (nonatomic, weak) id<[QNLocalVideoTrackDelegate](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/11970/QNLocalVideoTrackDelegate)> delegate;
  * 视频 Track 回调代理

cameraDelegate

  * @property (nonatomic, weak) id<[QNCameraVideoTrackDelegate](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/12438/QNCameraVideoTrackDelegate)> cameraDelegate;
  * 摄像头采集 Track 回调代理

captureDevicePosition

  * @property (nonatomic, assign, readonly) AVCaptureDevicePosition captureDevicePosition;
  * 摄像头的位置，只读变量，默认为 AVCaptureDevicePositionFront 前置

如需设置，请在
[QNCameraVideoTrackConfig](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8844/QNCameraVideoTrackConfig-
iOS) 中设置

videoOrientation

  * @property (nonatomic, assign) AVCaptureVideoOrientation videoOrientation;
  * 开启 camera 时的采集摄像头的旋转方向，默认为 AVCaptureVideoOrientationPortrait

torchOn

  * @property (nonatomic, assign, getter=isTorchOn) BOOL torchOn;
  * 是否开启手电筒，默认为 NO

continuousAutofocusEnable

  * @property (nonatomic, assign, getter=isContinuousAutofocusEnable) BOOL continuousAutofocusEnable;
  * 是否连续自动对焦，默认为 YES

smoothAutoFocusEnabled

  * @property (nonatomic, assign, getter=isSmoothAutoFocusEnabled) BOOL smoothAutoFocusEnabled;
  * 是否平滑对焦减缓抖动感，默认为 YES

> 适用于视频拍摄过程中，用来减缓因自动对焦产生的镜头伸缩，使画面不因快速的对焦而产生抖动感

manualFocus

  * @property (nonatomic, assign) CGPoint manualFocus;
  * 聚焦的位置，默认为 (0.5, 0.5)，即中间位置

(0,0) 代表左上, (1,1) 代表右下

videoZoomFactor

  * @property (nonatomic, assign) CGFloat videoZoomFactor;
  * 控制摄像头的缩放，默认为 1.0

> 设置的数值，务必小于等于 videoActiveForat.videoMaxZoomFactor，否则会设置失败

supportedVideoFormats

  * @property (nonatomic, strong, readonly) NSArray<AVCaptureDeviceFormat *> *supportedVideoFormats;
  * 设备支持的 formats

videoActiveFormat

  * @property (nonatomic, strong) AVCaptureDeviceFormat *videoActiveFormat;
  * 设备当前的 format

videoFormat

  * @property (nonatomic, copy) NSString *videoFormat;
  * 视频采集的分辨率，默认为 AVCaptureSessionPreset640x480

videoFrameRate

  * @property (nonatomic, assign) NSUInteger videoFrameRate;
  * 采集的视频数据的帧率，默认为 24

previewMirrorFrontFacing

  * @property (nonatomic, assign) BOOL previewMirrorFrontFacing;
  * 前置摄像头，预览是否开启镜像，默认为 YES

previewMirrorRearFacing

  * @property (nonatomic, assign) BOOL previewMirrorRearFacing;
  * 后置摄像头，预览是否开启镜像，默认为 NO

encodeMirrorFrontFacing

  * @property (nonatomic, assign) BOOL encodeMirrorFrontFacing;
  * 前置摄像头，对方观看时是否开启镜像，默认 NO

encodeMirrorRearFacing

  * @property (nonatomic, assign) BOOL encodeMirrorRearFacing;
  * 后置摄像头，对方观看时是否开启镜像，默认 NO

Core Methods

updateMute

  * \- (void)updateMute:(BOOL)mute;
  * 更新当前 Track 的 mute 值，静默后，SDK 将会发送静默帧数据

当静默状态改变后，远端用户将会收到
[QNRemoteVideoTrackDelegate.didMuteStateChanged](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/11947)
的回调

> 需要发布成功后才可以执行 mute 操作

Parameters

    * mute: BOOL 

是否静默 Track

destroy

  * \- (void)destroy;
  * 销毁本地音/视频 Track

> 在不使用该 Track 之后，请务必调用此接口

sendSEI

  * \- (void)sendSEI:(NSString *)videoSEI uuid:(NSString *)uuid repeatNmuber:(NSNumber *)repeatNumber;
  * 发送 SEI

> 该接口已废弃，请使用
> [QNLocalVideoTrack.sendSEIWithData](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8849)

> 需要停止发送 SEI，可以设置 videoSEI 为 nil，repeatNumber 为 0 即可

Parameters

    * videoSEI: NSString 

SEI 的消息内容

    * uuid: NSString 

设备 UUID

    * repeatNumber: NSNumber 

重复次数

sendSEIWithData

  * \- (void)sendSEIWithData:(NSData *)SEIData uuid:(NSData *)uuid repeatCount:(NSNumber *)repeatCount;
  * 发送 SEI

> SEIData SEI 内容，不超过 4096 个字节
>
> 需要停止发送 SEI，可以设置 SEIData 为 nil，repeatCount 为 0 即可

Parameters

    * SEIData: NSString 

SEI 的消息内容

    * uuid: NSString 

设备 UUID

    * repeatCount: NSNumber 

重复次数

play

  * \- (void)play:([QNVideoGLView](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/11950/QNVideoGLView-iOS) *)videoView;
  * 视频 Track 渲染

Parameters

    * videoView: [QNVideoGLView](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/11950/QNVideoGLView-iOS)

渲染的 view

switchCamera[1/2]

  * \- (void)switchCamera;
  * 切换前后摄像头

> 该接口废弃，请使用
> [QNCameraVideoTrack.switchCamera[2/2]](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/8852)

switchCamera[2/2]

  * \- (void)switchCamera:(nullable [QNCameraSwitchResultCallback](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/9254))callback;
  * 切换前后摄像头

Parameters

    * callback: [QNCameraSwitchResultCallback](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/9254)

切换摄像头返回结果的 Callback

setBeautifyModeOn

  * -(void)setBeautifyModeOn:(BOOL)beautifyModeOn;
  * 是否开启美颜

Parameters

    * beautifyModeOn: BOOL 

美颜开关

setSmoothLevel

  * -(void)setSmoothLevel:(CGFloat)smoothLevel;
  * 设置磨皮程度参数，范围从 0 ~ 1

> 如果美颜不开启，设置该参数无效

Parameters

    * beautify: CGFloat 

美颜程度

setWhiten

  * -(void)setWhiten:(CGFloat)whiten;
  * 设置美白程度参数，范围从 0 ~ 1

> 如果美颜不开启，设置该参数无效

Parameters

    * whiten: CGFloat 

美白程度

setRedden

  * -(void)setRedden:(CGFloat)redden;
  * 设置红润的程度参数，范围从 0 ~ 1

> 如果美颜不开启，设置该参数无效

Parameters

    * redden: CGFloat 

红润程度

setWaterMarkWithImage

  * -(void)setWaterMarkWithImage:(UIImage *)waterMarkImage position:(CGPoint)position;
  * 设置水印

Parameters

    * waterMarkImage: UIImage 

水印图片

    * position: CGPoint 

水印位置

clearWaterMark

  * -(void)clearWaterMark;
  * 移除水印

pushImage

  * \- (int)pushImage:(nullable UIImage *)image;
  * 设置摄像头 Track 发送图片，返回值代表接口调用是否成功，若接口调用成功，但是图片推流失败，将会通过 [QNCameraVideoTrackDelegate.didPushImageWithError](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/undefined) 接口回调相关错误。

> 由于某些特殊原因不想使用摄像头采集的数据作为发送视频数据时，可以使用该接口设置一张图片来替代。传入 nil 则关闭该功能。

> 请确保传入的 image 的宽和高是 16 的整数倍
>
> 请根据调用结果对应处理，返回 0 表示接口调用成功；非 0 则是具体错误码，表示接口调用失败

code | describe | message  
---|---|---  
QNRTCErrorImageParserFailed | 图片解析失败 | 请检查图片资源是否合法  
QNRTCErrorFatalError | 非预期错误 | 请确认是否已经正常创建 Track  
  
Parameters

    * image: UIImage 

图片

Returns 调用接口是否成功

startCapture

  * \- (void)startCapture;
  * 开启摄像头采集

stopCapture

  * \- (void)stopCapture;
  * 关闭摄像头采集

setVideoEncoderConfig

  * \- (void)setVideoEncoderConfig:(QNVideoEncoderConfig *)config;
  * 动态修改编码配置

Parameters

    * config: [QNVideoEncoderConfig](https://developer.qiniu.com/rtc/8640/QNCameraVideoTrack/11944/QNVideoEncoderConfig-iOS)

编码参数配置

以上内容是否对您有帮助？