问题描述
|
是否可以实时流式传输本地网络的一部分屏幕?
ScreenCaptureJob只能流式传输到文件,并且如果要广播该文件,则该文件将被阻止,因为它已被另一个进程使用。
jobScreenCap = new ScreenCaptureJob();
// Creates a new job for encoding
job = new LiveJob();
var capRect = new System.Drawing.Rectangle(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(今年发布)以来是可能的
屏幕截图作为实时信号源-现在,您可以在Live项目中选择屏幕作为设备进行流式传输或存档。
(资源)
以编程方式:
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 ...