gpt4 book ai didi

c# - 使用 FFMPEG/FFMediaElement (FFME) 在 WPF 应用程序中以低延迟播放 RTSP

转载 作者:行者123 更新时间:2023-12-04 22:47:09 26 4
gpt4 key购买 nike

我正在尝试使用 FFMediaElement (FFME,基于 FFmpeg 的 WPF MediaElement 替换)组件在我的 WPF 应用程序中播放 RSTP 实时视频。

我的相机连接良好,我想以最小的可用延迟播放它。

我通过更改 ProbeSize 减少了延迟到它的最小值:

private void Media_OnMediaInitializing(object Sender, MediaInitializingRoutedEventArgs e)
{
e.Configuration.GlobalOptions.ProbeSize = 32;
}

但是自流开始以来,我仍然有大约 1 秒的延迟。我的意思是,当我开始播放时,我必须等待 1 秒,直到视频出现,然后我有 1 秒的延迟。

我还尝试更改以下参数:
e.Configuration.GlobalOptions.EnableReducedBuffering = true;
e.Configuration.GlobalOptions.FlagNoBuffer = true;
e.Configuration.GlobalOptions.MaxAnalyzeDuration = TimeSpan.Zero;

但它没有结果。

我测量了 FFmpeg 输出行之间的时间间隔(第一列中的数字是时间,从上一行经过,毫秒)
 ----     OpenCommand: Entered
39 FFInterop.Initialize: FFmpeg v4.0
0 EVENT START: MediaInitializing
0 EVENT DONE : MediaInitializing
379 EVENT START: MediaOpening
0 EVENT DONE : MediaOpening
0 COMP VIDEO: Start Offset: 0,000; Duration: N/A
41 SYNC-BUFFER: Started.
609 SYNC-BUFFER: Finished. Clock set to 1534932751,634
0 EVENT START: MediaOpened
0 EVENT DONE : MediaOpened
0 EVENT START: BufferingStarted
0 EVENT DONE : BufferingStarted
0 OpenCommand: Completed
0 V BLK: 1534932751,634 | CLK: 1534932751,634 | DFT: 0 | IX: 0 | PQ: 0,0k | TQ: 0,0k
0 Command Queue (1 commands): Before ProcessNext
0 Play - ID: 404 Canceled: False; Completed: False; Status: WaitingForActivation; State:
94 V BLK: 1534932751,675 | CLK: 1534932751,699 | DFT: 24 | IX: 1 | PQ: 0,0k | TQ: 0,0k

因此,“同步缓冲”过程花费的时间最多。

FFmpeg 是否有任何参数可以减小缓冲区的大小?

最佳答案

我是FFME的作者。这是一个常见的问题。除了 MediaInitializing 事件中的容器配置选项,您还可以处理 MediaOpening事件并更改以下选项:(这仅适用于版本 4.1.280 及更高版本)

    // You can render audio and video as it becomes available but the downside of disabling time
// synchronization is that video and audio will run on their own independent clocks.
// Do not disable Time Sync for streams that need synchronized audio and video.
e.Options.IsTimeSyncDisabled =
e.Info.Format == "libndi_newtek" ||
e.Info.InputUrl.StartsWith("rtsp://uno");

// You can disable the requirement of buffering packets by setting the playback
// buffer percent to 0. Values of less than 0.5 for live or network streams are not recommended.
e.Options.MinimumPlaybackBufferPercent = e.Info.Format == "libndi_newtek" ? 0 : 0.5;

// The audio renderer will try to keep the audio hardware synchronized
// to the playback position by default.
// A few WMV files I have tested don't have continuous enough audio packets to support
// perfect synchronization between audio and video so we simply disable it.
// Also if time synchronization is disabled, the recommendation is to also disable audio synchronization.
Media.RendererOptions.AudioDisableSync =
e.Options.IsTimeSyncDisabled ||
e.Info.InputUrl.EndsWith(".wmv");

关于c# - 使用 FFMPEG/FFMediaElement (FFME) 在 WPF 应用程序中以低延迟播放 RTSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51895242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com