WPF应用程序,用于以15秒的延迟广播视频

本文关键字:延迟 广播 视频 15秒 应用程序 用于 WPF | 更新日期: 2023-09-27 18:36:56

我有一个使用 Microsoft.expression.encoder 和框架 4.0 广播视频的 WPF 应用程序,但在广播时我遇到了 15 秒的延迟。是否有任何建议可以减少广播时的延迟。

以下是代码

using Microsoft.Expression.Encoder.Live; 
using Microsoft.Expression.Encoder;
private void button1_Click(object sender, RoutedEventArgs e)
{ 
    try 
    { 
        EncoderDevice video = null; 
        EncoderDevice audio = null;
        GetSelectedVideoAndAudioDevices(out video, out audio);
        StopJob();
        if (video == null)
        {
            return;
        }
        StopJob();
        _job = new LiveJob();
        if (video != null && audio != null)
        {
            //StopJob();
            _deviceSource = null;
            _deviceSource = _job.AddDeviceSource(video, audio);
            _job.ActivateSource(_deviceSource);
            // Finds and applys a smooth streaming preset        
            //_job.ApplyPreset(LivePresets.VC1HighSpeedBroadband4x3);
            // Creates the publishing format for the job
            PullBroadcastPublishFormat format = new PullBroadcastPublishFormat();
            format.BroadcastPort = 9090;
            format.MaximumNumberOfConnections = 50;
            // Adds the publishing format to the job
            _job.PublishFormats.Add(format);
            // Starts encoding
            _job.StartEncoding();
        }
        //webCamCtrl.StartCapture();
    }
    catch (Exception ex)
    {
        WriteLogFile(this.GetType().Name, "button1_Click", ex.Message.ToString());
    }
}

我正在使用MediaElement在我的服务器和客户端系统上显示网络摄像头。

在客户端

 try
            {
                theMainWindow.getServerIPAddress();
                IP = theMainWindow.machineIP;
                MediaElement1.Source = new Uri("http://" + IP + ":9090/");
            }
            catch (Exception ex)
            {
            }

WPF应用程序,用于以15秒的延迟广播视频

不幸的是,没有解决方案(至少截至2011年1月)。根据Microsoft:

"我们在编码过程中增加了几秒钟的延迟,然后在服务器级别进行了缓存,可以再增加 5-20 秒,最后 Silverlight 也会缓存几秒钟的延迟。

http://social.expression.microsoft.com/Forums/is/encoder/thread/898b2659-c0d5-4c84-8fba-225f58806f5d

您可以通过使用 PreviewWindow 而不是 MediaElement 来消除客户端中的一些延迟,从而绕过在客户端中显示流之前对流进行编码的需要。 PreviewWindow是一个 WinForms 控件,因此这仅适用于 WPF。

在 XAML 中:

<WindowsFormsHost>
    <wf:Panel x:Name="PreviewPanel" />
</WindowsFormsHost>

代码隐藏:

var previewWindow = new PreviewWindow(new HandleRef(this.PreviewPanel, this.PreviewPanel.Handle));
_deviceSource.PreviewWindow = previewWindow;
// ..
_job.ActivateSource(_deviceSource);