w3c / html

Deliverables of the HTML Working Group until October 2018
https://w3c.github.io/html/
Other
1.95k stars 527 forks source link

HTMLVideoElement needs source image width and height properties #1691

Closed juj closed 4 years ago

juj commented 5 years ago

red_in_blue_par.zip

Check out the attached video, which is of source pixel size 400x200. Video files can have a metadata field that specifies a stretch/aspect ratio in them. In this video, the aspect ratio is specified as 1:1 (or, expressed as stretch ratio, 1:2), meaning that to view this video, a video player should stretch the height up 2x, and in this case, produce a video stream of size 400x400.

This has uses in special cases related to letterboxing, and also e.g. in Anamorphic video files.

Browsers seem to handle the video aspect ratio/stretch metadata properly, which is great.

HTMLVideoElement has fields videoWidth and videoHeight. Observing those elements when playing the attached video, they report the post-stretch-applied size of 400x400, and not the source image size 400x200. Examining the different fields, it is currently not possible to receive the original source video stream size from the video.

When implementing a "video in a WebGL texture" use case, developers may need to know the source pixel size, since they need to know the size of the 2D texture they need to create. For example for the video file attached here, developer would need to create a video texture of size 400x200 to accommodate the video.

In simple use cases developer can avoid needing to know the size in JS code by offloading the texture size determination to the unsized gl.texImage2D() call. This works for simple demos, but in more complex use cases, it falls short.

For example if developer would like to upload two or more video subrectangles into the same texture, they will need to know the unscaled dimensions in order to know which part of the source texture to allocate for the video frames. Or if developer would like to gl.readPixels() to snapshot a single frame of such a texture to JS/Wasm side for video processing, they cannot do that since they do not know what size the video texture actually is. Or if one would like to generate mip levels for the texture, they need to know what the size of the texture actually is. Not knowing the video texture size also prevents the use of the more modern gl.storage2D() API, since that requires knowing the size of the target texture to create up front.

One way to solve this issue is that HTMLVideoElement would add unscaled size fields, e.g. rawVideoWidth, rawVideoHeight (or unscaledVideoWidth/unscaledVideoHeight) to HTMLVideoElement, which would report the proper unscaled size. Would this be a possible addition to the spec?

siusin commented 4 years ago

Thanks @juj .

We're closing this issue on the W3C HTML specification because the W3C and WHATWG are now working together on HTML, and all issues are being discussed on the WHATWG repository.

If you filed this issue and you still think it is relevant, please open a new issue on the WHATWG repository and reference this issue (if there is useful information here). Before you open a new issue, please check for existing issues on the WHATWG repository to avoid duplication.

If you have questions about this, please open an issue on the W3C HTML WG repository or send an email to public-html@w3.org.