using Windows Media Encoder to record screen

試著忘記壹切 提交于 2020-01-13 06:59:19

问题


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?

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

thanks! George


回答1:


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.




回答2:


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

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




回答3:


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

The one I use is: 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.

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

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.

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.

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.




回答4:


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.




回答5:


Yes, that is totally doable with 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.

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.




回答6:


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.

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();
        }
    }


来源:https://stackoverflow.com/questions/810994/using-windows-media-encoder-to-record-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!