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

Allow WebP and AVIF image streams #3845

Closed
dvoracek-slub opened this issue Jan 11, 2022 · 4 comments · Fixed by #3856 or #4009
Closed

Allow WebP and AVIF image streams #3845

dvoracek-slub opened this issue Jan 11, 2022 · 4 comments · Fixed by #3856 or #4009
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Milestone

Comments

@dvoracek-slub
Copy link

Have you read the FAQ and checked for duplicate open issues?
Yes

Is your feature request related to a problem? Please describe.
To allow better compression in thumbnail / image tracks, I would like to use WebP or AVIF instead of JPEG images (when supported in the browser). Currently, AVIF streams are always dropped, and WebP are kept only on WebOS, Tizen, Chromecast.

Describe the solution you'd like
Instead of white-listing supported image formats per platform, StreamUtils::filterImageStreams_() should check actual browser support.

Describe alternatives you've considered
Alternatively, stream filtering could be made customizable, so that I may check browser support in the app itself.

@dvoracek-slub dvoracek-slub added the type: enhancement New feature or request label Jan 11, 2022
@avelad
Copy link
Collaborator

avelad commented Jan 11, 2022

Do you know an API to verify image support?

One possibility is to use something like this:

function isImageSupported (imageElement) {
  return new Promise((resolve) => {
    if ('decode' in imageElement) {
      imageElement.decode().then(() => {
        resolve(true);
      }).catch(() => {
        resolve(false);
      });
    } else {
      imageElement.onload = imageElement.onerror = () => {
        resolve(imageElement.height === 2);
      };
    }
  });
}

const WebP = new Image();
WebP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
isImageSupported(WebP).then((res) => {
  console.log('WebP support:', res);
});

const AVIF = new Image();
AVIF.src = 'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=';
isImageSupported(AVIF).then((res) => {
  console.log('AVIF support:', res);
});

@dvoracek-slub
Copy link
Author

I don't know a way other than via a sample image, but also I hadn't looked into this extensively yet. At least for WebP, though, this seems to be the recommended approach (https://developers.google.com/speed/webp/faq#in_your_own_javascript).

@shaka-bot shaka-bot added this to the Backlog milestone Jan 11, 2022
@avelad
Copy link
Collaborator

avelad commented Jan 11, 2022

@joeyparrish do you know another method to check if a image mime type is supported?

@joeyparrish
Copy link
Member

No, I don't know a better way. I would suggest this:

  1. Create the smallest sample images possible for each format, to minimize the size of the base64 data URIs
  2. Hard-code the data URIs into a map, indexed by MIME type
  3. Adapt the async code above to check by MIME type using that map (would work like an async version of MediaSource.isTypeSupported)
  4. Have the implementation memoize the results of a MIME type query, so future filtering passes could be done more quickly

joeyparrish pushed a commit that referenced this issue Jan 13, 2022
shaka-bot pushed a commit that referenced this issue Jan 18, 2022
This better reflects the code landed in PR #3856

Issue #3845

Change-Id: I301f1d70c7c52454c22c6d0ee7c9d1461d7e7691
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Mar 14, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2022
@avelad avelad modified the milestones: Backlog, v4.0 May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
4 participants