How to Record HD video from WebCam with Sound in C# Desktop App (WPF or Winform)?

5.6k Views Asked by At

I am making a Lecture Recording app and I need to Record High Definition Video from HD WebCam. Initially I used Microsoft Expression Encoder to Record the Video. It works fine for low resolutions but it lags on 720p and above. As for Aforge Library it only deals with the Video but I need to record audio too.

I have tried but Ozeki Camera SDK but I am unable to customize the resolution and framerate etc. and using other microphone doesnt sync the audio and video too.

I hope if anyone can help me with my problem either making Expression Encoder work fine with higher resolution or suggesting some other SDK or dll to use which gives encoding capabilities as well as configuring resolution, framerate and bitrate etc of audio and video.

P.S I dont have much knowledge about Encoding etc Thanks.

1

There are 1 best solutions below

4
Pepernoot On

I myself used AForge.NET framework I know It doesn't support audio. So for that I used NAudio. You can you can easily install them with NuGet package manager Console.

Aforge Install-Package AForge

NAudio Install-Package NAudio

Here are some code snippets for audio capture

private void LifeChattingManagerForm_Load(object sender, EventArgs e)
        {
            if (!AudioCapture.Initalized)
            {
                AudioCapture.Initalize();
                AudioCapture.StartCapturing();
            }

            AudioCapture.DataAvailable += AudioEvent;
            AudioPlayer.DisposeInput = false;
            AudioPlayer.Run();
        }

        private void AudioEvent(byte[] buffer)
        {
            if (!Calling) return;
            var audioPackage = new SAudioPackage(buffer);
            HandleClient.Send(audioPackage);
        }

Audio player

AudioPlayer.AddSamples(package);


internal class AudioPlayer
{
    private static readonly BufferedWaveProvider WaveProvider = new BufferedWaveProvider(new WaveFormat());
    private static DirectSoundOut _waveOut;

    public static void AddSamples(byte[] buffer)
    {
        WaveProvider.AddSamples(buffer, 0, buffer.Length);
    }

    public static void Run()
    {
        _waveOut = new DirectSoundOut();
        _waveOut.Init(WaveProvider);
        _waveOut.Play();
    }
}

if you have any questions please let me know in the comment