visibleRect.width overrides VideoFrame codedWidth in VideoFrameBufferInit constructor
jkosir opened this issue · comments
From a VideoDecoder I am given a VideoFrame
with different coded and display heights:
I'm trying to construct a new VideoFrame with a copy of data using the VideoFrameBufferInit
constructor but cannot set codedWidth
correctly, whatever is passed as visibleRect.width
overrides codedWidth
which then of course causes the rendering of such frame to produce a completely invalid image.
More specifically I'm constructing a I420A
frame from I420
by appending opacity data but even just trying to create a copy of source I420
frame fails.
Running const frameDuplicate = new VideoFrame(buffer, init)
results in:
results in frameClone.codedWidth = 640
, while it should be 704
.
If I omit visibleRect in videoFrameBufferInit
then codedWidth
is set correctly, however visibleRect
defaults to codedWidth (and not displayWidth) which again produces garbage when rendering.
Is this somehow expected per spec or is it a bug in Chromium?
Per https://w3c.github.io/webcodecs/#dom-videoframe-videoframe-data-init the UA may adjust coded size as necessary:
The User Agent may choose to allocate resource with a larger coded size and plane strides to improve memory alignment. Increases will be reflected by codedWidth and codedHeight. Additionally, the User Agent may use visibleRect to copy only the visible rectangle. It may also reposition the visible rectangle within resource. The final position will be reflected by visibleRect.
That shouldn't cause any rendering issues though. Is the issue that your alpha channel is trying to use the coded size? Can you describe what's going wrong more?
Oh sorry, I assumed the mismatching codedWidth
was causing the rendering issue but actually I was copying frame data wrong. While a newly created frame from a copied buffer has the different codedWidth
it is in fact rendered correctly. Was missing the { rect: videoFrame.codedRect }
in videoFrame.copyTo()
.