gpt4 book ai didi

c# - 来自带有微软表达式编码器的屏幕截图的实时流

转载 作者:行者123 更新时间:2023-11-30 15:44:13 25 4
gpt4 key购买 nike

是否可以为本地网络实时流式传输部分屏幕?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>

最佳答案

是的,从 Encoder 4 SP1 开始(今年发布)

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

以编程方式:

EncoderDevices.FindDevices(EncoderDeviceType.Video) 返回的 EncoderDevice 集合包含一个名为“Screen Capture Source”的设备

所以你需要这样的东西:

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

关于c# - 来自带有微软表达式编码器的屏幕截图的实时流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6173914/

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