Notes About Android Camera APIs

Photography features

  • Fill light has no API
  • There’s no API for semi-automatic exposure, where you specify exposure duration and the OS takes care of ISO or vice-versa. You have to specify both or none.
  • Dual cameras: Different vendors provide dual cameras for their Android devices to improve the photo quality for the average user, more often than not, specifically tuned for special conditions like challenging illumination or distortions of selfie mode. Each vendor uses proprietary technologies to handle dual cameras, and they don’t disclose implementation details. The only public interface they support is a virtual single camera which is more or less compliant with Google specs.
  • Android cameras have different hardware levels. A hardware level defines a minimum set of camera support. The least level is LEGACY, and all phones support at least LEGACY. This gives you a baseline of what you can expect.

Video recording

Android has two APIs to record a video:

MediaRecorder

This receives input from the camera.

MediaRecorder has built-in support for timelapse recording. You specify a capture rate in MediaRecorder, like 0.1 to mean a frame every 10 seconds. This makes the capture rate different from playback rate, thus producing a timelapse video.

You can specify different quality levels, with QUALITY_TIME_LAPSE_HIGH representing the highest supported quality. You can also set a custom width and height by getting a CamcorderProfile and then assigning to its width.

MediaCodec

This is a lower-level API where you give it frames to write to a video file.

Image Capture

There are different ImageFormats to choose from. Different phones support different formats. Of those, the following are guaranteed to be supported everywhere:

There are formats that don’t have chroma subsampling, like RGB and 4:4:4, but these are not supported either on the Pixel 1 or on the Redmi Note 4.

Video Codec Capabilities

Android guarantees support for H264 (in an mp4 container) encoding and decoding.

All video codecs support COLOR_FormatYUV420Flexible on Android 7+.

There are two ways to get information: CamcorderProfile and MediaCodecInfo. The following tells you the capabilities of the camera: what resolution, frame rate, etc, it can record in. The latter tells you the capabilities of the video encoder. This would apply if, for example, you programmatically generate a video rather than recording it using the camera. I expect the latter to be higher since, if a device can’t encode a UHD video, it can’t encode one when the data is coming from the camera. Also, a device may support UHD for decoding and not encoding.

The MediaCodecInfo tells you what width, height, frame rate and bitrate are supported. It gives you two kinds of information:

Supported

… means that it works, though performance may not be good enough — the video may stutter while playing.

You can find out which width, height, frame rate and bit rate are supported.

You can also find out combinations like which heights are supported for a given width.

Achievable

… means that there’s at least some guarantee of performance.

But this API is broken, reporting that the P30 Pro supports only 9FPS at UHD, and 10FPS on the Redmi Note 4.

The only information provided in this category is what frame rate is achievable for a given width and height. The API gives you a range of frame rates, like 30–60 FPS. We should take the lower value, and halve it, and use that number, 15 in this case, because the system is guaranteed to meet that level of sustained performance 90% of the time. If you don’t halve it, and use 30FPS, the system will fall below that level half the time, making for a stuttering video playback.

You can also find out whether a codec is hardware-accelerated.

The min SDK version should be at least 24, because we can’t get reliable information on whether the device can play back a video encoded at a certain frame rate.

--

--

Tech advisor to CXOs. I contributed to a multi-million dollar outcome for a client. ex-Google, ex-founder, ex-CTO.