Camera controls
The Video SDK for macOS lets you control the local camera during a session: select a camera, mirror and rotate the local video, set the aspect ratio, and pan, tilt, and zoom (PTZ). These per-device operations run through ZMVideoSDKVideoHelper. To use more than one camera at the same time, see Multiple camera support.
Get the camera list
To enumerate the cameras available on the device, call getCameraList on the ZMVideoSDKVideoHelper. Each ZMVideoSDKCameraDevice carries the deviceID you'll need for selectCamera and the PTZ methods. Use getNumberOfCameras to read the count.
if let cameraList = ZMVideoSDK.shared()?.getVideoHelper()?.getCameraList() {
for camera in cameraList {
// Each device exposes deviceID, deviceName, and more.
}
}
NSArray<ZMVideoSDKCameraDevice *> *cameraList = [[[ZMVideoSDK sharedVideoSDK] getVideoHelper] getCameraList];
for (ZMVideoSDKCameraDevice *camera in cameraList) {
// Each device exposes deviceID, deviceName, and more.
}
Select a camera
To switch to a specific camera, pass a deviceID from getCameraList to selectCamera.
let didSelect = ZMVideoSDK.shared()?.getVideoHelper()?.selectCamera("cameraDeviceID")
BOOL didSelect = [[[ZMVideoSDK sharedVideoSDK] getVideoHelper] selectCamera:@"cameraDeviceID"];
To cycle to the next available camera without specifying a device, call switchCamera.
ZMVideoSDK.shared()?.getVideoHelper()?.switchCamera()
[[[ZMVideoSDK sharedVideoSDK] getVideoHelper] switchCamera];
Mirror the local video
Mirroring is a common convention for a front-facing camera, so the user sees themselves the way they would in a mirror. Use mirrorMyVideo(true) to enable and mirrorMyVideo(false) to disable. Use isMyVideoMirrored to read the current state.
let videoHelper = ZMVideoSDK.shared()?.getVideoHelper()
videoHelper?.mirrorMyVideo(true)
let isMirrored = videoHelper?.isMyVideoMirrored()
ZMVideoSDKVideoHelper *videoHelper = [[ZMVideoSDK sharedVideoSDK] getVideoHelper];
[videoHelper mirrorMyVideo:YES];
BOOL isMirrored = [videoHelper isMyVideoMirrored];
Rotate the local video
To update the orientation of the locally captured video, call rotateMyVideo with the desired ZMVideoRotation value.
ZMVideoSDK.shared()?.getVideoHelper()?.rotateMyVideo(ZMVideoRotation_90)
[[[ZMVideoSDK sharedVideoSDK] getVideoHelper] rotateMyVideo:ZMVideoRotation_90];
Aspect ratio of the local video
By default, the SDK renders video at the source aspect ratio. To force the original aspect ratio, use enableOriginalAspectRatio. Check the current setting with isOriginalAspectRatioEnabled.
ZMVideoSDK.shared()?.getVideoHelper()?.enableOriginalAspectRatio(true)
[[[ZMVideoSDK sharedVideoSDK] getVideoHelper] enableOriginalAspectRatio:YES];
Pan, tilt, and zoom
For a PTZ-capable camera, the local user can move the camera using turnCameraLeft, turnCameraRight, turnCameraUp, turnCameraDown, zoomCameraIn, and zoomCameraOut. Each method takes a range parameter between 10 and 100 that controls how far the camera moves per call, and the deviceID of the camera to move (pass nil for the selected camera).
Before moving the camera, confirm it can be controlled with canControlCamera.
let videoHelper = ZMVideoSDK.shared()?.getVideoHelper()
var canControl: ObjCBool = false
videoHelper?.canControlCamera(&canControl, deviceID: nil)
if canControl.boolValue {
videoHelper?.turnCameraLeft(20, deviceID: nil)
videoHelper?.turnCameraRight(20, deviceID: nil)
videoHelper?.turnCameraUp(20, deviceID: nil)
videoHelper?.turnCameraDown(20, deviceID: nil)
videoHelper?.zoomCameraIn(15, deviceID: nil)
videoHelper?.zoomCameraOut(15, deviceID: nil)
}
ZMVideoSDKVideoHelper *videoHelper = [[ZMVideoSDK sharedVideoSDK] getVideoHelper];
BOOL canControl = NO;
[videoHelper canControlCamera:&canControl deviceID:nil];
if (canControl) {
[videoHelper turnCameraLeft:20 deviceID:nil];
[videoHelper turnCameraRight:20 deviceID:nil];
[videoHelper turnCameraUp:20 deviceID:nil];
[videoHelper turnCameraDown:20 deviceID:nil];
[videoHelper zoomCameraIn:15 deviceID:nil];
[videoHelper zoomCameraOut:15 deviceID:nil];
}
Smaller range values produce finer movement, which makes UI controls (such as press-and-hold arrow buttons) feel responsive without overshooting the target. To control another participant's camera instead of your own, see Remote camera control.
Alpha channel mode
Alpha channel mode lets the SDK render video with a transparent background, useful for compositing a user's video over other content. It is gated by both device hardware and the current session state. For the capability checks, the enable call, and the raw-data callbacks, see Raw video with alpha channel.