Startsida‎ > ‎labs‎ > ‎

Playing with Expression Encoder 3

Expression Encoder 3 has been out for a while but I have never had time to test it. Yesterday I downloaded the free version from Microsoft website to play with it a little.

There are very few code samples available both in the EE3 SDK and on the net. The feeling is that EE3 is not seriously supported by MS or the community. 

On my Vista PC I have Visual Studio 8. The EE3 SDK is installed at the same time I install EE3. 
I used the live SDK sample as a starting-point with the aim to be able to do live streaming from my webcam. 

First I was a little confused. I couldn't find the Encoder object! Earlier when programming with the Windows Media Encoder 9 this was the main object for automation. OK, so I have to browse a few samples to find the right way to do it. I also printed out the class diagrams found in the EE3 SDK folder. I am rather glad that I am not going to automate the post production. The class diagram is huge. 

Basically what I did to get live streaming work:
  1. Get a reference to the LiveJob object. 
  2. Enumerate available video and audio devices and activate one of each type (video and audio).
  3. Select on of the eight live streaming presets.
  4. Setup the output broadcast format.
  5. Start encoding!

Code

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Expression.Encoder;
using Microsoft.Expression.Encoder.Live;

namespace Live
{
    class Program
    {
        /// <summary>
        /// This sample demonstrates boadcasting a simple file continuously looped.
        /// </summary>
        /// <param name="args">input parameters, the name of the file we are going to broadcast</param>
        static void Main(string[] args)
        {

            Console.Out.WriteLine("Starting encoding...");

            // Create a new LiveJob to begin broadcasting this file. Make sure
            // to dispose the LiveJob when you are finished with it.
            using (LiveJob livejob = new LiveJob())
            {
                // Lookup devices that can be used for live streaming
                foreach (LiveDevice liveDev in livejob.VideoDevices)
                {
                    Console.Out.WriteLine("Video: {0}", liveDev.Name);
                }

                foreach (LiveDevice liveDev in livejob.AudioDevices)
                {
                    Console.Out.WriteLine("Audio: {0}", liveDev.Name);
                }

                // Set live device
                LiveDeviceSource livesrc = livejob.AddDeviceSource(livejob.VideoDevices[0], livejob.AudioDevices[0]);

                // Activate the source
                livejob.ActivateSource(livesrc);

                // Lookup presets that can be used for live streaming
                // The presets are fixed!
                //LivePresets.VC1256kDSL16x9;
                //LivePresets.VC1256kDSL4x3;
                //LivePresets.VC1512kDSL16x9;
                //LivePresets.VC1512kDSL4x3;
                //LivePresets.VC1Broadband16x9;
                //LivePresets.VC1Broadband4x3;
                //LivePresets.VC1HighSpeedBroadband16x9;
                //LivePresets.VC1HighSpeedBroadband4x3;

                // Select one preset for the live webcast
                livejob.ApplyPreset(LivePresets.VC1Broadband4x3);

                // Create a new windows media broadcast output format so we
                // can broadcast this encoding on the current machine.
                // We are going to use the default audio and video profiles
                // that are created on this output format.
                WindowsMediaBroadcastOutputFormat outputFormat = new WindowsMediaBroadcastOutputFormat();

                // Let's broadcast on the local machine on port 8080
                outputFormat.BroadcastPort = 8080;

                // Set the output format on the job
                livejob.OutputFormat = outputFormat;

                Console.Out.WriteLine("Stream is available at http://localhost:8080");

                // Start encoding
                Console.Out.Write("Press 'x' to stop encoding...");
                livejob.StartEncoding();

                // Let's listen for a keypress to know when to stop encoding
                while (Console.ReadKey(true).Key != ConsoleKey.X)
                {
                    // We are waiting for the 'x' key
                }

                // Stop our encoding
                Console.Out.WriteLine("Encoding stopped.");
                livejob.StopEncoding();
            }
        }
    }
}

ċ
Live.zip
(3k)
Anders Mårtén,
8 Nov 2009, 11:43
ċ
LiveDevice-project.zip
(7k)
Anders Mårtén,
8 Nov 2009, 11:43
Comments