# HighSpeedVideoSessionConfig

Artifact: [androidx.camera:camera-video](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/video/HighSpeedVideoSessionConfig.kt+class:androidx.camera.video.HighSpeedVideoSessionConfig) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

*** ** * ** ***

<br />

```
class HighSpeedVideoSessionConfig : SessionConfig
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.camera.core.SessionConfig](https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig) ||
|   | ↳ | [androidx.camera.video.HighSpeedVideoSessionConfig](https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig) |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` for high-speed video recording sessions.

This class encapsulates the necessary configurations for a high-speed video recording session, including video capture, optional preview and frame rate. Once configured, this config can be bound to a camera and lifecycle using `androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle` or `androidx.camera.lifecycle.LifecycleCameraProvider.bindToLifecycle`.

The supported frame rate range can be queried using `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#getSupportedFrameRateRanges()` with a specific `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig`. Supported frame rate is at least 120 FPS and is in multiples of 30. Common high-speed frame rates include 120 FPS, 240 FPS, and sometimes higher (like 480 FPS or even 960 FPS on some devices). If the given frame rate is not one of the supported frame rate ranges, an `IllegalArgumentException` will be thrown when binding to lifecycle.

High-speed recording is subject to specific constraints, aligning with those imposed by Android's camera2 `https://developer.android.com/reference/android/hardware/camera2/CameraConstrainedHighSpeedCaptureSession.html` API.

**Constraints:**

- `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#videoCapture()` and `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#preview()` must not have their target frame rates set explicitly.

- `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#videoCapture()` must not have its mirror mode set.

- If `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#preview()` is present, its resolution selector, target resolution and target aspect ratio must not be set. `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#preview()` will get the same resolution as `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#videoCapture()`. Note that the preview stream will not operate at the high frame rate as `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture`; instead, it is typically limited to at least 30 FPS by the camera system to ensure a smooth display.

- `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort` and `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect` are not supported.

Recording a high-speed video follows the same process as recording a regular video. This involves creating a `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder` with the desired `https://developer.android.com/reference/kotlin/androidx/camera/video/QualitySelector` and other settings. The supported qualities and related settings for high-speed sessions can be queried using `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getHighSpeedVideoCapabilities(androidx.camera.core.CameraInfo)`.

**Slow-Motion Video Recording:** When the `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#isSlowMotionEnabled()` flag is set to `true`, the recorded high-speed video will be processed and saved at a standard frame rate of 30 FPS. This creates the slow-motion effect upon playback. The resulting playback speed will be inversely proportional to the ratio of the high recording frame rate to the standard playback frame rate (30 FPS).

For example:

- If you record at 120 FPS with `isSlowMotionEnabled` set to `true`, the video will be saved at 30 FPS, resulting in a **1/4x speed** during playback (120 / 30 = 4).

- If you record at 240 FPS with `isSlowMotionEnabled` set to `true`, the video will be saved at 30 FPS, resulting in a **1/8x speed** during playback (240 / 30 = 8).

If `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#isSlowMotionEnabled()` is `false`, the video will be saved at the actual recording frame rate specified by the `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#(androidx.camera.video.VideoCapture,androidx.camera.core.Preview,android.util.Range,kotlin.Boolean,kotlin.Boolean)` parameter, e.g. 120 FPS, without slow-motion effect.

See the sample code below for recording a slow-motion video:

