Skip to content

fix(utils): detect AVIF and HEIC bytes as images - #300

Open
Manishram-ai wants to merge 1 commit into
apple:mainfrom
Manishram-ai:fix/media-avif-heic-images
Open

Manishram-ai wants to merge 1 commit into
apple:mainfrom
Manishram-ai:fix/media-avif-heic-images

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Follow-up to #257, which fixed this on the backend. AVIF and HEIC use the same ftyp container as M4A, but detectImageMimeType doesn't recognize them, so detectAudioMimeType reports audio/mp4 and the viewer's valueKind shows an audio player for these images. Base64 strings hit the same problem through detectBase64MimeType.

This reads the major and compatible ftyp brands in detectImageMimeType, with the same brand lists the backend's _detect_mime_type uses. MP4 and M4A brands still fall through to audio.

HEIC will only display where the browser can decode it. WebKit displayed my HEIC test files, and Chromium showed a broken image in place of the audio player.

Testing:

  • New tests in packages/utils/test/media.test.js and packages/viewer/test/renderer_utils.test.ts fail on main and pass with the fix. All 128 utils tests and 145 viewer tests pass.
  • AVIF and HEIC files from ImageMagick, sips and heif-enc come back as images as raw bytes, {bytes, path} objects and base64 strings. M4A, MP4 and MOV files from ffmpeg still come back as audio.
  • The AVIF files display in Chromium and WebKit.
  • tsc --build and Prettier are clean.

This branch has not been deployed

No deployments
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