unosquare / ffmediaelement

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

RTSP stream stops playing after few seconds #581

Open imothep666 opened 2 years ago

imothep666 commented 2 years ago

Hello,

I am writing a net core 3.1 wpf application to display multiple rtsp streams.

the NuGet-Package version is FFME:Windows 4.4.350 and FFmpeg.Autogen 4.4.1

At the moment I open a single fixed Uri in the code behind. But after a few seconds of playback the stream stops without any log output from ffmpeg.

When the window of the application is loaded I open the stream directly with:

if (!await MediaElement.Open(new Uri("rtsp://192.168.93.40:554/1"))) { throw new Exception("unable to open media stream"); }

further i have subscribed the "MediaInitializing", "MediaOpening" and "FFmpegMessageLogged" events.

` private void MediaElement_FFmpegMessageLogged(object sender, MediaLogMessageEventArgs e) { Debug.WriteLine(e.Message); }

    private void MediaElement_MediaInitializing(object sender, MediaInitializingEventArgs e)
    {
        //e.Configuration.GlobalOptions.ProbeSize = 32;
        e.Configuration.GlobalOptions.EnableReducedBuffering = true;
        e.Configuration.GlobalOptions.FlagNoBuffer = true;
        e.Configuration.GlobalOptions.MaxAnalyzeDuration = TimeSpan.Zero;
    }

    private void MediaElement_OnMediaOpening(object sender, MediaOpeningEventArgs e)
    {
        e.Options.IsTimeSyncDisabled = true;
        e.Options.MinimumPlaybackBufferPercent = e.Info.Format == "libndi_newtek" ? 0 : 0.5;
        e.Options.IsAudioDisabled = true;
    }

`

The FFmpeg log: ` [tcp @ 0a3a8ac0] Starting connection attempt to 192.168.93.40 port 554

    [tcp @ 0a3a8ac0] Successfully connected to 192.168.93.40 port 554
    [rtsp @ 0a3c1a80] SDP:
    v=0
    o=StreamingServer 3331435948 1116907222000 IN IP4 192.168.93.40
    s=h264.mp4
    c=IN IP4 0.0.0.0
    t=0 0
    a=control:*
    m=video 0 RTP/AVP 96
    a=control:trackID=0
    a=rtpmap:96 H264/90000
    a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0KAH9oFglMBagQEBGBAA+gAAjKL3vhI,aM48gA==
    m=audio 0 RTP/AVP 0
    a=control:trackID=1
    a=rtpmap:0 PCMU/8000
    m=application 0 RTP/AVP 107
    a=control:trackID=2
    a=rtpmap:107 vnd.onvif.metadata/90000
    [udp @ 0a3aac00] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
    [udp @ 0a3aacc0] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
    [rtsp @ 0a3c1a80] setting jitter buffer size to 500
    [udp @ 0a3e6cc0] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
    [udp @ 0a3f7280] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
    [rtsp @ 0a3c1a80] setting jitter buffer size to 500
    [udp @ 0a4077c0] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
    [udp @ 0a407b40] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
    [rtsp @ 0a3c1a80] setting jitter buffer size to 500
    [h264 @ 0a3b4440] Reinit context to 352x288, pix_fmt: yuv420p
    [h264 @ 1f309800] Reinit context to 352x288, pix_fmt: yuv420p

`

Thanks in edvance

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.

cactusjack66 commented 3 months ago

I had the same problem, but after I used the following configuration, it (hopefully) does not seem to happen any longer:

private void onMediaOpening(object? sender, MediaOpeningEventArgs e)
{
        e.Options.IsTimeSyncDisabled = true;
        e.Options.IsAudioDisabled = true;
        e.Options.MinimumPlaybackBufferPercent = 0.1;
        e.Options.VideoForcedFps = 30;

        e.Options.DecoderParams.EnableFastDecoding = true;
        e.Options.DecoderParams.EnableLowDelayDecoding = true;
}
private void onMediaInitializing(object? sender, MediaInitializingEventArgs e)
{
        e.Configuration.PrivateOptions["rtsp_transport"] = "tcp";
        e.Configuration.PrivateOptions["fflags"] = "nobuffer";
        e.Configuration.PrivateOptions["flvflags"] = "no_duration_filesize";
        e.Configuration.PrivateOptions["avioflags"] = "direct";
        e.Configuration.PrivateOptions["framedrop"] = "true";
        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.GlobalOptions.ProbeSize = 32;
        e.Configuration.GlobalOptions.EnableReducedBuffering = true;
        e.Configuration.GlobalOptions.MaxAnalyzeDuration = TimeSpan.Zero;
}