realtime stream from screencapture with microsoft expression encoder

8.6k Views Asked by At

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>

1

There are 1 best solutions below

3
On BEST ANSWER

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