Video recording mode#

Video recording can operate in different modes that can be configured with Camera APIs:

  • standard: standard recording mode

  • hyperlapse: records accelerated videos

  • slowMotion: record slowed down videos

  • highFramerate: record high-framerate videos (playback speed is x1)

Camera 1#

Sample code to monitor video mode:

/// Keep reference on MainCamera peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera>?

/// Monitors and prints video recording mode.
func monitorVideoMode(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {
            if camera.recordingSettings.supportedModes.isEmpty {
                // setting value is not relevant if there is no supported value
                print("No supported value")
            } else {
                // get setting value
                let videoMode = camera.recordingSettings.mode
                print("Current value is: \(videoMode)")
            }
        }
    }
}

Example of output:

Current value is: standard

Sample code to modify video mode:

/// Sets video mode.
func setVideoMode(drone: Drone, videoMode: CameraRecordingMode) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        // set setting value
        camera.recordingSettings.mode = videoMode
    }
}

Trying to change the setting value to an unsupported value has no effect. Values supported by the camera are provided by CameraRecordingSettings.supportedModes.

For hyperlapse mode, the ratio of recorded frames can be configured as follows:

/// Sets hyperlapse value.
func setHyperlapseValue(drone: Drone, hyperlapseValue: CameraHyperlapseValue) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera) {
        // set setting value
        camera.recordingSettings.hyperlapseValue = hyperlapseValue
    }
}

Camera 2#

Camera2 supports only standard recording mode.

Sample code to monitor video mode:

/// Keep reference on MainCamera2 peripheral to get notified of changes.
private var cameraRef: Ref<MainCamera2>?

/// Monitors and prints video recording mode.
func monitorVideoMode(drone: Drone) {
    cameraRef = drone.getPeripheral(Peripherals.mainCamera2) { camera in
        // called on main thread when the camera peripheral changes
        if let camera = camera {
            // get configuration parameter
            if let configParam = camera.config[Camera2Params.videoRecordingMode] {
                if configParam.currentSupportedValues.isEmpty {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    print("No supported value in current configuration")
                } else {
                    // get parameter value
                    let videoMode = configParam.value
                    print("Current value is: \(videoMode)")
                }
            }
        }
    }
}

Example of output:

Current value is: standard

Sample code to modify video mode:

/// Sets video mode.
func setVideoMode(drone: Drone, videoMode: Camera2VideoRecordingMode) {
    if let camera = drone.getPeripheral(Peripherals.mainCamera2) {
        // create configuration editor, starting from current configuration
        let editor = camera.config.edit(fromScratch: false)
        // retrieve configuration parameter
        if let configParam = editor[Camera2Params.videoRecordingMode] {
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = videoMode
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}

Trying to change the parameter value to an unsupported value has no effect. Values supported by the camera are provided by the parameter field configParam.overallSupportedValues.