I've written two articles that record microphone voice and camera video ( for voice video recording , Voice video recording on the server side ), and recently a friend asked, what if you want to implement a feature like screen recording? In fact, the principle is similar, if you know what I have described in the previous two articles, just make some changes on their basis.
I. Principle of implementation
The implementation is still based on omcs+mfile, and the principle is similar to implementing voice video recording , where I only list the main differences:
(1) Connect to the screen desktop using Dynamicdesktopconnector.
(2) using a timer (such as 10fps, then every 100ms) timed call Dynamicdesktopconnector Getcurrentimage method, the resulting image using mfile written to the video file.
(3) Demo demo is not required to record the sound of the microphone at the same time, so using the Silencevideofilemaker components provided by Mfile (rather than the original Videofilemaker components), just record video data.
(4) control the sharpness of the screen image by Multimediamanager the Desktopencodequality property.
Two. Implementing the Code
The demo of all the source code as shown below, if you do not want to download the demo, you can directly through the following code to understand the detailed implementation ideas.
Public partial class Form1:form {private multimediaserver server;//embedded OMCS server in the local private imultimed Iamanager Multimediamanager; Private Silencevideofilemaker maker = new Silencevideofilemaker (); Record Silent video private dynamicdesktopconnector dynamicdesktopconnector = new Dynamicdesktopconnector (); Remote Desktop Connector public Form1 () {InitializeComponent (); int port = 9900; omcsconfiguration config = new Omcsconfiguration (10,8, encodingquality.high,16000,640,480, ""); This.server = new Multimediaserver (port, New Defaultuserverifier (), config, false, null); This.multimediamanager = Multimediamanagerfactory.getsingleton (); this.multimediaManager.DesktopEncodeQuality = 1; This parameter controls the sharpness this.multimediaManager.Initialize ("Aa01", "" "," 127.0.0.1 ", port); this.dynamicDesktopConnector.ConnectEnded + = new Esbasic.cbgeneric<connectresult> (dynamicdesktopconnector_connectended); This.dynamicDesktopConnector.BeginConnect ("Aa01"); Connect the local desktop this. Cursor = Cursors.waitcursor; } void dynamicdesktopconnector_connectended (Connectresult obj) {System.threading.thread.s Leep (500); This. Ready (); private void Ready () {if ' (this. invokerequired) {this. BeginInvoke (New Cbgeneric (this. Ready)); } else {this. Cursor = Cursors.Default; This.button1.Enabled = true; This.label1.Visible = false; }} private System.Threading.Timer Timer; private void Button1_Click (object sender, EventArgs e) {try {Oraycn.MFile.Gl Obalutil.setauthorizeduser ("Freeuser", "" "); Initialize H264 video file this.maker.Initialize ("Test.mp4", videocodectype.h264, this. DynamicDesktopConnector.DesktopSize.Width, This.dynamicDesktopConnector.DesktopSize.Height, 10); This.timer = new System.Threading.Timer (new System.Threading.TimerCallback (this. Callback), NULL, 0, 100); This.label1.Text = "Recording ..."; This.label1.Visible = true; this.button1.Enabled = false; This.button2.Enabled = true; } catch (Exception ee) {MessageBox.Show (EE. Message); }}//timed to get the screen image and use Mfile to write to the video file private void Callback (object state) {Bi TMap BM = This.dynamicDesktopConnector.GetCurrentImage (); This.maker.AddVideoFrame (BM); } private void Button2_Click (object sender, EventArgs e) {this.timer.Dispose (); this.button1.Enabled = false; this.button2.Enabled = false; This.label1.Visible = false; This.maker.Close (True); MessageBox.Show ("Generate Video file successfully! "); } }
Three. Demo download
2015.01.06 Now the better solution is mcapture + mfile, the audio/mic/camera/Screen capture and recording in a demo, run as follows:
2014.11.26 now recording local voice, video, screen the best solution is mcapture + mfile, rather than through the Omcs around a large circle, the corresponding demo source download : Oraycn.RecordDemo.rar .
Of course, if you are recording voice, video, and screen remotely, the best solution is OMCS + mfile.
2015.6.18 finishing all relevant demo as follows:
(sound card/mic/camera/Screen) Capture & Record Demo:winform version, WPF version.
Sound card Recording demo, Mix & Record demo, simultaneous recording (desktop + mic + sound card) demo, Mic camera recording (preview)
Record pip (Desktop + Camera + mic/sound card).
Remotely record or record a voice video screen on the server side
C # Implementation Recording screen