5

I'm looking for a way to duplicate my desktop on a network. (Something that would work on a web browser client would be amazing.)

  • I tried to use vnc / x11vnc but quality/framerate is too low. (cpu too high on smartphone client - I think.)

  • I tried to transform the screen into a streaming video with ffmpeg but i couldn't do it. (bad quality and not real streaming system)

Is there a way to do that ? Maybe by using X11 forwarding and duplicate screen ?

A mix of ssh -X and xrandr -d :0 --output HDMI-1 --auto maybe ? (This xrandr code duplicate screen on HDMI-1)

Like : xrandr -d :0 --output http://192.168.1.3:9001 --auto (I'm dreaming.)

EDIT : Maybe xpra can do what I'm looking for ? But I can't make it work for now.

bob dylan
  • 1,832
  • 3
  • 20
  • 31
  • Do you need to interact with the screen as well or just display/stream it? – rudib Dec 17 '18 at 13:14
  • just display is enough (duplicate screen) read-only – bob dylan Dec 17 '18 at 14:14
  • just like if it was another screen with the same output – bob dylan Dec 17 '18 at 14:23
  • `xpra` seems to be more for individual applications that are invoked from the remote side. I'm usure if that's what you want. Did you try the improved `ffmpeg` command? An alternative could be something like NX (a remote desktop application, see e.g. NoMachine). Remote desktop applictations may be more optimised in regards of latency. However note that the person on the other end can interact with your machine. This should also be the case with `xpra`. – rudib Dec 20 '18 at 21:17
  • Yeah.. but high cpu usage, low quality, low fps. I was really hoping for more... Using more network, less cpu. – bob dylan Dec 23 '18 at 11:44
  • I don't understand where is the problem about sending data to the wifi instead of the let's say hdmi cable... (speed of course, but I'm far from using the bandwidth of my 802.11ac in everything i tried) – bob dylan Dec 23 '18 at 11:47
  • There is a significant CPU load to be expected when screen capturing. There is a fundamental difference between the hardware output of your graphics chip and the programmatically captured and encoded screen. Essentially, there is a whole processor dedicated to render your graphics output. You could try to leverage that by running ffmpeg with hardware acceleration. See the [docs](https://trac.ffmpeg.org/wiki/HWAccelIntro). If I can make that work I'll also update my answer, but it might depend on your graphics chip/card if this is supported. – rudib Dec 23 '18 at 13:16
  • To (almost) completely eliminate the load, you could use a dedicated e.g. HDMI capturing device. – rudib Dec 23 '18 at 13:19
  • yeah but google remote desktop is doing a way better job at this. (Try to play a video player and record with ffmpeg, the result isn't great.) I don't think that recording the screen and sending it over the network is the way to go. – bob dylan Dec 23 '18 at 14:59
  • I'm afraid, you can't fix this completely. Google remote desktop may do a better job, but effectively it's doing the same thing, recording the screen and sending it over the network (while still having some latency). I'm not sure what your application is exactly, so I can't really improve my recommendations. The nature of the content is a crucial factor in this. For serious (hq, live) streaming you'd have to use a powerful workstation that can put up with the recording and encoding load. – rudib Dec 23 '18 at 17:40

3 Answers3

3

You could use ffmpeg for that:

On the transmitting device, run:

ffmpeg -f x11grab -s 1800x1000 -framerate 30 -i :0.0 -preset fast -vcodec libx264 -tune zerolatency -b 900k -f mpegts udp://RECEIVERIP:9000

And on the receiving device, open the firewall port 9000/UDP and run:

ffplay udp://@:9000

You need to set RECEIVERIP accordingly, as well as adjust the area of the screen you want to transmit by modifying -s 1800x1000. Of course, you can choose any free port you want instead of 9000.

Performance-wise you can adjust -framerate and -preset (...|fast|ultrafast) as far as your transmitting machine can handle while maintaining the quality and latency you need.

ffplay is a very minimal client that may fit your needs. You could also use vlc.

To display the stream on a browser, you would probably have to use a streaming server in addition. vlc would have that capability, but it may be slow and I didn't find suffucient documentation for that yet.

Notes:

An optimised transmitting command (for lower latency, but lower quality and not especially dynamic content) may look like this:

ffmpeg -f x11grab -s 1800x1000 -framerate 15 -i :0.0 -preset ultrafast -vcodec libx264 -tune zerolatency -b 500k -f mpegts udp://RECEIVERIP:9000

To further optimise the load, you can leverage hardware acceleration, as documented. While this is platform dependent, it might significantly decrease the CPU load if supported.

rudib
  • 1,532
  • 1
  • 13
  • 33
  • 1
    I appreciate the full example. I tried to use this but the cpu usage is way too high, ~30% with `ultrafast`. And there is delay of about 3 seconds. – bob dylan Dec 19 '18 at 09:31
  • tested it on localhost `127.0.0.1` – bob dylan Dec 19 '18 at 09:39
  • Unfortunately, you can't completely eliminate the CPU load. Decreasing the bitrate `-b 900k` should also decrease the load a bit. Of course the frame rate of 30 FPS may also be too high for your machine. I'm not sure what exactly you want to transmit, so dropping the frame rate drastically may make sense or not. If you want to transmit dynamic content (e.g. video), that would require a high frame rate or it would be chopped up. But if the image is not expected to change rapidly, you could try 20 or 15 FPS. – rudib Dec 19 '18 at 10:55
  • I've updated my answer with an example (optimised for lower latency, lower quality and not especially dynamic content) that reduced the load on my machine to about 15-20% avg. Unfortunately, you can't really compare that. – rudib Dec 19 '18 at 12:44
2

Chrome Remote Desktop is probably what you are looking for:

https://chrome.google.com/webstore/detail/chrome-remote-desktop/gbchcmhmhahfdphkhkmpfmihenigjmpp?hl=en

V13
  • 4,551
  • 1
  • 15
  • 20
  • Interesting but it is very similar to vnc. (better than vnc I have to admit) But I was only able to create a new session with `exec /usr/bin/startxfce4` in `~/.chrome-remote-desktop-session`. Do you know how to duplicate screen from my laptop / read only ? – bob dylan Dec 19 '18 at 09:24
  • See here: https://support.google.com/chrome/answer/1649523 at the section "Share your computer with someone else" and "Access a computer remotely" – V13 Dec 19 '18 at 22:57
  • I still don't know how to duplicate a screen, i just have another session. – bob dylan Dec 23 '18 at 11:45
  • So, do you know how to duplicate the output of an existing session ? – bob dylan Jan 06 '19 at 11:04
0

Yes, you can do that with xpra. (both xpra, vnc and the ffmpeg solutions will use screenscraping to capture the pixel data - so there are performance constraints) Assuming that your X11 display is on ":0", try:

xpra shadow :0 --bind-tcp=0.0.0.0:14500 --tcp-auth=pam
#wait a second or two and then:
xdg-open http://localhost:14500/
totaam
  • 1,023
  • 8
  • 12