Open In App

How to Capture HDR Videos in Android 13?

Improve
Improve
Like Article
Like
Save
Share
Report

You can preview and capture HDR video material with your camera thanks to the Camera2 APIs’ support for high dynamic range (HDR) video capture. The video which is taken in HDR is way ahead of the Standard Video that your current app is currently rendering, and is a must to use if the user’s device supports it! High Dynamic Range (HDR) gives a broader variety of colors and expands the luminance component’s dynamic range. This produces video quality with richer colors, brighter highlights, and darker shadows that more closely resemble real life.

Device Requirements

HDR video capture is not supported by all Android devices. Check to see if your device satisfies the requirements listed below before recording HDR video in your app:

  1. Uses Android 13, as already mentioned in this article’s title.
  2. Has a camera sensor capable of 10-bit or greater. 

When configuring HDR video capture in your app, you should include a different code route because not all devices will match the requirements. This enables your app to fall back to SDR on devices that aren’t compatible. Think about including an SDR UI option as well. The user can then switch between SDR and HDR depending on their demands for video recording.

Diagram #1: Understanding the architecture behind HDR.

Diagram #1: Understanding the architecture behind HDR.

Format HDR

In order to capture and display HDR content, camera devices must support HLG10 starting with Android 13 and have 10-bit output capabilities. Additionally, device manufacturers are free to use the HDR capture architecture to enable any HDR format of their choice. The available HDR formats and their HDR video capture capabilities are listed in the table below.

Format

Metadata

Codec

Bitrate

HDR10  Static HEVC 10
HLG10 No HEVC 10
HDR10 + Dynamic HEVC 10
Dolby Vision 8.4  Dynamic HEVC 10

The Camera2 framework allows a buffer to store the camera sensor output when a camera device takes an HDR photo. Additionally, if the HDR profile requires it, it attaches the relevant HDR metadata. As depicted in the diagram, the Camera2 framework then queues the filled buffer for the output surface specified in the CaptureRequest, such as a display or video encoder.

Verifying HDR Support

Check to see if the device supports the HDR profile you want before you start recording HDR video for your app. To find out your device’s HDR capability, use the CameraManager getCameraCharacteristics() method to get a CameraCharacteristics object. The subsequent actions determine if a device supports HLG10. Device manufacturers must support the HDR baseline standard HLG10 on cameras with 10-bit output.

Step by Step Implementation

Step #1: Determine whether the device supports 10-bit profiles (the HDR10+ bit-depth)

Kotlin




private fun isTenBitProfileSupported(gfgCameraId: String): Boolean {
  val gfgCameraCharacteristics = gfgCameraManager.getGfgCameraCharacteristics(gfgCameraId)
  val availableCapabilities = gfgCameraCharacteristics.get(GfgCameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)
  for (capability in availableCapabilities!!) {
      if (capability == GfgCameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT) {
          return true
      }
  }
  return false
}


Step #2: Next, determine whether HDR10+ (or another supported profile) is supported by the device

Kotlin




@RequiresApi(api = 33)
private fun isHDR10+Supported(gfgCameraId: String): Boolean {
if (isTenBitProfileSupported(gfgCameraId)) {
  Val gfgCameraCharacteristics = gfgCameraManager.getGfgCameraCharacteristics(gfgCameraId)
  val availableProfiles = gfgCameraCharacteristics
  .get(GfgCameraCharacteristics.REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES)!!
  .getSupportedProfiles()
 
  // Checks for the desired profile, in this case HDR10+
  return availableProfiles.contains(DynamicRangeProfiles.HDR10+10)
}
return false;
}


Step #3: Starting the HDR Video Recording

Kotlin




gfgSession.setRepeatingRequest(previewRequest, null, cameraHandler)
gfgSession.setRepeatingRequest(recordRequest,
        object : CameraCaptureGfgSession.CaptureCallback() {
    override fun onCaptureCompleted(gfgSession: CameraCaptureGfgSession,
            request: CaptureRequest, result: TotalCaptureResult) {
        if (currentlyRecording) {
            encoder.frameAvailable()
        }
    }
}, cameraHandler)


Conclusion

Your camera app sends a repeated CaptureRequest to preview the video as soon as it initializes the camera, after which you can pass this to intent and start recording HDR videos on your device, and enjoy the Higher Dynamic Range for the camera.

Make sure your device is HDR-capable before setting up your app to take a raw HDR video stream from the camera. To pass a device-supported HDR profile to the stream’s OutputConfiguration, which is then passed to the CameraCaptureSession upon creation, use setDynamicRangeProfile(). View the supported HDR profiles list.



Last Updated : 06 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads