KSYAVFCapture Class Reference

Inherits from NSObject
Conforms to AVCaptureAudioDataOutputSampleBufferDelegate
AVCaptureVideoDataOutputSampleBufferDelegate
Declared in KSYAVFCapture.h

Overview

基于 AVFoundation的 音视频采集模块

  • 通过回调将采集的音频和视频数据传出
  • 将摄像头和音频的常用操作进行封装
  • 注意: 使用AVFoundation的音频采集时,可能无法进行后台采集

Other Methods

  isRunning

Whether or not the underlying AVCaptureSession is running

@property (readonly, nonatomic) BOOL isRunning

Declared In

KSYAVFCapture.h

  captureSession

The AVCaptureSession used to capture from the camera

@property (readonly, retain, nonatomic) AVCaptureSession *captureSession

Declared In

KSYAVFCapture.h

  captureSessionPreset

This enables the capture session preset to be changed on the fly

@property (readwrite, nonatomic, copy) NSString *captureSessionPreset

Declared In

KSYAVFCapture.h

  frameRate

采集帧率 有效范围为 0~30

@property (readwrite) int32_t frameRate

Declared In

KSYAVFCapture.h

  outputPixelFmt

输出图像的像素格式 有效值 为 NV12 和BGRA - kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange - kCVPixelFormatType_420YpCbCr8BiPlanarFullRange - kCVPixelFormatType_32BGRA

@property (readwrite) OSType outputPixelFmt

Declared In

KSYAVFCapture.h

  frontFacingCameraPresent

Easy way to tell which cameras are present on device

@property (readonly, getter=isFrontFacingCameraPresent) BOOL frontFacingCameraPresent

Declared In

KSYAVFCapture.h

  backFacingCameraPresent

Easy way to tell which cameras are present on device

@property (readonly, getter=isBackFacingCameraPresent) BOOL backFacingCameraPresent

Declared In

KSYAVFCapture.h

  inputCamera

Use this property to manage camera settings. Focus point, exposure point, etc.

@property (readonly) AVCaptureDevice *inputCamera

Declared In

KSYAVFCapture.h

  outputImageOrientation

This determines the rotation applied to the output image, based on the source material

@property (readwrite, nonatomic) UIInterfaceOrientation outputImageOrientation

Declared In

KSYAVFCapture.h

  bMirrorRearCamera

These properties determine whether or not the two camera orientations should be mirrored. By default, (YES, NO).

@property (readwrite, nonatomic) BOOL bMirrorFrontCamera , bMirrorRearCamera

Declared In

KSYAVFCapture.h

+ isBackFacingCameraPresent

后置摄像头是否存在

+ (BOOL)isBackFacingCameraPresent

Declared In

KSYAVFCapture.h

+ isFrontFacingCameraPresent

前置摄像头是否存在

+ (BOOL)isFrontFacingCameraPresent

Declared In

KSYAVFCapture.h

+ uiOrientationToAVOrientation:

UIInterfaceOrientation 转为 AVCaptureVideoOrientation

+ (AVCaptureVideoOrientation)uiOrientationToAVOrientation:(UIInterfaceOrientation)orien

Parameters

orien

UI 的朝向,比如状态栏相对Home键的位置

Declared In

KSYAVFCapture.h

Initialization and teardown

– initWithSessionPreset:cameraPosition:

Begin a capture session

- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition

Parameters

sessionPreset

Session preset to use

cameraPosition

Camera to capture from

Discussion

See AVCaptureSession for acceptable values

Declared In

KSYAVFCapture.h

– addAudioInputsAndOutputs

Add audio capture to the session. Adding inputs and outputs freezes the capture session momentarily, so you can use this method to add the audio inputs and outputs early, if you’re going to set the audioEncodingTarget later. Returns YES is the audio inputs and outputs were added, or NO if they had already been added.

- (BOOL)addAudioInputsAndOutputs

Declared In

KSYAVFCapture.h

– removeAudioInputsAndOutputs

Remove the audio capture inputs and outputs from this session. Returns YES if the audio inputs and outputs were removed, or NO is they hadn’t already been added.

- (BOOL)removeAudioInputsAndOutputs

Declared In

KSYAVFCapture.h

– removeInputsAndOutputs

Tear down the capture session

- (void)removeInputsAndOutputs

Declared In

KSYAVFCapture.h

Manage the camera video stream

– startCameraCapture

Start camera capturing

- (void)startCameraCapture

Declared In

KSYAVFCapture.h

– stopCameraCapture

Stop camera capturing

- (void)stopCameraCapture

Declared In

KSYAVFCapture.h

– pauseCameraCapture

Pause camera capturing

- (void)pauseCameraCapture

Declared In

KSYAVFCapture.h

– resumeCameraCapture

Resume camera capturing

- (void)resumeCameraCapture

Declared In

KSYAVFCapture.h

– cameraPosition

Get the position (front, rear) of the source camera

- (AVCaptureDevicePosition)cameraPosition

Declared In

KSYAVFCapture.h

– videoCaptureConnection

Get the AVCaptureConnection of the source camera

- (AVCaptureConnection *)videoCaptureConnection

Declared In

KSYAVFCapture.h

– rotateCamera

This flips between the front and rear cameras

- (void)rotateCamera

Declared In

KSYAVFCapture.h

– captureDimension

查询实际的采集分辨率

- (CGSize)captureDimension

Discussion

参见iOS的 AVCaptureSessionPresetXXX的定义

Declared In

KSYAVFCapture.h

– isTorchSupported

当前采集设备是否支持闪光灯

- (BOOL)isTorchSupported

Return Value

YES / NO

Discussion

通常只有后置摄像头支持闪光灯

Declared In

KSYAVFCapture.h

– toggleTorch

开关闪光灯

- (void)toggleTorch

Discussion

切换闪光灯的开关状态 开 <–> 关

Declared In

KSYAVFCapture.h

– setTorchMode:

设置闪光灯

- (void)setTorchMode:(AVCaptureTorchMode)mode

Parameters

mode

AVCaptureTorchModeOn/Off

Discussion

设置闪光灯的开关状态

开始预览后开始有效

请参考 AVCaptureTorchMode

Declared In

KSYAVFCapture.h

  audioProcessingCallback

音频处理回调接口

@property (nonatomic, copy) void ( ^ ) ( CMSampleBufferRef sampleBuffer ) audioProcessingCallback

Discussion

sampleBuffer 原始采集到的音频数据

请注意本函数的执行时间,如果太长可能导致不可预知的问题@discussion 请参考 CMSampleBufferRef

请参考 CMSampleBufferRef

Declared In

KSYAVFCapture.h

  videoProcessingCallback

视频处理回调接口

@property (nonatomic, copy) void ( ^ ) ( CMSampleBufferRef sampleBuffer ) videoProcessingCallback

Discussion

sampleBuffer 原始采集到的视频数据

请注意本函数的执行时间,如果太长可能导致不可预知的问题

请参考 CMSampleBufferRef

Declared In

KSYAVFCapture.h

  interruptCallback

采集被打断的消息通知

@property (nonatomic, copy) void ( ^ ) ( BOOL bInterrupt ) interruptCallback

Discussion

bInterrupt 为YES, 表明被打断, 采集暂停

bInterrupt 为NO, 表明恢复采集

Declared In

KSYAVFCapture.h