google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.74k stars 6.03k forks source link

Latency playing RTSP video #11221

Open stratosk opened 1 year ago

stratosk commented 1 year ago

I'm using ExoPlayer for RTSP streaming video. When I initially set the mediaSource and prepare the player, the video starts to play after ~10sec. So, the video is already 10 sec behind the edge of the stream.

I use a listener like this:

override fun onPlaybackStateChanged(state: Int) {
                super.onPlaybackStateChanged(state)
                if (state == Player.STATE_READY) {
                    val bufferedPosition = exoPlayer.bufferedPosition
                    exoPlayer.seekTo(bufferedPosition)
                }
            }

in order to seek to the end of the stream once the video starts to play. This cause a delay of another 10 seconds that the video freezes (due to buffering) but at the end the player almost is synced to the end of the stream.

I use this configuration for load control and livePlaybackSpeedControl:

        val loadControl = DefaultLoadControl.Builder()
            .setBufferDurationsMs(
                400,
                3000,
                400,
                400
            )
            .build()
        val livePlaybackSpeedControl = DefaultLivePlaybackSpeedControl.Builder()
            .setFallbackMinPlaybackSpeed(0.5f)
            .setFallbackMaxPlaybackSpeed(1.5f)
            .build()

Is there anything I can do to minimize these 10 seconds delays?

Thanks in advance!

microkatz commented 1 year ago

@stratosk

I don't advise that seekTo method call after onPlaybackStateChanged as that will cause buffering. ExoPlayer is not setup to play an RTSP stream as a live stream. You can adjust the DefaultLoadControl settings as you have done to lessen the amount of samples needed to buffer before playing.

10 seconds seems like a long time to start playing though. Do you know if you are using TCP or UDP with your rtsp source? If you are using UDP then that might be quicker with the less overhead. I could check if you were to send logs. To enable logging, use RtspMediaSource.Factory.setDebugLoggingEnabled().

stratosk commented 1 year ago

@microkatz thanks for your response!

I'm using UDP. I enabled the logs. Please find attached the section of the logcat until I see the video playing.

stratosk commented 1 year ago

exoplayer.log

SFocus commented 1 year ago

@stratosk did you manage to solve the problem? I have the same problem as you. I need the stream to go almost without delay, low latency as possible.

stratosk commented 1 year ago

@stratosk did you manage to solve the problem? I have the same problem as you. I need the stream to go almost without delay, low latency as possible.

@SFocus no I didn't. I tried with VLC. I have again some seconds delay, but at least when it starts playing, there is < 1sec delay from the edge of the video. But, I still prefer ExoPlayer because of it's small size.

SFocus commented 1 year ago

@stratosk thank you for your response. You can take a look at the GStreamer library. With it I have achieved a delay in milliseconds, but I have other problems somewhere there is a crash.

Vane101 commented 1 year ago

@stratosk thank you for your response. You can take a look at the GStreamer library. With it I have achieved a delay in milliseconds, but I have other problems somewhere there is a crash.

Hi what type of problems are you encountering, checking if its worth going down that path.

microkatz commented 1 year ago

exoplayer.log

Hi @stratosk, sorry for the delay. I looked at your file but did not see any ExoPlayer logs as well. You'll need to make sure you also add the EventLogger as an Analytics Listener to your player. Here is some documentation on how to do that. https://developer.android.com/guide/topics/media/exoplayer/debug-logging.

Also here are some directions about how to take a bug report.

Please again update this bug when you have done so! Thank you!

stratosk commented 1 year ago

Hi @microkatz . No worries. Thank you for your response. Below the log after enabling the EventLogger. eventloger.txt