Search code examples
androidandroid-cameraandroid-camera2

Camera2 YUV formats efficiency and differences


I noticed that in Camera2 the StreamConfigurationMap.getOutputFormats() function returns different YUV formats depending on the phone's hardware.

For example, my Samsung S21 returns ImageFormat.YUV_420_888, as well as ImageFormat.NV21.

I was wondering if there are any differences in efficiency, compatibility or feature parity here? E.g. does NV21 support 60 FPS streaming whereas YUV_420_888 doesn't? Or is this purely just data layout for consuming it later?


Solution

  • All camera2 devices have to support ImageFormat.YUV_420_888, so that's the safest format to target.

    It's a flexible format, and can describe NV21 or YV21 (or NV12 or YV12, etc) layouts.

    Some devices want to also declare specific formats like NV21; it's very possible YUV_420_888 on that device is also the exact same layout, but if you pick NV21 then you don't have to query the row and pixel strides.

    The camera2 API doesn't allow specifying different available features based on the output format, for the most part. The general exception is RAW output, since it's directly from the sensor and not processed, obviously features like eletronic image stabilization or noise reduction have no impact on RAW data. But different YUV formats should all have the same feature set available.

    It's possible some YUV formats have lower performance overhead than others, if supporting format X requires an internal conversion from ISP's preferred internal format Y. But there's no real way to query for that today.