Reduce delay when playing rtp stream with libvlc on Android
Asked Answered
M

3

6

I am using LibVLC version 3.0.0 to play incoming mpeg2ts stream over rtp on Android. The code is the following:

SurfaceView playerView; //Initialized somewhere before    

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"));
MediaPlayer player = new MediaPlayer(libVlc);
IVLCVout vout = player.getVLCVout();
vout.setVideoView(playerView);
vout.attachViews();
Media media = new Media(libVlc, Uri.parse("rtp://@:" + UDP_PORT + "/"));
player.setMedia(media);
player.play();

This does play the stream, but there is a delay of approximately 2 seconds. I know for certain that the delay can be reduced to ~300 ms as some other player can play it at this delay. Which options should I use to reduce this latency? I understand that I will have to trade quality for it, but how do I do it in the first place?

Marine answered 25/1, 2017 at 10:46 Comment(1)
can you help me how to integrate camera rtsp stream in flutterBraeunig
T
13

There is a way to reduce the delay from ~2sec to ~200ms

Solution:

 ArrayList<String> options = new ArrayList<>();
 options.add("--file-caching=2000");
 options.add("-vvv");

 LibVLC mLibVLC = new LibVLC(getApplicationContext(), options);
 MediaPlayer mMediaPlayer =  new MediaPlayer(mLibVLC);

 Media media = new Media(mLibVLC, Uri.parse("rtsp://192.168.0.1:1935/myApp/myStream"));
        media.setHWDecoderEnabled(true, false);
        media.addOption(":network-caching=150");
        media.addOption(":clock-jitter=0");
        media.addOption(":clock-synchro=0");

 mMediaPlayer.setMedia(media);
 mMediaPlayer.play();

Hope this help you! =)

Teneshatenesmus answered 31/1, 2017 at 15:29 Comment(5)
Hi, thank you for your answer! I have tried this and it does not seem to be working. What version of LibVLC are you using?Marine
compile "de.mrmaffen:vlc-android-sdk:2.0.6"Teneshatenesmus
With your code I have managed to reduce delay to ~800 ms. Is it possible to get it down even further?Marine
Great anwser! With this solution I reduced delay in rtsp stream from ~2s to ~300ms ;)Scarlettscarp
I also get delays with 2 sec it is possible to stream without delays it's a local networkAalto
D
2

I solved this problem.

Android:

    val options: ArrayList<String> = ArrayList()
    options.add("--file-caching=2000")
    options.add("-vvv")
    options.add("--rtsp-tcp")

Flutter:

class _MyHomePageState extends State<MyHomePage> {
final VlcPlayerController _vlcViewController = 
VlcPlayerController.network(
  "rtsp://RTSP_URL_HERE",
  autoPlay: true,
  options: VlcPlayerOptions(
      rtp: VlcRtpOptions([VlcRtpOptions.rtpOverRtsp(true)])));
Disputatious answered 22/12, 2022 at 15:3 Comment(1)
This code also working fine Thanks for post but i am getting bottom black bar its not fitting video view in Surface view can you please help me what i am doing wrongReflector
P
1

Using the following as options did the trick for me.

ArrayList<String> options = new ArrayList<>();
options.add("-vvv");
options.add("--rtsp-tcp");

LibVLC used:

implementation 'org.videolan.android:libvlc-all:3+'
Phyllous answered 7/1, 2022 at 15:22 Comment(1)
This code also working fine Thanks for post but i am getting bottom black bar its not fitting video view in Surface view can you please help me what i am doing wrong URL [1]: i.sstatic.net/5iG9u.pngReflector

© 2022 - 2024 — McMap. All rights reserved.