减少在Android上使用libvlc播放rtp流时的延迟 [英] Reduce delay when playing rtp stream with libvlc on Android
问题描述
我正在使用LibVLC 3.0.0版在Android上通过rtp播放传入的mpeg2ts流.代码如下:
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();
这确实会播放流,但是会有大约2秒的延迟.我肯定知道延迟可以减少到〜300毫秒,因为其他一些玩家可以在此延迟下播放它.我应该使用哪些选项来减少此延迟?我知道我将不得不为此而牺牲质量,但是我该如何做呢?
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?
推荐答案
有一种方法可以将延迟从〜2sec减少到〜200ms
There is a way to reduce the delay from ~2sec to ~200ms
解决方案:
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! =)
这篇关于减少在Android上使用libvlc播放rtp流时的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!