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

The closest have been able to get to 160x160 is 176x144 using any combination of constraints. 

To create a 160x160 `MediaStreamTrack` from original `MediaStreamTrack`, this can be done at Chromium, not at Firefox or Nightly, where `resizeHeight` and `resizeWidth` are not defined at `createImageBitmap()` and `ImageCapture` is not supported, and `OffscreenCanvas` is behind a flag and has implementation issues. Nonethess a workaround is till possible for Mozilla browsers


```
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');
  const ctx = canvas.getContext('bitmaprenderer');
  const canvasStream = canvas.captureStream();
  const [canvasTrack] = canvasStream.getVideoTracks();
  video.srcObject = canvasStream;
  const imageCapture = new ImageCapture(track);
  console.log('before constraints:', track.getSettings(), await track.getConstraints());
  let controller;
  const rs = new ReadableStream({
    start(_) {return controller = _},
    async pull() {
      const frame = await imageCapture.grabFrame();
      const bitmap = await createImageBitmap(frame, 0, 0, width, height, 
                                 {resizeWidth: 160, resizeHeight: 160}
                               );
      controller.enqueue(bitmap);
      // adjust frame rate manually or dynamically here, e.g.,
      // await new Promise(resolve => setTimeout(resolve, 1000/30));
    }
  })
  .pipeTo(new WritableStream({
    write(bitmap, c) {
      ctx.transferFromImageBitmap(bitmap);
    }
  }));
  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);
});
```

-- 
GitHub Notification of comment by guest271314
Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/723#issuecomment-698581716 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 20:50:57 UTC