unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.15k stars 238 forks source link

Setting low latency flags does not lower the latency in video playback from rtsp stream #606

Open Videstra opened 2 years ago

Videstra commented 2 years ago

Setting low latency flags does not lower the latency in the media element.

Although the same flags work as expected in ffplay (same DLLs being used in the ffmediaelement), setting those flags through the PrivateOptions in the MediaInitializing event do not result in lowered latency.

Issue Categories

Version Information

Steps to Reproduce

I used the sample code from the sample provided in the github download. I refactored to VB.net as:

    Private Sub OnMediaInitializing(sender As Object, e As Unosquare.FFME.Common.MediaInitializingEventArgs) Handles Media.MediaInitializing
        'calls as an attempt to reduce latency on the video playback over rtsp.   The udp part may not work well over the internet however, we may need to use tcp
        If e.MediaSource.StartsWith("rtsp://", StringComparison.InvariantCultureIgnoreCase) Then
            e.Configuration.PrivateOptions("rtsp_transport") = "tcp"
            e.Configuration.PrivateOptions("flags") = "low_delay"
            e.Configuration.PrivateOptions("framedrop") = ""
            e.Configuration.GlobalOptions.FlagNoBuffer = True
            e.Configuration.GlobalOptions.EnableReducedBuffering = True
            e.Configuration.GlobalOptions.FlagDiscardCorrupt = True
            e.Configuration.GlobalOptions.MaxAnalyzeDuration = TimeSpan.Zero
            e.Configuration.GlobalOptions.ProbeSize = 32
        End If
    End Sub

The following commandline for ffplay results in very low latency:

ffplay -fflags nobuffer -flags low_delay -flags drop_changed -framedrop -rtsp_transport tcp rtsp://admin:admin@192.168.1.13:554/media/video1

The latency in the ffplayer window is <1/4 second. However setting all the flags in the code provided above continues to result in a latency of nearly 2 seconds in the ffmediaelement.
Since I am using this for a camera control application (Pan Tilt Zoom Focus) the long latency makes it extremely difficult to use.
Perhaps I am not setting these correctly (Based on the sample provided in the download the PrivateOptions do not need the dash in the key (e.g. e.Configuration.PrivateOptions("-flags") = "low_delay"). Please let me know if they do. Perhaps the ffmediaelement has it's own lengthy internal buffers that can't be bypassed...

Wolfleader101 commented 2 years ago

Same issue has #605

Videstra commented 2 years ago

Same issue has #605

Yes - sorry to post something redundant, but it would be good to get this sorted.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.