Bug 250200 - The stream obtained through navigator.mediaDevices.getDisplayMedia has black edges on both sides of the video. And cannot set width and height
Summary: The stream obtained through navigator.mediaDevices.getDisplayMedia has black ...
Status: RESOLVED WORKSFORME
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 16
Hardware: Mac (Apple Silicon) macOS 13
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
: 250199 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-01-06 02:31 PST by mawencan
Modified: 2023-01-13 11:46 PST (History)
3 users (show)

See Also:


Attachments
https://meet.google.com (679.57 KB, image/png)
2023-01-06 02:31 PST, mawencan
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mawencan 2023-01-06 02:31:00 PST
mac m1 air 
```
const shareOptions: DisplayMediaStreamOptions = {
  video: true,
  audio: {
    echoCancellation: true,
    noiseSuppression: true,
    sampleRate: 44100,
  },
};
stream = await navigator.mediaDevices.getDisplayMedia(shareOptions);
video.srcObject = stream;
video.play();
```
There are black edges on both sides of the video. I hope the video content is covered without black edges
--------------------
Or by https://meet.google.com To reproduce
Comment 1 mawencan 2023-01-06 02:31:38 PST
Created attachment 464371 [details]
https://meet.google.com
Comment 2 mawencan 2023-01-06 02:35:43 PST
There will be a bug when sharing the screen, but the shared window is normal
Comment 3 Alexey Proskuryakov 2023-01-07 11:20:04 PST
*** Bug 250199 has been marked as a duplicate of this bug. ***
Comment 4 Radar WebKit Bug Importer 2023-01-13 02:31:18 PST
<rdar://problem/104217613>
Comment 5 Eric Carlson 2023-01-13 11:46:16 PST
Your video frames have black bars because the aspect ratio of the monitor is different than the aspect ratio of the capture size. This happens because your getDisplayMedia constraints doesn't specify a video stream width or height, so WebKit's default of 640x480 is used.

If you don't want black bars you can pass just a width or just a height in your getDisplayMedia constraints, and WebKit will pick the other using the screen's intrinsic aspect ratio.

For example, this will result in a video track that is 640px wide without bars:

  const constraints = {
    video: { width: 640 },
  };
  stream = await navigator.mediaDevices.getDisplayMedia({ video: { width: 640 } });
  video.srcObject = stream;

Simple example here: https://jsfiddle.net/eric_carlson/nvrbptg0/


Alternatively, you could start capture without specifying width or height and use the MediaStreamTrack's intrinsic size (get with track.getCapabilities()) to calculate and set a new size.