Video Capture with Jetpack Camera App

Jetpack Camera App 📸

Jetpack Camera App (JCA) is a camera app, focused on features used by app developers, and built entirely with CameraX, Kotlin and Jetpack Compose. It follows Android design and development best practices and it's intended to be a useful reference for developers and OEMs looking to validate their camera feature implementations.

Development Environment ⚒️

This project uses the gradle build system, and can be imported directly into Android Studio.

Currently, Jetpack Camera App is built using the Android Gradle Plugin 8.4, which is only compatible with Android Studio Jellyfish or newer.

Architecture 📐

JCA is built with modern android development (MAD) principles in mind, including architecture and testing best practices.

The app is split into multiple modules, with a clear separation between the UI and data layers.

Testing 🧪

Thorough testing is a key directive of JCA. We use Compose Test and UI Automator to write instrumentation tests that run on-device.

These tests can be run on a connected device via Android Studio, or can be tested on an Android Emulator using built-in Gradle Managed Device tasks. Currently, we include Pixel 2 (API 28) and Pixel 8 (API 34) emulators which can be used to run instrumentation tests with:

$ ./gradlew pixel2Api28StableDebugAndroidTest and $ ./gradlew pixel8Api34StableDebugAndroidTest

Features ✨🧰✨

This section provides a detailed overview of the camera app's features, highlighting its capabilities and functionalities. Each feature is described with its purpose, usage, and any relevant considerations to help you understand and utilize the app effectively.

Standard Camera Features

This section outlines the essential features of the camera app that enable you to capture photos and videos with ease. It covers fundamental aspects of camera operation, providing a solid starting point for utilizing the app's capabilities.

Viewfinder

The viewfinder provides a real-time preview of the camera's sensor output, accurately displaying the scene with correct scaling and orientation. It functions as a "What You See Is What You Get" ( WYSIWYG) display, showing only the pixels that will be captured in the final image or video, when hardware and processing capabilities allow (see limitations). This ensures that the displayed preview precisely reflects the captured content, allowing for accurate composition and framing.

How to Enable / Use

Constraints / Limitations

Aspect Ratio

Sets the proportions of the preview and the captured image or video.

How to Enable / Use

  1. Open the camera app settings and select Set Aspect Ratio
  2. Or open the quick dropdown in the preview screen and look for the aspect ratio icon
  3. Select/toggle among the desired aspect ratios (e.g., 16:9, 4:3, 1:1).

Image Capture

Captures a still image from the camera. When the capture button is pressed, the camera captures a still image that accurately represents the scene currently displayed in the viewfinder. The captured image will incorporate any applicable image processing settings, such as Ultra HDR, based on the user's selected mode.

How to Enable / Use

  1. Open the camera app.
  2. Tap the shutter button (white circle).
  3. The resulting image is saved to the device's media store, or, when the app is launched via the ACTION_IMAGE_CAPTURE or INTENT_ACTION_STILL_IMAGE_CAMERA intents, to the URI(s) provided.

Constraints / Limitations

Tap to Focus

Allows the user to manually select the focus point of the camera.

How to Enable / Use

  1. Open the camera app.
  2. Tap on the desired area of the viewfinder.
  3. The camera will adjust the focus to the tapped area.

Constraints / Limitations

Flip Camera

This feature allows users to instantly switch between the device's primary front-facing and rear-facing cameras.

How to Enable / Use

There are several ways to flip camera lenses:

  1. Open the camera app.
  2. Tap the flip camera button.

Alternatively,

  1. Open the camera app.
  2. Double tap on the viewfinder.

Alternatively,

  1. Open the camera app.
  2. Open quick settings by tapping the downward facing arrow at the top of the screen.
  3. Tap the flip camera button which is displaying the currently visible camera.

Constraints / Limitations

Zoom

This feature enables users to digitally or optically zoom in and out on the scene. On devices equipped with Camera2's LOGICAL_MULTI_CAMERA capability, the zoom functionality may automatically transition between available lenses, such as the main, telephoto, and wide-angle lenses, to provide seamless zoom transitions across the device's optical range.

