Skip to content

Can example7 not encode images taken by the iphone8? #45

Open
@jassonjackson

Description

@jassonjackson

Can example7 not encode images taken by the iPhone8?

Activity

nokiatech

nokiatech commented on Mar 16, 2018

@nokiatech
Owner

Example7 is not really meant to read iPhone8 images as they are organized bit differently than conformance file the example uses. But Reader can definitely parse iPhone8 images so with some additions to the example7 code you can also duplicate them on writing output.

Typical iPhone8 heic file actually consist of 50 images. They form "grid" image item, which is shown to user when watching photo on phone. This is probably done because single still image is too big for phone HEVC encoder to handle so original image is split into smaller tiles that are encoded and form the grid image.

  • 48 master images that are hidden and have linked derived image (iPhone case this it "grid" item). So they have following ImageInformation.features:
    • ImageFeatureEnum::IsMasterImage
    • ImageFeatureEnum::IsHiddenImage
    • ImageFeatureEnum::HasLinkedDerivedImage
  • 1 derived image, which is also primary/cover image and which has linked external metadata and thumbnail. So it has following ImageInformation.features:
    • ImageFeatureEnum::IsMasterImage
    • ImageFeatureEnum::IsPrimaryImage
    • ImageFeatureEnum::IsDerivedImage
    • ImageFeatureEnum::IsCoverImage
    • ImageFeatureEnum::HasLinkedThumbnails
    • ImageFeatureEnum::HasLinkedMetadata
  • 1 thumbnail image with ImageFeatureEnum::IsThumbnailImage

File also has 2 items in FileInformation.rootMetaBoxInformation.itemInformations:

  • Item for derived image "grid" definition. With matching itemID to derived image above.
  • Item for external "Exif" metadata with ItemFeatureEnum::IsMetadataItem and ::IsExifItem.

You can process the items like this:

// get information about all input file content
FileInformation fileInfo{};
reader->getFileInformation(fileInfo);

// go through all items in input file
for (const auto& item : fileInfo.rootMetaBoxInformation.itemInformations)
{
    FourCC itemType{};
    reader->getItemType(item.itemId, itemType);
    if (itemType == "grid")
    {
        Grid gridItem{};
        reader->getItem(item.itemId, gridItem);

        for (const auto& gridMember : gridItem.imageIds)
        {
            // grid members are the hidden coded images
        }
    }
    else if (itemType == "exif")
    {
        // can be processed like in example 8
    }
}

...

for (const auto& image : fileInfo.rootMetaBoxInformation.imageInformations)
{
    // you can process the image information through here (like which one is the primary image and its thumbnail, etc
}
jassonjackson

jassonjackson commented on Mar 19, 2018

@jassonjackson
Author

Thank you!Another question,How to feed 'data' to decoder and display the cover image in exampe1?

nokiatech

nokiatech commented on Mar 19, 2018

@nokiatech
Owner

You can use your platform HEVC/H.265 codecs to decode/encode images. HEIF library itself doesn't contain codecs.

In decoding case you typically create decoder instance, configure it with information from Reader::getDecoderParameterSets() and then give it actual image bitstream you get from Reader::getItemData() to decode the image.

myrao

myrao commented on Nov 17, 2020

@myrao

@nokiatech
Thanks for wrote the great open source lib, I want decode a grid image, but wan't to get lossless source image, becasue MediaCodec decodes all source images will cost too much time, actually I just wanna get a middle size file for Previewer in Android Devices.
When I'm using this file:

  • Image Resolution: 5792x4344px
  • Image Size: 3.41MB
  • Source Image Count: 109

The Mediacodec decode one image will cost about 50ms, totally 5.5s, how can I solve this problem?
Thanks so much! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @myrao@nokiatech@jassonjackson

        Issue actions

          Can example7 not encode images taken by the iphone8? · Issue #45 · nokiatech/heif