使用 Microsoft 表达式编码器进行屏幕捕获的实时流

发布于 2024-11-10 03:49:57 字数 3196 浏览 4 评论 0 原文

是否可以在本地网络上实时传输屏幕的一部分? 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>

Is it possible to stream in real-time a part of the screen for the local network?
The ScreenCaptureJob can only stream to a file, and if a want to broadcast the file, it blocks because it's used by another process.

            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();

EDIT:
New problem, it isnt running realtime.I'he got a delay of 10 seconds, I need real-time or at least 1second. It doesn't go through the Internet

Server code:

 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();

Player Code:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的笑 2024-11-17 03:49:57

是的,从 Encoder 4 SP1 开始就有可能(今年发布)

屏幕捕获作为实时源 - 现在您可以选择屏幕作为实时项目中的设备进行流式传输或存档。
(来源) >

以编程方式

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

所以您需要这样的东西:

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 ...

Yes its possible since Encoder 4 SP1 (released this year)

Screen capture as a live source - Now you can select the screen as a device in Live projects to stream or archive.
(Source)

Programmatically:

The EncoderDevice Collection returned by EncoderDevices.FindDevices(EncoderDeviceType.Video)contains a device named "Screen Capture Source"

So something like this is what you would need:

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 ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文