How to Enable / Use

  1. Open the camera app.
  2. Use pinch-to-zoom gestures. Text indicating the current magnification factor will appear above the capture button. If the device supports the LOGICAL_MULTI_CAMERA capability, switching between lenses will occur automatically as zoom increases or decreases.

Constraints / Limitations

Scene Illumination / Flash

This feature provides various options for illuminating the scene during capture of images and video, including:

How to Enable / Use

  1. Open the camera app.
  2. Tap the flash icon to toggle between scene illumination modes (on, off, auto, LLB).
  3. Take a photo or video.

Alternatively,

  1. Open the camera app.
  2. Open quick settings by tapping the downward facing arrow at the top of the screen.
  3. Tap the flash icon to toggle between scene illumination modes.
  4. Take a photo or video.

Constraints / Limitations

Video Features

This section explores the camera app's comprehensive video recording capabilities, providing tools and settings to enhance your video capture experience. It covers various aspects of video functionality, from basic recording to advanced controls and customization.

Video Capture

Records video that, in most cases (see limitations), represents the scene visible in the viewfinder. When HDR mode is enabled, the captured video can record 10-bit HDR content.

How to Enable / Use

  1. Open the camera app.
  2. Press and hold the shutter button (white circle) until video recording starts, indicated by a filled red circle in the shutter button and an incrementing duration timer above the shutter button.
  3. Release the shutter button to finish recording. The resulting video is saved to the device's media store, or, when the app is launched via the ACTION_VIDEO_CAPTURE intent, to the URI provided.

Constraints / Limitations

Pause / Resume

Temporarily stops and restarts video recording.

How to Enable / Use

  1. While recording video, tap the pause button.
  2. Tap the resume button to continue recording.

Constraints / Limitations

Video Duration Limit

Sets a maximum length for video recordings.

How to Enable / Use

  1. Open the camera app settings.
  2. Select Set Maximum Video Duration
  3. Choose the desired duration limit.

Video Quality

Sets the resolution and compression level of video recordings.

How to Enable / Use

  1. Open the camera app settings.
  2. Select Set Video Quality.
  3. Choose the desired video quality (e.g., 720p, 1080p, 4K).

Constraints / Limitations

Audio / Amplitude Visualization

Controls the audio recording level and processing.

How to Enable / Use

  1. Start video recording by holding down the capture button
  2. Audio visualization appears to the right of the button while recording

Frame Rate

Sets the number of frames recorded per second in a video.

How to Enable / Use

  1. Open the camera app settings.
  2. Select Set Frame Rate
  3. Select the desired frame rate (e.g., 30fps, 60fps).

Constraints / Limitations

Video Stabilization

This feature offers multiple stabilization modes to enhance video smoothness and clarity. The following stabilization modes are offered as options by JCA

How to Enable / Use

  1. Open the camera app settings from the settings icon in the upper left corner.
  2. Click the “Set Video Stabilization” setting if it is selectable. If it is not selectable, the current lens does not support any video stabilization.
  3. Choose the desired stabilization mode and press “close”. The stabilization mode will be applied when returning to the camera viewfinder. This selected stabilization mode will be persisted if the app is closed, and will be applied the next time the app is opened.

Constraints / Limitations

Flip Camera While Recording

Switches between front and rear cameras during video recording.

How to Enable / Use

  1. While recording video, tap the flip camera button.

Constraints / Limitations

Advanced Camera Features

This section delves into the advanced capabilities of the camera app, unlocking a new level of control and creativity for experienced users. It explores features that extend beyond basic camera operation, offering specialized functionalities and enhanced capture modes.

Screen Flash

During image capture with a front-facing camera, this feature illuminates the subject by displaying a solid, bright overlay on the device's screen and maximizing screen brightness.

How to Enable / Use

  1. Open the camera app.
  2. Ensure a front-facing camera is selected by tapping on the “flip camera” button.
  3. Tap the flash icon to toggle between scene illumination mode. Screen flash will be selected if the “On” or “Auto” flash mode is selected.
  4. Take a photo.

See the “Scene Illumination / Flash” feature for other methods of enabling screen flash.

Constraints / Limitations

Dual Concurrent Camera

