我目前正在尝试使用Expression Encoder SDK,但我发现在实时流式传输时使用它非常困惑。我正在尝试从网络摄像头捕获视频流,使用我的程序进行编码,然后将其作为实时流从我的计算机发布,同时还注入脚本命令。我一直在浏览SDK但我找不到任何与直播或网络摄像头有关的内容。一些代码示例提到了如何使用 Job 类进行编码,但我发现的只是本地编码文件。

有帮助吗?

解决方案

尚未尝试过,但有一个名为Microsoft.Expression.Encoder.Live.LiveJob的类应该支持流式传输。我尝试了这个示例,它从我的硬盘上传输了一个文件。我想它也应该支持编码视频流。以下是示例代码(适用于编码器3.0)

using (LiveJob job = new LiveJob())
            {
                // Create a new file source from the file name we were passed in
                LiveFileSource fileSource = job.AddFileSource(fileToEncode);

                // Set this source to Loop when finished
                fileSource.PlaybackMode = FileSourcePlaybackMode.Loop;

                // Make this source the active one
                job.ActivateSource(fileSource);

                // 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
                job.OutputFormat = outputFormat;

                // Start encoding
                Console.Out.Write("Press 'x' to stop encoding...");
                job.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.");
                job.StopEncoding();
            }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top