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 recording mode:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints video recording mode. */
fun monitorVideoMode(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.recording()?.run {
            if (supportedModes().isEmpty()) {
                // setting value is not relevant if there is no supported value
                println("No supported value")
            } else {
                // get setting value
                val mode = mode()
                println("Current value: $mode")
                // updating flag
                println("Updating: $isUpdating")
            }
        }
    }
}

Example of output:

Current value is: STANDARD
Updating: false

Sample code to modify video recording mode:

/** Sets video recording mode. */
fun setVideoMode(drone: Drone, mode: CameraRecording.Mode) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // set setting value
        recording().setMode(mode)
    }
}

Trying to change the setting value to an unsupported value has no effect. Values supported by the camera are provided by CameraRecording.Setting.supportedModes().

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

/** Sets hyperlapse value. */
fun setHyperlapseValue(drone: Drone, hyperlapseValue: CameraRecording.HyperlapseValue) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // set setting value
        recording().setHyperlapseValue(hyperlapseValue)
    }
}

Camera 2#

Video recording resolution is configured with parameter Camera.Config.VIDEO_RECORDING_MODE.

Sample code to monitor video recording mode:

/** Reference on MainCamera peripheral. */
private var cameraRef: Ref<MainCamera>? = null

/** Monitors and prints video recording mode. */
fun monitorVideoMode(drone: Drone) {
    cameraRef = drone.getPeripheral(MainCamera::class.java) { camera ->
        // called on main thread when the camera peripheral changes
        camera?.run {
            // get configuration parameter
            config[Camera.Config.VIDEO_RECORDING_MODE].run {
                if (supportedValues(onlyCurrent = true).isEmpty()) {
                    // parameter value is not relevant
                    // if there is not supported values in current configuration
                    println("No supported value in current configuration")
                } else {
                    println("Current value: $value")
                }
            }
        }
    }
}

Example of output:

Current value is: STANDARD

Sample code to modify video recording mode:

/** Sets video recording mode. */
fun setVideoMode(drone: Drone, mode: Camera.VideoRecordingMode) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.VIDEO_RECORDING_MODE].let { configParam ->
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = mode
            // 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 retrieved by calling configParam.supportedValues(onlyCurrent = false).

For hyperlapse mode, the ratio of recorded frames can be configured with parameter Camera.Config.VIDEO_RECORDING_HYPERLAPSE, as follows:

/** Sets hyperlapse value. */
fun setHyperlapseValue(drone: Drone, hyperlapseValue: Camera.HyperLapseValue) {
    drone.getPeripheral(MainCamera::class.java)?.run {
        // create configuration editor, starting from current configuration
        val editor = config.edit(fromScratch = false)
        // get configuration parameter
        editor[Camera.Config.VIDEO_RECORDING_HYPERLAPSE].let { configParam ->
            // change parameter value,
            // and unset other parameters conflicting with this new value
            configParam.value = hyperlapseValue
            // complete configuration, by setting missing parameters values
            editor.autoComplete()
            // send new configuration to drone
            editor.commit()
        }
    }
}