This feature enables simultaneous video capture from both the front and rear-facing cameras. It is built upon the CameraX concurrent camera APIs and is only available on devices that support the PackageManager.FEATURE_CAMERA_CONCURRENT feature. The interface displays two video streams: a " primary" stream and a "secondary" stream. The primary stream occupies the majority of the viewfinder, providing the main view, while the secondary stream is presented in a picture-in-picture format. The "Flip Camera" feature will swap the roles of the primary and secondary camera streams, effectively switching which camera provides the main view.

How to Enable / Use

  1. Open the camera app.
  2. Open quick settings by tapping the downward facing arrow at the top of the screen.
  3. Tap the concurrent camera mode button to select the concurrent camera mode. It will display “DUAL” underneath the button when Dual Concurrent Camera mode is enabled, and “SINGLE” for normal single-camera operation.
  4. Both streams will be visible in the viewfinder. You may optionally record a video of what is visible in the viewfinder. Both streams will be composited in the recorded video.

Constraints / Limitations

HDR (High Dynamic Range)

This multifaceted feature enhances the camera's ability to capture and display a wider range of colors and brightness levels. It comprises three key components:

How to Enable / Use

  1. Open the camera app.
  2. Open quick settings by tapping the downward facing arrow at the top of the screen.
  3. Tap the “HDR” button to select HDR mode, if it is enabled. Tapping again will toggle back to SDR mode.
  4. Exit quick settings by tapping the upward facing arrow at the top of the screen.
  5. Toggle between 10-bit HDR video mode and Ultra HDR image capture mode using the toggle switch in the lower right corner. If only one of these modes is available on the device, this switch will be disabled, and tapping it will display a reason for why it is disabled.
  6. Take a photo or video as normal, depending on which mode is selected.

Constraints / Limitations

LLB (Low Light Boost)

Enhances the brightness of the camera's preview and recorded videos. If the device supports it, this feature utilizes Camera2's ON_LOW_LIGHT_BOOST_BRIGHTNESS_PRIORITY auto-exposure (AE) mode to improve brightness in low-light conditions.

How to Enable / Use

  1. Tap the flash icon to cycle through flash modes.
  2. The crescent moon icon indicates that LLB is enabled.
  3. LLB has two states:
    1. Outlined Crescent Moon: LLB is inactive (the scene isn't dark enough).
    2. Filled Crescent Moon: LLB is active (the scene is dark enough, and brightness is enhanced).
  4. To disable LLB, switch to a different flash mode.

Constraints / Limitations

Single / Multi-stream Mode

This setting controls whether the camera uses a single stream or multiple streams for preview, video, and image capture.

How to Enable / Use

  1. Open quick settings by tapping the downward facing arrow at the top of the screen.
  2. Tap the single or multi stream button. This will toggle between single stream or multi stream modes.

Constraints / Limitations

Special Application Features

This section explores features that provide extended functionality and customization within the camera app, going beyond core image and video capture capabilities. These features cater to specific user preferences and developer needs.

Debug Mode

Provides advanced camera information and controls for developers.

How to Enable / Use

  1. Launch the app with extra KEY_DEBUG_MODE set to true
  2. Access the debug mode UI through the purple “Debug” button in the preview screen

Constraints / Limitations

Intent Capture Modes

Launch the app into modes with specialized user flow. Also allows configuring content values for media to be captured

How to Enable / Use

  1. In the launching intent for JCA, set intent action to ACTION_IMAGE_CAPTURE, ACTION_VIDEO_CAPTURE, or INTENT_ACTION_STILL_IMAGE_CAMERA for single image capture, single video capture, or multiple image capture mode.
  2. Configure content values and insert the url into the intent at MediaStore.EXTRA_OUTPUT
  3. Launch JCA

Dark Mode

This feature allows users to customize the app's appearance by selecting between three modes:

The appearance of UI elements will differ depending on the selected mode. This setting only affects the user interface and does not impact the captured images or videos.

How to Enable / Use

  1. Open the camera app settings from the settings icon in the upper left corner.
  2. Tap the “Set Dark Mode” setting under “App Settings”.
  3. Select the desired mode.

Source Code Headers

Every file containing source code must include copyright and license information. This includes any JS/CSS files that you might be serving out to browsers. (This is to help well-intentioned people avoid accidental copying that doesn't comply with the license.)

Apache header:

Copyright (C) 2024 The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.