w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
978 stars 136 forks source link

Consider Blob for access to raw buffers #65

Open sandersdan opened 4 years ago

sandersdan commented 4 years ago

Due to the lack of read-only ArrayBuffers, extra copying may be necessary to make some WebCodecs APIs safe.

Blobs however can be read-only. We should investigate whether supporting Blobs in some APIs would be beneficial.

chcunningham commented 4 years ago

IIUC, this still entails copying. When you construct the blob from an ArrayBuffer, the spec says you copy those bytes. When you get an ArrayBuffer via arrayBuffer(), I think this is again a copy (spec is less clear to me here).

sandersdan commented 4 years ago

There is also the opposite case, where we decode a VideoFrame and then want to expose the contents. We can do so as a Blob without copying.

There is a proposal to be able to mmap Blobs in WASM, if that lands it could be very helpful.

padenot commented 3 years ago

https://github.com/Jack-Works/proposal-readonly-arraybuffer https://github.com/Jack-Works/proposal-arraybuffer-fixed-view

are two recent proposals in ES that would be helpful for this.

chcunningham commented 3 years ago

triage note: marking 'extension' as proposals above involve new methods/attributes without breaking.

surma commented 3 years ago

Related: It would be really nice from a developer experience standpoint if these APIs also consumed File and Blob, as that’s what you get from an <input type="file"> element.

Workaround for now is to do

const decoder = new ImageDecoder({
  type: file.type,
  data: new Response(file).body
});