15

I've recently started using libVLC in an Android application with the intent of replacing a commercial SDK that we're paying a lot for, but not seeing the results that we'd hoped for. The application requires viewing RTSP streams at as-close-to real-time as possible. 500ms or better ideally (depending on the tablet), without that latency drifting over time.

The process of switching out the commercial SDK for libVLC was almost seamless and it worked right away, with the exception of the latency being a few seconds (without touching any default settings). It connects to the RTSP streams really fast, and doesn't drop connections.

I've spent a couple of days tweaking the various settings to try to reduce the latency as much as possible. In some cases, I get 300ms latency, that eventually drifts to a few seconds of latency, before the stream drops and restarts (and the latency dance begins again). In other cases (I guess when I set the network cache too low), I get a log full of errors and never get a picture.

My current settings are:

val media = Media(libVLC, Uri.parse(streamUrl))
media.setHWDecoderEnabled(true, false)
media.addOption(":network-caching=300")
media.addOption(":clock-jitter=0")
media.addOption(":clock-synchro=0")

If I set network-caching to anything less than 200, I never see an image (I read somewhere this might be because the tablet's decoder latency is higher than 200ms).

Anyways, I've found dozens of potential answers spanning a decade, some are similar, some conflicting, and some using deprecated flags. Some notable ones:

2019: https://forum.videolan.org/viewtopic.php?t=149511

m.AddOption(":network-caching=150");
m.AddOption(":clock-jitter=0");
m.AddOption(":clock-syncro=0");

2018: Android LibVLC options do not work

options.add("--network-caching=50");
options.add("--clock-jitter=0");
options.add("--clock-synchro=0");

2017: Reduce delay when playing rtp stream with libvlc on Android

LibVLC libVlc = new LibVLC(context, arrayListOf(
    "--file-caching=150", 
    "--network-caching=150",
    "--clock-jitter=0",
    "--live-caching=150", 
    "--clock-synchro=0",
    "-vvv", 
    "--drop-late-frames", 
    "--skip-frames"
)); 

...OR...

media.setHWDecoderEnabled(true, false);
media.addOption(":network-caching=150");
media.addOption(":clock-jitter=0");
media.addOption(":clock-synchro=0");

2015: https://forum.videolan.org/viewtopic.php?f=35&t=124932&p=420020&hilit=latency#p420020

Set network cache to 500, and disable HW acceleration

2015: Decrease delay during streaming and live streaming methods

mLibvlc.setDevHardwareDecoder(LibVLC.DEV_HW_DECODER_AUTOMATIC);
mLibvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_DISABLED);
mLibvlc.setNetworkCaching(150);
mLibvlc.setFrameSkip(true);

2013: Stream desktop over RTP using VLC with the lowest latency possible

Related to Desktop VLC and tweaking FFMPEG

And of course, we have the immense VLC flags list here: https://wiki.videolan.org/VLC_commaand-line_help/

So, in conclusion, is there a canonical method for libVLC 3+ on Android that we should collectively use for real-time streaming applications?

In my case, zero caching and dropping late frames, in order to stay as close as possible to real-time is ideal (even with janky frames). But, I do also understand that for most people, stable streaming (with occasional, sporadic frame drops) would be preferred.

I originally posted on the VideoLAN forums, 3 days ago.

SJoshi
  • 1,866
  • 24
  • 47
  • 1
    There is a new `low-delay` flag that you could try, need a recent (4+) build. – mfkl Jun 25 '19 at 01:50
  • Also try the LibVLC dev forum section. – mfkl Jun 25 '19 at 01:52
  • @mtz Thanks! I just found another low-latency post in that forum, including a mention to the 4.0 low-delay flag. I'm very curious about "Videolabs has 60ms latency working. That's not clean enough to be released yet." – SJoshi Jun 25 '19 at 02:36
  • Bear in mind that many options applied at `Media` level will probably have no effect. The only way to be sure, is to apply them at the `Instance` level. This is true for those us using python and I suspect true for other programming languages as well. – Rolf of Saxony Jul 02 '19 at 07:23
  • 1
    We went through this exact same path. There are a couple other parameters you can take a look at: rtsp-caching, realrtsp-caching, sout-mux-caching. Not sure if any of those are deprecated. I've found sometimes I have to go look in the actual source code to figure that out since the documentation is (as you noted) a mess of years. – avariant Jul 03 '19 at 22:14
  • Hello, any updates on that problem? Also, what is your playback start time? My rtsp h264/opus stream takes about 20 seconds to start :O – StayCool Feb 05 '20 at 09:12
  • 1
    @StayCool Unfortunately, no great answers. Playback time is pretty quick (seconds), but I haven't received any "canonical" settings yet. We're working with VLC to test out some low latency options, but the results are kinda scattered as we change settings. Short answer is that they're recommending waiting until VLC 4 is stable, as that should be a substantial improvement. – SJoshi Feb 11 '20 at 17:09
  • @Sjoshi thanks for inside details of what's going on. Actually, my current need is very low latency rtsp stream. Can you please share numbers of what you achieved using 3.0, so, if they not satisfying for my case, I could just start moving further, with or withour libVLC. Also, it would be really great, if you could kindly share some startup arguments which I can pass to my org.videolan.libvlc.VLC object and speed up start of playback ) thanks again and looking forward to your reply! – StayCool Feb 11 '20 at 17:52
  • 1
    Hey @StayCool, I don't have detailed numbers, because none of the numbers were even in the ballpark of what we needed them to be. Either they had low latency and then the lag accumulated to unreasonable levels (> 5 seconds) within a few minutes, or we had to accept a latency of around 1 second - and most of the arguments in my original answer/linked answers can lead to the 1 second latency. – SJoshi Feb 11 '20 at 18:02
  • @SJoshi feelsbad to hear that ( also, this is official port from 3.0 libvlc github.com/videolan/vlc-android? Do they have approximate date of releasing vlc 4.0 for android? – StayCool Feb 11 '20 at 18:23
  • 1
    @StayCool Yep. and Nope. – SJoshi Feb 12 '20 at 05:06
  • Hi @SJoshi, in my case I'm not interested in <1s latency but I'd like to disable this annoying lag accumulation that drifts to 5 seconds or more. Did your settings solved this drift? Did you find a final solution? – Oneiros Sep 15 '21 at 09:30
  • @Oneiros Unfortunately not. We've been in touch with VLC directly, and they proposed some ideas - none of which worked. It sounds like VLC 4 will be the way forward... Whenever it comes out (unless it has already officially come out, I haven't looked at this in a couple months) – SJoshi Sep 16 '21 at 13:01

0 Answers0