Stream desktop over RTP using VLC with the lowest latency possible
Asked Answered
L

2

9

I have been trying to figure out how to stream my desktop (over LAN) using VLC and to achieve the lowest latency possible (<100ms). The goal is to have another computer receive the stream and potentially play games while streaming (i.e playing game from PC1 on the PC beside the TV).

What settings should I use? I have tried multiple approaches but have yet to succeed.

EDIT: I am open to using something other than VLC as well.

Leitmotiv answered 4/5, 2013 at 1:38 Comment(0)
S
10

I have also tried the same with VLC and couldn't ever get latency bellow 3 seconds. FFmpeg did wonders and finally provided a latency bellow 1 second.

mpeg2video and UPD provided the best results, RTP latency felt a bit worse but very close. Moving to x264 improves quality in exchange for a bit more latency, but that really depends on how much dynamic content is there and how fast the CPU is. I only got x264 working with UDP, but there must be a way to do it with RTP.

I'm not sure it's feasible for playing. The server will be under a heavy workload and latency will be noticeable - at least on Linux, don't know about windows.

On Linux try one of the following commands:

$ ffmpeg -f x11grab -s 1600x900 -r 50 -vcodec mpeg2video -b:v 8000 -f rtp rtp://192.168.0.10:1234

or

$ ffmpeg -f x11grab -s 1600x900 -r 50 -vcodec libx264 -preset ultrafast -tune zerolatency -crf 18 -f mpegts udp://192.168.0.10:1234

Adjust for screen resolution (-s <your resolution>), refresh rate (-r <fps>), bandwidth (-b:v <bits/s>), quality (-crf 18 or -qp 18, the lower the better), and target ip:port.

If running Windows use dshow in place of x11grab.

Watch it using ffplay udp://192.168.0.10:1234 or ffplay sdp://192.168.0.10:1234.

Mind you that none of those options will stream sound. I was unable to get such low latencies when streaming audio as well. It might be doable, I just didn't figured out how.

The most responsive client was ffplay, VLC introduced too much latency even with its network cache set to zero - with such cache it actually got worse, since it tried to 'resync' the stream too often.

If you need further details I made a post about my findings. Hope it helps. I appreciate any feedback. ^_^

Susian answered 9/6, 2013 at 21:23 Comment(4)
FFmpeg also has some x264 encoding settings like "-tune zerolatency" that might be useful here: trac.ffmpeg.org/wiki/StreamingGuide#LatencyTrying
I came to your website before running over this article. For my opinion vlc and ffplay had the almost same latency.Apo
I'd tried to pass resolution parameter as below URL but it does't seems to work, i mean rtsp recorded mp4 video remains high resolution even if i've passed 320x240 :( "-t 30 -i \"rtsp://xxx.xxxxxx.com/2\" -s 320x240 -acodec copy -vcodec copy -to"Summit
I get Output file #0 does not contain any streamAlphonsealphonsine
C
0

It needs to set display like display 0 with -i :0.0 flag, following works for me, now i am trying to lower the latency without giving up the quality;

ffmpeg -f x11grab -i :0.0 -s 1920x1080 -r 1000 -vcodec libx264 -preset ultrafast -tune zerolatency -crf 18 -f mpegts udp://192.168.13.37:5000
Cattish answered 3/2 at 3:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.