C # Recording Screen

Source: Internet
Author: User

I have previously written two articles about recording microphone voice and camera video (recording audio and video, recording audio and video on the server side). Recently, some friends asked me, what should I do if I want to implement screen recording? In fact, the principle is similar. If you understand the content I introduced in the previous two articles, you only need to make some modifications based on them. I. Implementation principle implementation solution is still built based on OMCS + MFile. The principle is similar to the implementation of audio and video recording. Here I only list the main differences: (1) Using dynamicloud topconnector to connect to the screen desktop. (2) Call the GetCurrentImage method of dynamicloud topconnector regularly using a timer (for example, 10 FPS, once every MS) to write the obtained image to the video file using MFile. (3) Demo demonstrates that you do not need to record the microphone sound at the same time. Therefore, you only need to record video data using the SilenceVideoFileMaker component provided by MFile instead of the original VideoFileMaker component. (4) control the definition of the screen image through the DesktopEncodeQuality attribute of MultimediaManager. II. Implementation Code all the source code of the Demo is as follows. If you do not want to download the Demo, you can learn the detailed implementation ideas through the following code. Copy the public partial class Form1: Form {private MultimediaServer server; // embed the local OMCS server private IMultimediaManager multimediaManager; private SilenceVideoFileMaker maker = new SilenceVideoFileMaker (); // recording silent video private dynamicloud topconnector = new dynamicloud topconnector (); // Remote Desktop connector public Form1 () {InitializeComponent (); int port = 9900; OMCSConfiguration config = new OM CSConfiguration (10, 8, EncodingQuality. high, 16000,640,480, ""); this. server = new MultimediaServer (port, new DefaultUserVerifier (), config, false, null); this. multimediaManager = MultimediaManagerFactory. getSingleton (); this. multimediaManager. optional topencodequality = 1; // this parameter controls the definition. this. multimediaManager. initialize ("aa01", "", "127.0.0.1", port); this. dynamicloud topconnector. connectEnded + = new ESBa Sic. cbGeneric <ConnectResult> (dynamic1_topconnector_connectended); this. dynamicloud topconnector. beginConnect ("aa01"); // connect to the local desktop this. cursor = Cursors. waitCursor;} void dynamic1_topconnector_connectended (ConnectResult obj) {System. threading. thread. sleep (500); this. ready ();} private void Ready () {if (this. invokeRequired) {this. beginInvoke (new CbGeneric (this. ready);} else {this. cursor = Cur Sors. default; this. button1.Enabled = true; this. label1.Visible = false ;}} private System. threading. timer timer; private void button#click (object sender, EventArgs e) {try {Oraycn. MFile. globalUtil. setAuthorizedUser ("FreeUser", ""); // initialize the H264 video file this. maker. initialize ("test.mp4", VideoCodecType. h264, this. dynamicloud topconnector. maximum topsize. width, this. dynamicloud topconnector. maximum topsize. height, 10); this. timer = new System. threading. timer (new System. threading. timerCallback (this. call back), 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) ;}} // obtain the screen image at regular intervals and use MFile to write the video file private void Callback (object state) {Bitmap bm = this. dynamicloud topconnector. getC UrrentImage (); 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 ("video file generated successfully! ");}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.