Skip to content

fix(heif): detect HEIC and AVIF motion photos without libheif - #8

Merged
DichenZhang1 merged 1 commit into
Developmentfrom
fix/heif-motion-photo-detection
Oct 6, 2026
Merged

DichenZhang1 merged 1 commit into
Developmentfrom
fix/heif-motion-photo-detection

Conversation

@DichenZhang1

@DichenZhang1 DichenZhang1 commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Mirrors Google3 cl/990031203 (fixes b/567336720): enables the Java API (MetadataEngine.parseMetadata, parseMetadataFd, isMotionPhoto), Android builds, and C++ ParseMotionPhotoFrom*(..., nullptr) to detect HEIC and AVIF motion photos without requiring libheif.

Root Causes Addressed

  1. JNI parse entry points previously hard-coded FileType::kJpeg; ParseMetadataFromFd now sniffs the ftyp box header via SniffFileType().
  2. MetadataEngine::Parse previously had no container splitter for HEIF, producing an empty MetadataCollection.
  3. C++ ParseMotionPhotoFrom* previously detected HEIF only via MotionPhotoHeifInfoBuilder when out_metadata != nullptr (and only when compiled with libheif, which is disabled on Android).

Changes

  • container_splitter.h / jpeg_container_splitter.cc / heif_container_splitter.cc / metadata_engine.cc:
    • Renames CreateContainerSplitter() in jpeg_container_splitter.cc to CreateJpegContainerSplitter().
    • Adds CreateHeifContainerSplitter() in heif_container_splitter.cc, which reads the ISO BMFF item boxes of the meta box directly (pitm, iinf, iref, iloc, idat) and emits the primary image's XMP item as a standard.xmp block when a valid top-level mpvd box is present.
    • Dispatches CreateJpegContainerSplitter() vs CreateHeifContainerSplitter() in MetadataEngine::Parse().
  • motion_photo_jni.cc: Adds SniffFileType() and uses it in ParseMetadataFromFd and AGTM entry points.
  • heif_container_splitter_test.cc / libmotionphoto_api_test.cc / MetadataEngineTest.java / lib/core/CMakeLists.txt: Adds unit tests for HeifContainerSplitter, ParseMotionPhotoFrom*(..., nullptr), and Java MetadataEngine HEIC detection.

@DichenZhang1
DichenZhang1 force-pushed the fix/heif-motion-photo-detection branch from 20a1015 to f10dbca Compare October 6, 2026 19:29
@DichenZhang1
DichenZhang1 merged commit b09d29d into Development Oct 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant