Skip to content
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

Transformer does not work with supported image MimeTypes when the type comes from ContentResolver #1373

Closed
kleiren opened this issue May 14, 2024 · 1 comment
Assignees

Comments

@kleiren
Copy link

kleiren commented May 14, 2024

When adding an image with a supported mimeType (.heic) as a mediaItem, and generating a video using the transformer, it will return an error with the message "Image format not supported by given bitmapLoader", although it should be supported.

The issue seems to be that in function isImage() from the DefaultAssetLoaderFactory, the mimeType is coming from the contentResolver directly as heic, and then checked with the function isBitmapFactorySupportedMimeType() that only checks for heif instead of heic and heif.

[...]
    if (mimeType == null) {
      if (Objects.equals(localConfiguration.uri.getScheme(), ContentResolver.SCHEME_CONTENT)) {
        ContentResolver cr = context.getContentResolver();
        mimeType = cr.getType(localConfiguration.uri);
      } else {
        mimeType = getCommonImageMimeTypeFromExtension(localConfiguration.uri);
      }
    }
[...]
    checkState(
        bitmapLoader.supportsMimeType(mimeType),
        "Image format not supported by given bitmapLoader");
[...]

If the mimetype does not come from the content resolver, it will be extracted from the file extension and "commonized" using getCommonImageMimeTypeFromExtension()
In this case, if the image is heic, it will return a heif mimetype, and will pass the isBitmapFactorySupportedMimeType() check.
Of course this should happen with many other image types.

My question is, is there any way of skipping this check? I have tried setting the mimetype directly to the mediaItem, but it seems to be ignored for this case. Maybe this is a bug and supportsMimeType() should "commonize" all mimetypes.

Thanks!

@tof-tof
Copy link
Contributor

tof-tof commented May 14, 2024

It seems there is a bug in the fact that the checkState throws in this case. I'll submit a fix for this.

There is a few ways to surpass the check. you can set the mimetype to be image/heif instead of image/heic which passes the supportsMimeType check for the default bitmap loader.

Alternatively, you can pass a BitmapLoader implementation, for which bitmapLoader.supportsMimeType("image/heic") returns true (possibly just by wrapping the default DataSourceBitmapLoader and changing the relevant method) the bitmapLoader can be passed an an argument for the DefaultAssetLoaderFactory, which can then be passed into Transformer

copybara-service bot pushed a commit that referenced this issue May 14, 2024
This treats heic as a separate mimetype to heif (even though heic files are a subset of heif files). This is in line with other platform classes like android.content.ContentResolver

https://developer.android.com/media/platform/supported-formats#image-formats was updated to include avif support or API level 34, so added this MimeType as well and updated our associated util.

solves Issue: #1373

PiperOrigin-RevId: 633616214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants