0
I am working on an application that should record video and audio through a webcam. I was able to make the program run only with the video, but when trying to add the audio I am getting an error. I will not publish the entire code because it is too long, I will put everything that involves this problem in a single method to reduce to the maximum.
using AForge.Video.DirectShow;
using Accord.Video.FFMPEG;
using Accord.Audio;
using Accord;
using Accord.DirectSound;
using Accord.Audio.Formats;
using Accord.Math;
private VideoFileWriter FileWriter = new VideoFileWriter();
private SaveFileDialog saveAvi;
private VideoCaptureDevice FinalVideo = null;
private Signal s;
private AudioCaptureDevice audioSource = null;
private void Main()
{
    audioSource = new AudioCaptureDevice();
    audioSource.DesiredFrameSize = 4096;
    audioSource.SampleRate = 22050;
    FinalVideo = new VideoCaptureDevice(_device[deviceindex].MonikerString);
    FinalVideo.NewFrame += new AForge.Video.NewFrameEventHandler(get_Frame);
    FinalVideo.Start();
    audioSource.NewFrame += audioSource_NewFrame;
    audioSource.Start();
    saveAvi = new SaveFileDialog();
    saveAvi.Filter = "Avi Files (*.avi)|*.avi";
    if (saveAvi.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        try
        {
            int h = video.Height;
            int w = video.Width;
            int frameRate = 25;
            int bitRate = 400000;
            int audioBitrate = 320000;
            int sampleRate = 44100;
            int channels = 1;
            //Erro aparece aqui
            FileWriter.Open(saveAvi.FileName, w, h, /*aqui vem o Accord.Math.Rational*/25, VideoCodec.MPEG4, bitRate, AudioCodec.MP3, audioBitrate, sampleRate, channels);
            //o vídeo e audio (video,s.RawData) são processados e depois adicionados ao VideoFileWriter (o processamento e a escrita no FileWriter não é feito no Load, só coloquei aqui para facilitar o entendimento)
            FileWriter.WriteVideoFrame(video);
            FileWriter.WriteAudioFrame(s.RawData);
            //depois de processados e adicionados ao FileWriter
            FileWriter.Close();
        }
        catch
        {
        }
    }
}
Error: CS0012 The "Rational" type is defined in an Assembly that is not referenced. You should add a reference to Assembly "Accord, Version=3.8.0.0, Culture=neutral, Publickeytoken=fa1a88e29555ccf7".
The Rational type is included in the Accord.Math. library I installed and referenced the library in the project but still get the error.
When trying to instantiate an Accord.Rational var, I get no errors.
Rational rational = new Rational(25);
Before trying to add the audio I was not using this overload and did not receive errors, but only records video. I used only:
FileWriter.Open(saveAvi.FileName, w, h);
Has anyone had this problem? I have checked several times and the libraries are apparently correctly installed and referenced.