Skip to content

createImageBitmap(videoFrame) Semantics #159

Closed
@chcunningham

Description

@chcunningham

The plan is to make VideoFrame a CanvasImageSource (#158) and then (quickly) deprecate our videoFrame.createImageBitmap() in favor of window.createImageBitmap(videoFrame). This issue explores how window.createImageBitmap(videoFrame) would be spec'ed (in HTML).

Full credit to @sandersdan for the following. I'm just turning his excellent doc into a bug. I support his proposals. @domenic, are you the right html spec reviewer? Thoughts on the proposals below?


Purpose

There are a variety of things that createImageBitmap() for VideoFrame could optionally do, at a performance cost. This document tries to clarify what those are, whether they should be done, and whether there is or should be a configuration parameter.

Background

For a long time, it was assumed that transferToImageBitmap() would be the most efficient way to use VideoFrame, and a lot of focus was put on making ImageBitmap creation efficient (zero-copy). It’s now clear that other APIs (texImage2D(), drawImage(), and WEBGL_webcodecs_video_frame) will offer better performance, so our assumptions should be re-evaluated.

Properties

Lifetime

In some cases we can create an ImageBitmap that references the VideoFrame contents to avoid making a copy. This could require that the ImageBitmap is closed to avoid stalling the decoder, which is atypical for Web APIs.

  • Proposal: use zero-copy only when it cannot cause a decoder stall. Apps can rely on GC for ImageBitmaps, as they typically already do.

Crop

It is unclear whether users only need the visible region or will sometimes want the whole coded region.

  • Proposal: simplify usage and provide only the visible region. Recommend lower-level APIs for coded region access.

Scale

Scaling the frame to its natural size may prevent zero-copy. It’s also unclear whether API users would prefer raw pixels or 1:1 pixels.

  • ImageBitmapOptions has resizeWidth and resizeHeight to control this behavior.
  • ImageBitmaps are specified to be measured in CSS pixels, which implies a 1:1 PAR.
  • VR360 videos may have a PAR that causes the natural width to exceed the maximum WebGL texture size. We can recommend those users to specify a natural size in the VideoDecoderConfig that does not result in scaling.
  • Proposal: simplify usage and scale to the natural size. Recommend lower-level APIs for raw access.

Rotation

Rotating the frame to match the requested orientation may prevent zero-copy. Most API users will prefer that orientation is handled for them, unless they are intentionally trying to pass through the raw stream.

ImageBitmapOptions has imageOrientation, but it is for flipY only.

  • Proposal: simplify usage and always apply image orientation. Recommend lower-level APIs for raw access.

Color Conversion

VideoFrames can be created in a wider variety of color spaces than ImageBitmaps. Converting to an ImageBitmap color space is likely to be lossy, but ImageBitmaps do not carry their own color space information.

  • ImageBitmapOptions has colorSpaceConversion to disable this behavior.
  • Proposal: default to applying color space conversion (to sRGB). Recommend lower-level APIs for raw access.

Metadata

Metadata

Assignees

Labels

extensionInterface changes that extend without breaking.need-definitionAn issues where something needs to be specified normatively

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions