Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jassonjackson opened this issue Mar 16, 2018 · 4 comments
Open

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

jassonjackson opened this issue Mar 16, 2018 · 4 comments

Comments

@jassonjackson
Copy link

Can example7 not encode images taken by the iPhone8?

@nokiatech
Copy link
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
Copy link
Author

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

@nokiatech
Copy link
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
Copy link

myrao commented Nov 17, 2020

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants