使用 Microsoft 表达式编码器进行屏幕捕获的实时流
是否可以在本地网络上实时传输屏幕的一部分? 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,从 Encoder 4 SP1 开始就有可能(今年发布)
以编程方式:
EncoderDevices.FindDevices(EncoderDeviceType.Video)
返回的EncoderDevice
集合包含一个设备名为“屏幕捕获源”所以您需要这样的东西:
Yes its possible since Encoder 4 SP1 (released this year)
Programmatically:
The
EncoderDevice
Collection returned byEncoderDevices.FindDevices(EncoderDeviceType.Video)
contains a device named "Screen Capture Source"So something like this is what you would need: