Re: [mediacapture-main] Mandate implementations to support video frame subsampling (#723)

Firefox version, where `ReadableStream.pipeTo()` is not supported and `requestFrame()` is still defined at `MediaStream` rather than `CanvasCaptureMediaStreamTrack`, to record 160x160 video from source `MediaStreamTrack`, the key parameters being the last two to `drawImage()`, from MDN https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage

> **dWidth** Optional
>     The width to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in width when drawn.
> **dHeight** Optional
>     The height to draw the image in the destination canvas. This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.

```
navigator.mediaDevices.getUserMedia({video: true})
.then(async stream => {
  const video = document.createElement('video');
  document.body.appendChild(video);
  video.autoplay = true;
  const [track] = stream.getVideoTracks();
  const {width, height} = track.getSettings();
  const canvas = document.createElement('canvas');
  canvas.width = canvas.height = 160;
  document.body.appendChild(canvas);
  const ctx = canvas.getContext('2d');
  const canvasStream = canvas.captureStream(0);
  const [canvasTrack] = canvasStream.getVideoTracks();
  video.srcObject = stream;
  let controller;
  const rs = new ReadableStream({
    start(_) {return controller = _},
    async pull() {
      ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, 160, 160);
      canvasStream.requestFrame();
      controller.enqueue(null);
    }
  });
  const reader = rs.getReader();
  reader.read().then(async function processStream({value: bitmap, done}) {
    if (done) return;
    await new Promise(resolve => setTimeout(resolve, 1000/30));
    return reader.read().then(processStream);
  });

  const recorder = new MediaRecorder(canvasStream);
  recorder.ondataavailable = ({data}) => console.log(URL.createObjectURL(data));
  recorder.start();
  setTimeout(async _ => {
    recorder.stop(); 
    controller.close();
    track.enabled = false; 
    canvasTrack.stop();  
  }, 10000);
});
```

If gather the Issue correctly, this is how `applyConstraints()` should work, instead of reporting incorrect values and not throwing error or exception.

-- 
GitHub Notification of comment by guest271314
Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/723#issuecomment-698612993 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 24 September 2020 22:05:08 UTC