```kotlin
import androidx.camera.core.CameraSelector
import androidx.camera.core.DynamicRange
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.lifecycle.awaitInstance
import androidx.camera.video.HighSpeedVideoSessionConfig
import androidx.camera.video.Quality
import androidx.camera.video.QualitySelector
import androidx.camera.video.Recorder
import androidx.camera.video.VideoCapture
import androidx.core.content.ContextCompat

// Get ProcessCameraProvider.
val cameraProvider = ProcessCameraProvider.awaitInstance(activity)

// Get desired CameraInfo.
val cameraInfo = cameraProvider.getCameraInfo(CameraSelector.DEFAULT_BACK_CAMERA)

// Get high-speed video capabilities.
val videoCapabilities = Recorder.getHighSpeedVideoCapabilities(cameraInfo)
if (videoCapabilities == null) {
    // High-speed video is not supported on this camera device.
    return
}

// Get supported Qualities.
val supportedQualities = videoCapabilities.getSupportedQualities(DynamicRange.SDR)

// App's preferred qualities.
val preferredQualities = selectQualities(supportedQualities)

// Create UseCases and HighSpeedVideoSessionConfig.Builder
val preview = Preview.Builder().build()
preview.surfaceProvider = previewView.surfaceProvider
val recorder =
    Recorder.Builder()
        .setQualitySelector(QualitySelector.fromOrderedList(preferredQualities))
        .build()
val videoCapture = VideoCapture.withOutput(recorder)
val sessionConfigBuilder =
    HighSpeedVideoSessionConfig.Builder(videoCapture)
        .setPreview(preview)
        .setSlowMotionEnabled(true)

// Query supported frame rate ranges.
val supportedFrameRateRanges =
    cameraInfo.getSupportedFrameRateRanges(sessionConfigBuilder.build())

// App's preferred frame rate.
val preferredFrameRate = selectFrameRate(supportedFrameRateRanges)

// Apply preferred frame rate.
sessionConfigBuilder.setFrameRateRange(preferredFrameRate)

// Bind to lifecycle.
cameraProvider.bindToLifecycle(
    activity,
    CameraSelector.DEFAULT_BACK_CAMERA,
    sessionConfigBuilder.build(),
)

// Start recording.
val recording =
    recorder.prepareRecording(activity, generateOutputOptions()).start(
        ContextCompat.getMainExecutor(activity)
    ) { videoRecordEvent ->
        // ...
    }
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,kotlin.Array)` |   |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/Recorder#getHighSpeedVideoCapabilities(androidx.camera.core.CameraInfo)` |   |

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig.Builder` Builder for `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#HighSpeedVideoSessionConfig(androidx.camera.video.VideoCapture,androidx.camera.core.Preview,android.util.Range,kotlin.Boolean)( videoCapture: https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture<*>, preview: https://developer.android.com/reference/kotlin/androidx/camera/core/Preview?, frameRateRange: https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>, isSlowMotionEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Creates a `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig` from the given parameters. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#toString()()` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#isSlowMotionEnabled()` Whether to apply slow-motion effects to the recorded video. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview?` | `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#preview()` Optional `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` use case for displaying a preview during recording. |
| `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture<*>` | `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig#videoCapture()` The `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` use case for video recording. |

### Inherited functions

From [androidx.camera.core.SessionConfig](https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#setFeatureSelectionListener(java.util.concurrent.Executor,androidx.core.util.Consumer)(

executor: https://developer.android.com/reference/java/util/concurrent/Executor.html,

listener: https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature>>

)`

Sets a listener to know which features are finally selected when a session config is bound, based on the user-defined priorities/ordering for `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#preferredFeatureGroup()` and device capabilities.

### Inherited properties

From [androidx.camera.core.SessionConfig](https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect>` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#effects()`

The list of `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraEffect` to be applied on the camera session.
`https://developer.android.com/reference/kotlin/androidx/core/util/Consumer<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature>>` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#featureSelectionListener()`

Gets the feature selection listener set to this session config.
`https://developer.android.com/reference/java/util/concurrent/Executor.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#featureSelectionListenerExecutor()`

Gets the executor set to this session config for feature selection listener invocation.
`https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#frameRateRange()`

The desired frame rate range for the camera session.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#isAutoRotationEnabled()`

Whether to use auto rotation.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature>` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#preferredFeatureGroup()`

A list of preferred `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` ordered according to priority in descending order, i.e. a feature with a lower index in the list is considered to have a higher priority.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature>` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#requiredFeatureGroup()`

A set of `https://developer.android.com/reference/kotlin/androidx/camera/core/featuregroup/GroupableFeature` that are mandatory for the camera session configuration.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase>` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#useCases()`

The list of `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` to be attached to the camera and receive camera data.
`https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort?` `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig#viewPort()`

The `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort` to be applied on the camera session.

## Public constructors

### HighSpeedVideoSessionConfig

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
HighSpeedVideoSessionConfig(
    videoCapture: VideoCapture<*>,
    preview: Preview? = null,
    frameRateRange: Range<Int> = FRAME_RATE_RANGE_UNSPECIFIED,
    isSlowMotionEnabled: Boolean = false
)
```

Creates a `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig` from the given parameters.

| Parameters |
|---|---|
| `videoCapture: https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture<*>` | The `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` use case for video recording. |
| `preview: https://developer.android.com/reference/kotlin/androidx/camera/core/Preview? = null` | Optional `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` use case for displaying a preview during recording. |
| `frameRateRange: https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html> = FRAME_RATE_RANGE_UNSPECIFIED` | The desired frame rate range for high-speed video recording. The value must be one of the supported frame rates queried by `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#getSupportedFrameRateRanges()` with a specific `https://developer.android.com/reference/kotlin/androidx/camera/video/HighSpeedVideoSessionConfig`, or an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown when binding to lifecycle. |
| `isSlowMotionEnabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | Whether to apply slow-motion effects to the recorded video. |

## Public functions

### toString

```
open fun toString(): String
```

## Public properties

### isSlowMotionEnabled

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
val isSlowMotionEnabled: Boolean
```

Whether to apply slow-motion effects to the recorded video.

### preview

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
val preview: Preview?
```

Optional `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` use case for displaying a preview during recording.

### videoCapture

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/camera#1.5.0)

```
val videoCapture: VideoCapture<*>
```

The `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` use case for video recording.