且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

减少流式传输和实时流式传输方法期间的延迟

更新时间:2022-01-14 23:56:31

与您遇到的问题相同,流延迟很大(大约1.5-1.6秒)

had same issue as you with huge stream delay (around 1.5 - 1.6 sec)

我的设置是使用libStreaming在RTSP上流式传输其相机的Android设备,接收端是使用libVlc作为媒体播放器的Android设备.现在,我找到了一种将延迟降低到250-300毫秒的解决方案.这是通过使用以下参数设置libVlc来实现的.

My setup is Android device which streams its camera over RTSP using libStreaming, receiving side is Android device using libVlc as media player. Now I found a solution to decrease delay to 250-300 ms. It was achieved by setting up libVlc with following parameters.

 mLibvlc = new LibVLC();
    mLibvlc.setVout(LibVLC.VOUT_ANDROID_WINDOW);
    mLibvlc.setDevHardwareDecoder(LibVLC.DEV_HW_DECODER_AUTOMATIC);
    mLibvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_DISABLED);
    mLibvlc.setNetworkCaching(150);
    mLibvlc.setFrameSkip(true);
    mLibvlc.setChroma("YV12");
    restartPlayer();

private void restartPlayer() {
    if (mLibvlc != null) {
        try {
            mLibvlc.destroy();
            mLibvlc.init(this);
        } catch (LibVlcException lve) {
            throw new IllegalStateException("LibVLC initialisation failed: " + LibVlcUtil.getErrorMsg());
        }
    }
}

您可以使用setNetworkCaching(int networkCaching)来自定义位延迟

You can play with setNetworkCaching(int networkCaching) to customize a bit delay

请告诉我它是否对您有帮助,或者您在此环境或其他环境中找到了更好的解决方案.

Please let me know if it was helpful for you or you found better solution with this or another environment.