Accord .Net - WriteVideoFrame does not recognize Bitmap

18 Views Asked by At

i'm working in a windows form with .Net, i want record a video with a camera of PC, i use the Accord .NET library but when i want save a frame (Bitmap) in a WriteVideoFrame i have error of System.ArgumentException: 'the param not is valid'. I dotn understand why, if in my code, args.Frame is a Bitmap.

using Accord.Video;
using Accord.Video.DirectShow;
using Accord.Video.FFMPEG;
private void localVideoCaptureDeviceToolStripMenuItem_Click(object sender, EventArgs e)
{
    VideoCaptureDeviceForm form = new VideoCaptureDeviceForm();

    if (form.ShowDialog(this) == DialogResult.OK)
    {
        // create video source
        VideoCaptureDevice videoSource = form.VideoDevice;

        // open it
        OpenVideoSource(videoSource);
    }
}

private void OpenVideoSource(IVideoSource source)
{
    MessageBox.Show(source.ToString());
    // set busy cursor
    this.Cursor = Cursors.WaitCursor;

    // stop current video source
    CloseCurrentVideoSource();

    // start new video source
    videoSourcePlayer.VideoSource = source;
    videoSourcePlayer.Start();

    VideoCaptureDevice videoDevice = source as VideoCaptureDevice;
    Size frameSize = videoDevice.VideoCapabilities[0].FrameSize;
    frameHeight = frameSize.Height;
    frameWidth = frameSize.Width;
    this.Cursor = Cursors.Default;
}

private void videoSourcePlayer_NewFrame(object sender, NewFrameEventArgs args)
{
    DateTime now = DateTime.Now;
    Graphics g = Graphics.FromImage(args.Frame);

    if (writer != null && writer.IsOpen) // Si hay una grabación en curso y el escritor está abierto
    {
        // Escribir el fotograma actual en el archivo de video
        writer.WriteVideoFrame(args.Frame);
    }

    g.Dispose();
}

private void button1_Click(object sender, EventArgs e)
{
    // Crear una nueva instancia de VideoFileWriter
    writer = new VideoFileWriter();

    // Configurar los parámetros de escritura del archivo de video (por ejemplo, resolución, framerate, codec, etc.)
    writer.Open("ruta_del_video.mp4", frameHeight, frameWidth, 30, VideoCodec.MPEG4);

}

private void button2_Click(object sender, EventArgs e)
{
    writer.Close();

    // Liberar recursos
    writer.Dispose();
    writer = null;
}

When i select the camera, i can see the image in the panel with Graphics, but i want record a video i have problems...

camera selected

The error

Can you help me, please!

0

There are 0 best solutions below