我正在使用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毫秒,因为其他一些玩家可以在此延迟下播放它。我应该使用哪些选项来减少此延迟?我知道我必须为此付出代价,但是我该如何做呢?
有一种方法可以将延迟从〜2sec减少到〜200ms
解:
ArrayListoptions = 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();
希望这对您有所帮助!=)