使用microsoft表达式编码器从屏幕捕获实时流

时间:2011-05-30 08:24:24

标签: c# live-streaming expression-encoder expression-encoder-sdk expression-encoder-4

是否可以实时流式传输本地网络的部分屏幕? ScreenCaptureJob只能传输到一个文件,如果想要广播该文件,它会阻止,因为它被另一个进程使用。

            jobScreenCap = new ScreenCaptureJob();
        // Creates a new job for encoding
        job = new LiveJob();
        var capRect = new System.Drawing.Rectangle(0, 0, 300, 200);
        jobScreenCap.CaptureRectangle = capRect;
        jobScreenCap.ScreenCaptureVideoProfile = new ScreenCaptureVideoProfile();
        jobScreenCap.ScreenCaptureVideoProfile.Force16Pixels = true;
        EncoderDevice device = jobScreenCap.VideoDeviceSource;
        // -> the device is null
        //var source = job.AddDeviceSource(device, null);
        jobScreenCap.OutputPath = @"C:\output\ScreenCap";
        var fileName = @"C:\output\ScreenCap\test1.ismv";
        jobScreenCap.OutputScreenCaptureFileName = fileName;
        jobScreenCap.Start();
        LiveFileSource fileSource = job.AddFileSource(fileName);
        // Makes this file the active source. Multiple files can be added 
        // and cued to move to each other at their ends
        job.ActivateSource(fileSource);
        var format = new PullBroadcastPublishFormat();
        format.BroadcastPort = 8080;
        job.PublishFormats.Add(format);
        job.StartEncoding();

修改 新问题,它不是实时运行。我有10秒的延迟,我需要实时或至少1秒。它没有通过互联网

服务器代码:

 job = new LiveJob();

        Collection<EncoderDevice> devices = EncoderDevices.FindDevices(EncoderDeviceType.Video);
        EncoderDevice device = devices[0]; // maybe its somewhere else, so check for name ...  

        LiveDeviceSource source = job.AddDeviceSource(device, null);
        source.ScreenCaptureSourceProperties = new ScreenCaptureSourceProperties
                                                   {
                                                       CaptureCursor = true,
                                                       CaptureLargeCursor = false,
                                                       FrameRate = 6,
                                                       CaptureLayeredWindow = true,
                                                       Height =600,
                                                       Width = 800,
                                                       Left = 0,
                                                       Top = 0,
                                                   };
        job.ActivateSource(source);

         // Finds and applys a smooth streaming preset
        job.ApplyPreset(LivePresets.VC1256kDSL16x9);

        // Sets up variable for fomat data

            var format = new PullBroadcastPublishFormat {BroadcastPort = 8080};

        job.PublishFormats.Add(format);
        var data = job.BufferWindowSize;
        job.StartEncoding();

玩家代码:

<Window x:Class="XescPlayer.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="800">
<Grid>
    <MediaElement Name="VideoControl" Source="http://localhost:8080" />
</Grid>

1 个答案:

答案 0 :(得分:4)

是可能的,因为编码器4 SP1 (今年发布)

  

作为实时源的屏幕截图 - 现在您可以选择屏幕作为实时项目中的设备进行流式处理或存档。
  Source

编程:

EncoderDevice返回的EncoderDevices.FindDevices(EncoderDeviceType.Video)集合包含名为“屏幕捕获源”的设备

所以这就是你需要的东西:

LiveJob job = new LiveJob();   

Collection<EncoderDevice> devices = EncoderDevices.FindDevices(EncoderDeviceType.Video);
EncoderDevice device = devices[0]; // maybe its somewhere else, so check for name ...  

LiveDeviceSource source = job.AddDeviceSource(device, null);
source.ScreenCaptureSourceProperties = new ScreenCaptureSourceProperties(); // your Screen Capture settings here ...