Use C # To collect voice videos and screen desktops [based on MCapture components ],

Source: Internet
Author: User

Use C # To collect voice videos and screen desktops [based on MCapture components ],

In multimedia systems, data collection issues such as voice, video, and desktop are generally involved. The collected data can be used for transmission, playback, or storage. Therefore, multimedia data collection is one of the most basic functions for courseware recording systems, audio and video recording systems, and screen recording systems.

MCapture can be used to capture images taken by a local camera, microphone input sound, and current desktop images.

1. Introduction to MCapture

The core technologies of the MCapture component include:

(1) camera acquisition: You can specify the indexing of the camera, the resolution of the camera video, and the frame rate.

(2) microphone collection: You can specify the microphone index. The default sampling parameter is -- sampling bit: 16 bits, sampling frequency: 16000, and number of channels: 1.

(3) desktop screen collection: You can specify the frame rate, full screen collection, a rectangular area of the collection screen, and whether to display the mouse cursor.

 

Ii. MCapture Structure

The structure of main classes in the MFile component is as follows:

(1) ICameraCapturer is the camera video collection component; IMicrophoneCapturer is the microphone sound collection component; IDesktopCapturer is the screen desktop collection component. They are all integrated from the basic ICapture interface.

(2) We can call the CreateXXXX method of CapturerFactory to create a collector instance.

(3) After obtaining the collector instance, call the Start method to Start collection. Call the Stop method to Stop collection.

(4) the collected data will be exposed through the corresponding events (ImageCaptured and AudioCaptured). We can reserve these events to get the collected data.

 

Iii. Detailed Interface Definition

1. Various collector Interfaces

/// <Summary> /// basic interface of the AO Rui collector. /// </Summary> public interface ICapturer {// <summary> // This event is triggered if an error occurs during collection. /// </Summary> event CbGeneric <Exception> CaptureError; // <summary> /// start collection. /// </Summary> void Start (); /// <summary> // stop collection. /// </Summary> void Stop () ;}/// <summary> // The camera collector. /// </Summary> public interface ICameraCapturer: ICapturer {// <summary> // This event is triggered when an image is collected. /// </Summary> event CbGeneric <Bitmap> ImageCaptured;} // <summary> // desktop collector. /// </Summary> public interface IDesktopCapturer: ICapturer {// <summary> /// this event is triggered when an image is collected. /// </Summary> event CbGeneric <Bitmap> ImageCaptured;} // <summary> // microphone collector. /// </Summary> public interface IMicrophoneCapturer: ICapturer {// <summary> // This event is triggered when a frame of sound data is collected (20 ms. /// </Summary> event CbGeneric <byte []> AudioCaptured ;}

Note:

(1) The CaptureError event of the ICapture interface. When an error occurs during the collection process, this event is triggered and the collection process ends.

(2) For video and desktop collection, ImageCaptured exposes the acquired video frame (Bitmap). When the video frame is used up, call its Dispose method immediately, to release the memory it occupies (instead of waiting for GC to automatically recycle ).

 

2. Collector Factory

/// <Summary> /// collector factory. /// </Summary> public static class CapturerFactory {// <summary> // create a camera collector. /// </Summary> /// <param name = "cameraIndex"> camera index </param> /// <param name = "videoSize"> resolution of the camera </param> // <param name = "fps"> captured frame rate </param> // <returns> camera collector </returns> public static ICameraCapturer CreateCameraCapturer (int cameraIndex, size videoSize, int fps); // <summary> // create a desktop collector. /// </Summary> /// <param name = "fps"> the captured frame rate. </Param> /// <param name = "showMouseCursor"> whether the cursor is displayed in the collected image </param> /// <returns> desktop collector </returns> public static IDesktopCapturer create‑topcapturer (int fps, bool showMouseCursor); // <summary> // create a desktop collector. /// </Summary> /// <param name = "fps"> the captured frame rate. </Param> /// <param name = "showMouseCursor"> whether the cursor is displayed in the collected image </param> /// <param name = "captureRect"> Yes the area where the desktop is collected. </Param> // <returns> desktop collector </returns> public static IDesktopCapturer create‑topcapturer (int fps, bool showMouseCursor, Rectangle? CaptureRect); // <summary> // create a microphone collector (16-bit sampling number, sampling frequency: 16000, number of channels: 1 ). /// </Summary> /// <param name = "microphoneIndex"> microphone index </param> /// <returns> microphone collector </returns> public static IMicrophoneCapturer createMicrophoneCapturer (int microphoneIndex );}

 

4. MCapture Demo

Next we will use a demo to introduce how to use the MCapture component. In this demo, We will directly display the collected video data on the main form. If it is voice data, the length of the collected voice data is displayed on the page. The Demo runs as follows:

MCapture Demo source code: MCaptureDemo.rar

For recording and collecting audio videos or recording screens, you can combine MCapture with our audio and video recording component MFile to quickly implement this function.

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.