[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# HEIF imaging\n\nDevices running Android 10 support the HEIC\ncompressed image format, a high\nefficiency video encoding (HEVC) specific *brand* of the high efficiency image\nfile format (HEIF) as specified in\n[ISO/IEC 23008-12](https://www.iso.org/standard/66067.html).\nHEIC-encoded images offer\nbetter image quality with smaller file sizes as compared to JPEG files.\n\nHEIC images are generated by the camera framework requesting an uncompressed\nimage from the\n[camera HAL](/docs/core/camera/camera3) and sending it to the media subsystem to\nbe encoded by an HEIC or HEVC encoder.\n\nRequirements\n------------\n\nTo support the HEIC image format, your device must have a hardware encoder\nsupporting\n[`MIMETYPE_IMAGE_ANDROID_HEIC`](https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_IMAGE_ANDROID_HEIC)\nor\n[`MIMETYPE_VIDEO_HEVC`](https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_HEVC)\nwith the\n[constant quality mode](https://developer.android.com/reference/android/media/MediaCodecInfo.EncoderCapabilities.html#BITRATE_MODE_CQ).\n\nImplementation\n--------------\n\nTo support the HEIC image format on your device, implement an HEIC/HEVC codec\nand provide support for the required stream configurations, which are the\n`IMPLEMENTATION_DEFINED`/`YUV` streams and JPEG app segment streams.\n\n### Media\n\nImplement the HEIC/HEVC codec in constant quality (CQ) mode for the\ncorresponding hardware as follows:\n\n- The HEVC type codec consumes either the `IMPLEMENTATION_DEFINED` format with the `GRALLOC_USAGE_HW_VIDEO_ENCODER` usage or the `HAL_PIXEL_FORMAT_YCBCR_420_888` format depending on the image size.\n- The HEIC type codec consumes the `IMPLEMENTATION_DEFINED` format with the `GRALLOC_USAGE_HW_IMAGE_ENCODER` usage.\n\n### Camera\n\nIn the static metadata, set `ANDROID_HEIC_INFO_SUPPORTED` to true, and\n`ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT` to a value between `[1, 16]`,\nindicating the number of JPEG app segments.\n\nFor each mandatory stream combination, your camera device must support swapping\na JPEG stream with a HEIC stream of the same size.\n\nFor an HEIC output stream at the public API, the camera service creates two HAL\ninternal streams:\n\n- A BLOB stream with the `JPEG_APPS_SEGMENT` usage flag to store app segments including EXIF and thumbnail segments\n- An `IMPLEMENTATION_DEFINED` or `YCBCR_420_888` stream the size of the HEIC stream depending on the target codec and HEIC stream size\n\nBased on `ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT`, the camera framework\nallocates buffers large enough for the camera HAL to populate the JPEG app\nsegments. The `APP1` segment is required but segments following the `APP1`\nsegment (`APP2` and above) are optional. The camera framework overrides the EXIF\ntags in the `APP1` segment that can be derived from the capture result metadata\nor are related to the main image bitstream and sends them to `MediaMuxer`.\n\nBecause the media encoder embeds the orientation in the metadata of output\nimages, to ensure a consistent orientation between the main image and thumbnail,\nthe camera HAL must not rotate the thumbnail image based on\n`android.jpeg.orientation.` The framework writes the orientation into the EXIF\nmetadata and HEIC container.\n\nThe static, control, and dynamic metadata tags related to the JPEG format also\napply to the HEIC format. For example, the `android.jpeg.orientation` and\n`android.jpeg.quality` metadata tags in the capture request are used to control\nthe orientation and quality of HEIC images.\n| **Note:** JPEG and HEIC streams can't be configured at the same time.\n\nTo use the HEIC format in an app, use the\n[HEIC public API](https://developer.android.com/reference/android/graphics/ImageFormat#HEIC).\n\nFor more information, see the following sources.\n\n**Camera HAL**\n\n- [`docs.html`](https://android.googlesource.com/platform/system/media/+/a44fd450eae51e671b1020d4f2fb146b181bc1f7/camera/docs/docs.html#31733)\n- [`CameraBlob`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/camera/device/3.5/types.hal#156)\n- [`ANDROID_HEIC_INFO_SUPPORTED`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/camera/metadata/3.4/types.hal#166)\n- [`ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/camera/metadata/3.4/types.hal#172)\n\n**Graphic buffer data space**\n\n- [`JPEG_APP_SEGMENTS`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/graphics/common/1.2/types.hal#66)\n- [`HEIF`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/graphics/common/1.2/types.hal#77)\n\n**Graphic buffer usage space**\n\n- [`HW_IMAGE_ENCODER`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/graphics/common/1.2/types.hal#105)\n\nValidation\n----------\n\nTo validate that your implementation supports HEIC images, use the\n[`TestingCamera2`](https://android.googlesource.com/platform/pdk/+/refs/heads/android16-release/apps/TestingCamera2/)\ntest app and run the following camera CTS and VTS tests.\n\n**Camera CTS tests**\n\n- [`NativeImageReaderTest#testHeic`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/NativeImageReaderTest.java#46)\n- [`ImageReaderTest#testHeic`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ImageReaderTest.java#207)\n- [`ImageReaderTest#testRepeatingHeic`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ImageReaderTest.java#257)\n- [`ReprocessCaptureTest#testBasicYuvToHeicReprocessing`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ReprocessCaptureTest.java#122)\n- [`ReprocessCaptureTest#testBasicOpaqueToHeicReprocessing`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ReprocessCaptureTest.java#170)\n- [`RobustnessTest#testMandatoryOutputCombinations`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java#230)\n- [`StillCaptureTest#testHeicExif`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/StillCaptureTest.java#116)\n\n**Camera VTS tests**\n\n- [`VtsHalCameraProviderV2_4TargetTest.cpp`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp#2357)"]]