• 大小: 4.77MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-13
  • 语言: C#
  • 标签: c#录屏  c#混音  

资源简介

这个例子是基于sharpcapture开发的winform程序。提供源码。SharpCapture是一款音视频数据采集类库。它完全采用C#语言开发,基于DirectShow技术实现摄像头帧画面采集、屏幕录制、声卡采集、麦克风采集、混音等诸多强大功能为一体,且不依赖任何其他第三方组件。通过调用它,您可以快速实现摄像头画面的采集,系统屏幕的录制,采集计算机声卡以及麦克风声音,并且可以对声卡的声音和麦克风的声音进行混音。可以应用到直播、录屏、电脑录音、远程教学、视频聊天等业务场景。

资源截图

代码片段和文件信息

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using SharpCapture;
using SharpCapture.Interface;
namespace SimpleDemo
{
    public partial class Form1 : Form
    {
        #region 变量
        private int nAudioDataLen = 0;
        private ICameraCapture camera = null;
        private IScreenCapture screen = null;
        private ISoundcardCapture soundcard = null;
        private IMicrophoneCapture microphone = null;
        private IMixer mixer = null;

        //下面是wav文件生成类
        private WavHelper soundcardWav = null;
        private WavHelper microphoneWav = null;
        private WavHelper mixedWav = null;
        #endregion

        public Form1()
        {
            InitializeComponent();
        }


        #region 事件
        private void btnStart_Click(object sender EventArgs e)
        {
            try
            {
                lblStatus.Text = ““;
                if (this.comboBox1.SelectedIndex == 0)
                {
                    //摄像头采集
                    camera = CaptureFactory.GetCameraCapture(0 new Size(int.Parse(this.edtWidth.Text) int.Parse(this.edtHeight.Text))
                                    30);

                    //注册采集到帧图片的事件,在该事件函数中得到采集到的帧图片
                    camera.frameImageCaptured += new SGDelegate(CameraImageCaptured);

                    //开始采集
                    camera.Start();
                }
                else if (this.comboBox1.SelectedIndex == 1)
                {
                    //屏幕画面采集
                    screen = CaptureFactory.GetScreenCapture(20 false);

                    //注册采集到屏幕画面的事件,该事件函数中可以得到采集到的帧图片
                    screen.frameImageCaptured += new SGDelegate(ScreenImageCaptured);

                    //开始采集
                    screen.Start();
                }
                else if (this.comboBox1.SelectedIndex == 2)
                {
                    //麦克风采集,默认采集第一个麦克风
                    microphone = CaptureFactory.GetMicrophoneCapture(0);

                    //注册采集到声音数据的事件,每当采集到声音数据,就通过该事件上报
                    microphone.AudioDataCaptured += new SGDelegate(MicrophoneAudioDataCaptured);


                    //采集开始前,先初始化麦克风wav文件写入器
                    string path = Path.Combine(AppDomain.CurrentDomain.baseDirectory “microphone.wav“);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    microphoneWav = new WavHelper(path microphone.SampleRate (short)microphone.ChannelCount);


                    //开始采集
                    microphone.Start();
                }
                else if (this.comboBox1.SelectedIndex == 3)
                {
                    //声卡数据采集
                    soundcard = CaptureFactory.GetSoundcardCapture();

                    //注册采集到声音数据的事件,每当采集到声音数据,就通过该事件上报
                    sou

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-03 23:02  SharpCapture V2.3 Trial\
     目录           0  2019-04-03 23:02  SharpCapture V2.3 Trial\帮助手册\
     文件      176043  2019-04-01 19:43  SharpCapture V2.3 Trial\帮助手册\SharpCapture.chm
     目录           0  2019-04-03 23:02  SharpCapture V2.3 Trial\库\
     文件      937984  2019-04-02 23:58  SharpCapture V2.3 Trial\库\SGSupport.dll
     文件     1030144  2019-04-03 19:03  SharpCapture V2.3 Trial\库\SharpCapture.dll
     文件     1242624  2019-04-01 22:16  SharpCapture V2.3 Trial\库\SharpCapture.pdb
     文件       16034  2019-04-03 19:50  SharpCapture V2.3 Trial\库\SharpCapture.xml
     目录           0  2019-04-03 23:03  SharpCapture V2.3 Trial\示例\
     目录           0  2019-04-03 19:53  SharpCapture V2.3 Trial\示例\SimpleDemo\
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\
     文件       24064  2019-04-02 23:58  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\.suo
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\Server\
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\Server\sqlite3\
     文件           0  2019-04-02 23:29  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\Server\sqlite3\db.lock
     文件        4096  2019-04-02 23:29  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\Server\sqlite3\storage.ide
     文件       32768  2019-04-02 23:30  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\Server\sqlite3\storage.ide-shm
     文件      729272  2019-04-02 23:45  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\SimpleDemo\v15\Server\sqlite3\storage.ide-wal
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\Supercharger\
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\Supercharger\SimpleDemo\
     文件        2758  2019-04-02 23:58  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\Supercharger\SimpleDemo\codemap.dat
     文件        1131  2019-04-02 23:58  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\Supercharger\SimpleDemo\global_history.dat
     文件         214  2019-04-02 23:58  SharpCapture V2.3 Trial\示例\SimpleDemo\.vs\Supercharger\SimpleDemo\workbench.dat
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\bin\
     目录           0  2019-04-03 19:52  SharpCapture V2.3 Trial\示例\SimpleDemo\bin\Debug\
     文件      937984  2019-04-02 19:44  SharpCapture V2.3 Trial\示例\SimpleDemo\bin\Debug\SGSupport.dll
     文件      176043  2019-04-02 19:44  SharpCapture V2.3 Trial\示例\SimpleDemo\bin\Debug\SharpCapture.chm
     文件     1030144  2019-04-03 19:03  SharpCapture V2.3 Trial\示例\SimpleDemo\bin\Debug\SharpCapture.dll
     文件     1242624  2019-04-01 22:16  SharpCapture V2.3 Trial\示例\SimpleDemo\bin\Debug\SharpCapture.pdb
............此处省略23个文件信息

评论

共有 条评论