java – 在Android上使用libvlc播放rtp流时减少延迟
作者:互联网
我正在使用LibVLC 3.0.0版在Android上通过rtp播放传入的mpeg2ts流.代码如下:
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毫秒,因为其他一些玩家可以在这个延迟时间播放它.我应该使用哪些选项来减少延迟?我知道我必须为此交易质量,但我该如何做呢?
解决方法:
有一种方法可以将延迟从~2秒减少到~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();
希望这对你有所帮助! =)
标签:vlc,libvlc,android,java 来源: https://codeday.me/bug/20191006/1858431.html