# 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 />

```
public final class HighSpeedVideoSessionConfig extends SessionConfig
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.camera.core.SessionConfig](https://developer.android.com/reference/androidx/camera/core/SessionConfig) ||
|   | ↳ | [androidx.camera.video.HighSpeedVideoSessionConfig](https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig) |

*** ** * ** ***

A `https://developer.android.com/reference/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/androidx/camera/core/CameraInfo#getSupportedFrameRateRanges()` with a specific `https://developer.android.com/reference/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/androidx/camera/video/HighSpeedVideoSessionConfig#videoCapture()` and `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#preview()` must not have their target frame rates set explicitly.

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

- If `https://developer.android.com/reference/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/androidx/camera/video/HighSpeedVideoSessionConfig#preview()` will get the same resolution as `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#videoCapture()`. Note that the preview stream will not operate at the high frame rate as `https://developer.android.com/reference/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/androidx/camera/core/ViewPort` and `https://developer.android.com/reference/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/androidx/camera/video/Recorder` with the desired `https://developer.android.com/reference/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/androidx/camera/video/Recorder#getHighSpeedVideoCapabilities(androidx.camera.core.CameraInfo)`.

**Slow-Motion Video Recording:** When the `https://developer.android.com/reference/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/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/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/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,kotlin.Array)` |   |
| `https://developer.android.com/reference/androidx/camera/video/Recorder#getHighSpeedVideoCapabilities(androidx.camera.core.CameraInfo)` |   |

## Summary

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#HighSpeedVideoSessionConfig(androidx.camera.video.VideoCapture,androidx.camera.core.Preview,android.util.Range,kotlin.Boolean)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/video/VideoCapture<@https://developer.android.com/reference/androidx/annotation/NonNull ?> videoCapture, https://developer.android.com/reference/androidx/camera/core/Preview preview, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/util/Range.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> frameRateRange, boolean isSlowMotionEnabled )` Creates a `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig` from the given parameters. |

| ### Public methods |
|---|---|
| `final https://developer.android.com/reference/androidx/camera/core/Preview` | `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#getPreview()()` Optional `https://developer.android.com/reference/androidx/camera/core/Preview` use case for displaying a preview during recording. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/video/VideoCapture<@https://developer.android.com/reference/androidx/annotation/NonNull ?>` | `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#getVideoCapture()()` The `https://developer.android.com/reference/androidx/camera/video/VideoCapture` use case for video recording. |
| `final boolean` | `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#isSlowMotionEnabled()()` Whether to apply slow-motion effects to the recorded video. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/video/HighSpeedVideoSessionConfig#toString()()` |

### Inherited methods

From [androidx.camera.core.SessionConfig](https://developer.android.com/reference/androidx/camera/core/SessionConfig) `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraEffect>` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#getEffects()()`

The list of `https://developer.android.com/reference/androidx/camera/core/CameraEffect` to be applied on the camera session.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/featuregroup/GroupableFeature>>` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#getFeatureSelectionListener()()`

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

Gets the executor set to this session config for feature selection listener invocation.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/util/Range.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html>` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#getFrameRateRange()()`

The desired frame rate range for the camera session.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/featuregroup/GroupableFeature>` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#getPreferredFeatureGroup()()`

A list of preferred `https://developer.android.com/reference/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.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/featuregroup/GroupableFeature>` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#getRequiredFeatureGroup()()`

A set of `https://developer.android.com/reference/androidx/camera/core/featuregroup/GroupableFeature` that are mandatory for the camera session configuration.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/UseCase>` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#getUseCases()()`

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

The `https://developer.android.com/reference/androidx/camera/core/ViewPort` to be applied on the camera session.
`final boolean` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#isAutoRotationEnabled()()`

Whether to use auto rotation.
`final void` `https://developer.android.com/reference/androidx/camera/core/SessionConfig#setFeatureSelectionListener(java.util.concurrent.Executor,androidx.core.util.Consumer)(

@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor,

@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/core/util/Consumer<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/featuregroup/GroupableFeature>> listener

)`

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/androidx/camera/core/SessionConfig#preferredFeatureGroup()` and device capabilities.

## Public constructors

### HighSpeedVideoSessionConfig

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

```
public HighSpeedVideoSessionConfig(
    @NonNull VideoCapture<@NonNull ?> videoCapture,
    Preview preview,
    @NonNull Range<@NonNull Integer> frameRateRange,
    boolean isSlowMotionEnabled
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/video/VideoCapture<@https://developer.android.com/reference/androidx/annotation/NonNull ?> videoCapture` | The `https://developer.android.com/reference/androidx/camera/video/VideoCapture` use case for video recording. |
| `https://developer.android.com/reference/androidx/camera/core/Preview preview` | Optional `https://developer.android.com/reference/androidx/camera/core/Preview` use case for displaying a preview during recording. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/util/Range.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> frameRateRange` | 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/androidx/camera/core/CameraInfo#getSupportedFrameRateRanges()` with a specific `https://developer.android.com/reference/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. |
| `boolean isSlowMotionEnabled` | Whether to apply slow-motion effects to the recorded video. |

## Public methods

### getPreview

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

```
public final Preview getPreview()
```

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

### getVideoCapture

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

```
public final @NonNull VideoCapture<@NonNull ?> getVideoCapture()
```

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

### isSlowMotionEnabled

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

```
public final boolean isSlowMotionEnabled()
```

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

### toString

```
public @NonNull String toString()
```