chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.27k stars 457 forks source link

Ability to specify capture window via CLI #3667

Open domisjustanumber opened 6 months ago

domisjustanumber commented 6 months ago

Is your feature request related to a problem? Please describe. I am using CEF to host some JS code that processes a video feed with some machine vision tools, and the biggest hurdle we've run into is the only way to get video into CEF is via real or virtual webcams. This is a bit flakey and needs external software installing to work (SpoutCam or OBS).

It would be great if I could take advantage of Chrome's screen capture features to capture the contents of a specific window - it will be higher quality, not require any external tools to work, and hopefully much more reliable.

Describe the solution you'd like I got very excited when I found --auto-select-window-capture-source-by-title as it's pretty much exactly what I'd like https://peter.sh/experiments/chromium-command-line-switches/#auto-select-window-capture-source-by-title

Then when I do this:

let stream = await navigator.mediaDevices.getDisplayMedia({
        "video": {
          "displaySurface": "window"
        }
    },);

CEF would automatically share the window that had been specified via the CLI switch.

Right now it only seems to work for Chrome, but would be exactly what I want if it could be implemented in CEF as well. This would allow me to put the video content I want to capture in a window, shuffle it mostly off-screen, then use CEF to capture it without it having to take up screen real-estate.

Describe alternatives you've considered Right now if I run that navigator.mediaDevices.getDisplayMedia command in CEF, all screens are shared, which seems to be due to this code which says "if no media ID is specified, share everything".

I'd hoped it might be possible to request a specific window or Media ID from the JS side, but for security reasons, it's also not possible for JS code to request a specific Window name in code.

Specifying the window to be shared in the CEF command line switch seems like the correct place to do this, and it would restrict what is shared right now vs. the entire desktop, so hopefully not an enhanced security concern.

I also considered WebRTC streaming into CEF, but it adds a lot of complexity, and importantly - a pretty big delay. As this is on the same machine, and low-latency interactivity is the goal, using screen capture instead is much more preferable.

Additional context While not quite the same thing, this request seems to be related to specifying screen sharing sources in https://github.com/chromiumembedded/cef/issues/3552

magreenblatt commented 6 months ago

This likely already works with Chrome runtime (cefclient --enable-chrome-runtime).

domisjustanumber commented 6 months ago

Ah alas I tested with CEF 122 and CEF 123.0.5. In both cases, adding --enable-chrome-runtime to both cefclient and cefsimple makes no difference to the screen sharing things - you still get all screens shared every time.

In some older versions (CEF 110 I believe) only a single monitor is shared if you just use the --use-fake-ui-for-media-stream, but it's not the window I was specifying with --auto-select-window-capture-source-by-title.

AlexeyKobyakov commented 2 weeks ago

I think something went wrong at the junction of versions CEF 103.0.8 and CEF 104.4.18 In CEF 103.0.8 used command cefclient --enable-chrome-runtime when call mediaDevices.getDisplayMedia() shows a dialog box for selecting a source for capture And in CEF 104.4.18 command cefclient --enable-chrome-runtime return error NotAllowedError: Permission denied And if run cefclient --enable-chrome-runtime --enable-media-stream Then there will be no dialog box for selecting a source and the full screen will be captured automatically. I also checked in version CEF 128.4.9. It behaves like version CEF 104.4.18 Also, all versions of cefsimple correctly display the dialog box for selecting a source for capture.