unosquare / ffmediaelement

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

Cannot get 0 delay( low latency) working #605

Open Wolfleader101 opened 2 years ago

Wolfleader101 commented 2 years ago

Cannot get 0 delay live stream working

I am trying to get an RTSP live stream with zero delay to work on my WPF application using FFME however I have been unable to set the correct parameters for it in your library.

Currently, I can run the following directly via FFPlay CLI and I don't get any delays.

Issue Categories

Version Information

Expected Results

Sample Code

In my code I have the following:

XAML

<ffme:MediaElement x:Name="slipsView"  Grid.ColumnSpan="3" LoadedBehavior="Play"  IsDesignPreviewEnabled="True" MediaInitializing="Media_OnMediaInitializing" Stretch="Fill"/>

C

        private void Media_OnMediaInitializing(object sender, MediaInitializingEventArgs e)
        {
            e.Configuration.PrivateOptions["fflags"] = "nobuffer";
            e.Configuration.PrivateOptions["flags"] = "low_delay";
            e.Configuration.PrivateOptions["preset"] = "ultrafast";
            e.Configuration.PrivateOptions["tune"] = "zerolatency";
            e.Configuration.PrivateOptions["fpsprobesize"] = "1";
            e.Configuration.PrivateOptions["max_delay"] = "1";
            e.Configuration.PrivateOptions["probe_size"] = "32";

            e.Configuration.GlobalOptions.ProbeSize = 32;
            e.Configuration.GlobalOptions.FlagNoBuffer = true;
            e.Configuration.GlobalOptions.EnableReducedBuffering = true;
        }

Command line ffplay

ffplay -fflags nobuffer -flags low_delay -preset ultrafast -tune zerolatency -fpsprobesize 1 -max_delay 1 -probesize 32   rtsp:/192.168.0.10/ISAPI/Streaming/Channels/102/
Wolfleader101 commented 2 years ago

Update: I was able to reduce the delay a little bit, but is not decreased the whole way.....

Adding OnMediaOpening event somewhat helps...

<ffme:MediaElement
    x:Name="slipsView"
    Grid.ColumnSpan="3"
    IsDesignPreviewEnabled="True"
    LoadedBehavior="Play"
    MediaInitializing="Media_OnMediaInitializing"
    MediaOpening="Media_OnMediaOpening"
    Stretch="Fill" />
private void Media_OnMediaOpening(object sender, MediaOpeningEventArgs e)
{
            e.Options.IsTimeSyncDisabled = true;
            e.Options.IsAudioDisabled = true;
            e.Options.MinimumPlaybackBufferPercent = 0;

            e.Options.DecoderParams.EnableFastDecoding = true;
            e.Options.DecoderParams.EnableLowDelayDecoding = true;
            e.Options.VideoForcedFps = 30;
}
Videstra commented 2 years ago

Although I don't think 0 latency can ever be achieved (nature of mpeg video) - right now I'm looking at about 2 seconds (inside my LAN). I'm going to try your methods and see how much it trims. Thanks for positing this!

Wolfleader101 commented 2 years ago

With ffplay I was able to get it below 250ms - but yes not 0 đŸ¤£

Videstra commented 2 years ago

@Wolfleader101 +1. I called the properties as you list them above and it appears (knock on wood) that the latency is significantly better for my application. Thanks for posting this!

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.

SundayGoGo commented 1 year ago

@Wolfleader101 hi,I used the above configuration to reduce the playback delay, but after playing for a while, the delay will become higher and higher. How to solve this problem?