使用 Windows Media Encoder 录制屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/810994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:23:23  来源:igfitidea点击:

using Windows Media Encoder to record screen

windowsscreenmediacaptureencoder

提问by George2

Is it easy to write some .Net code to record screen and audio (from computer mic), then output to an wmv file. Any reference code?

编写一些 .Net 代码来记录屏幕和音频(来自计算机麦克风),然后输出到 wmv 文件是否容易。有参考代码吗?

BTW: I searched all codes from WME SDK, no such sample code.

顺便说一句:我从 WME SDK 中搜索了所有代码,没有这样的示例代码。

thanks! George

谢谢!乔治

回答by hlovdal

Microsoft and the content mafi^H^H^H^Hindustry are trying their best to make this impossible. You will be far better of searching for "open source screen audio capture" than browsing any officially supplied documentation/example code - I would be seriously surprised if Microsoft provided anything relevant.

微软和内容黑手党^H^H^H^Hindustry 正在尽最大努力使这成为不可能。与浏览任何官方提供的文档/示例代码相比,搜索“开源屏幕音频捕获”会更好 - 如果 Microsoft 提供任何相关内容,我会感到非常惊讶。

回答by Dylan Beattie

Check out the SDK that's available for Techsmith Camtasia:

查看可用于 Techsmith CamtasiaSDK

Camtasia is a full-screen desktop recording app with support for various video and audio sources, codecs, etc., and their SDK exposes this as an ActiveX control (which you can call from .NET quite happily).

Camtasia 是一个全屏桌面录制应用程序,支持各种视频和音频源、编解码器等,他们的 SDK 将其公开为 ActiveX 控件(您可以很高兴地从 .NET 调用它)。

回答by Nick Whaley

There are DirectShow compatible filters for screen capture. Which will allow you to use any recording program to capture the screen content or write an application yourself in .NET (but its not easy).

有用于屏幕捕获的 DirectShow 兼容过滤器。这将允许您使用任何录制程序来捕获屏幕内容或在 .NET 中自己编写应用程序(但这并不容易)。

The one I use is: http://www.hmelyoff.com/index.php?section=9

我使用的是:http: //www.hmelyoff.com/index.php?section=9

EDIT:I have don't have a sample or experience with the WME SDK. But I would recommend going the DirectShow route to avoid the requirement of having WME on the host system, the lack of support for it, and its just good to know DirectShow (or do it yourself) rather than some random API.

编辑:我没有 WME SDK 的示例或经验。但我建议使用 DirectShow 路线,以避免在主机系统上安装 WME、缺乏对它的支持,并且最好了解 DirectShow(或自己动手)而不是一些随机的 API。

To use the Hmelyoff filter, it works just like a webcam. Its just another video capture source available to any application that wants video input. It works by just copying the part of the viedo buffer to it's output pin on each frame (using a API function like BitBlt).

要使用 Hmelyoff 过滤器,它就像网络摄像头一样工作。它只是需要视频输入的任何应用程序可用的另一个视频捕获源。它的工作原理是将视频缓冲区的一部分复制到每一帧的输出引脚(使用像 BitBlt 这样的 API 函数)。

Some sample code is here.

一些示例代码在这里

Or if you want to just interface to DirectShow, the easiest way is using a library to do the COM interaction for you. http://directshownet.sourceforge.net/is a good one.

或者,如果您只想与 DirectShow 交互,最简单的方法是使用库为您进行 COM 交互。http://directshownet.sourceforge.net/是一个不错的选择。

EDIT again:Capturing as video is the same as capturing frames. It just captures frames 30 times a second. CPU hog? It is, don't expect to get the full framerate.

再次编辑:捕获为视频与捕获帧相同。它每秒只捕获 30 次帧。CPU 猪?是的,不要期望获得完整的帧率。

If what you are asking is how to save the frames as video, then you are going to need to pass the data to a video encoder. You WILL need to interface to DirectShow to do this.

如果您要问的是如何将帧保存为视频,那么您将需要将数据传递给视频编码器。您将需要连接到 DirectShow 来执行此操作。

回答by Chibueze Opata

Your best bet will be to import the windows media encoder libraries as a com interface in your .net application and use it in your application.

最好的办法是将 windows 媒体编码器库作为 .net 应用程序中的 com 接口导入,并在您的应用程序中使用它。

回答by Pablo Romeo

Yes, that is totally doable with WME: http://www.c-sharpcorner.com/UploadFile/armoghanasif/CaptureDesktopActivities11122005013755AM/CaptureDesktopActivities.aspx

是的,WME 完全可以做到:http://www.c-sharpcorner.com/UploadFile/armoghanasif/CaptureDesktopActivities11122005013755AM/CaptureDesktopActivities.aspx

I've done it in the past, and you can get very good quality videos once you start tweaking the encoding settings. Especially if WMV is a viable option for you. If not you'd have to re-encode to another format using another application.

我过去曾经这样做过,一旦开始调整编码设置,您就可以获得质量非常好的视频。特别是如果 WMV 对您来说是一个可行的选择。如果不是,您必须使用另一个应用程序重新编码为另一种格式。

The easiest way I found to tweak was to use the WME desktop application to test and record with different settings, and save those configuration files, which I later loaded programmatically from my application.

我发现的最简单的调整方法是使用 WME 桌面应用程序来测试和记录不同的设置,并保存这些配置文件,我后来从我的应用程序中以编程方式加载了这些文件。

回答by Cbrom

You can use Microsoft Expression Encoder 4, both to record video and audio. It just worked for me with C#. The following code should be familiar.

您可以使用 Microsoft Expression Encoder 4 来录制视频和音频。它只适用于 C#。下面的代码应该很熟悉。

void Encode(string jobPath)
    {
        using (Job j = new Job())
        {

            MediaItem mediaItem = new MediaItem(jobPath);
            var size = mediaItem.OriginalVideoSize;
            WindowsMediaOutputFormat WMV_Format = new WindowsMediaOutputFormat();
            WMV_Format.VideoProfile = new Microsoft.Expression.Encoder.Profiles.AdvancedVC1VideoProfile();
            WMV_Format.AudioProfile = new Microsoft.Expression.Encoder.Profiles.WmaAudioProfile();
            WMV_Format.VideoProfile.AspectRatio = new System.Windows.Size(16, 9);
            WMV_Format.VideoProfile.AutoFit = true;

            if (size.Width >= 1920 && size.Height >= 1080)
            {
                WMV_Format.VideoProfile.Size = new System.Drawing.Size(1920, 1080);
                WMV_Format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(6000);
            }
            else if (size.Width >= 1280 && size.Height >= 720)
            {
                WMV_Format.VideoProfile.Size = new System.Drawing.Size(1280, 720);
                WMV_Format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(4000);
            }
            else
            {
                WMV_Format.VideoProfile.Size = new System.Drawing.Size(size.Width, size.Height);
                WMV_Format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(2000);
            }
            mediaItem.VideoResizeMode = VideoResizeMode.Letterbox;
            mediaItem.OutputFormat = WMV_Format;
            j.MediaItems.Add(mediaItem);
            j.CreateSubfolder = false;
            j.OutputDirectory = @"D:\output";
            j.EncodeProgress += new EventHandler<EncodeProgressEventArgs>(j_EncodeProgress);
            j.Encode();
        }
    }