2

I just want to make a simple console app that can record video from webcam and save it to a filepath in the background without a GUI interface. I just want to call it from another program and have it run based on the runtime of the mother program that is calling the console app. I found this, How to capture image using webcam in console application ??? however it is capturing an image only, I would like it to capture a video. Is this possible in console app? I've only found examples using win Form. I am a complete newb. I'm uncertain what I'm doing, and only trying to copy examples so please excuse my code.

using System;
using System.Drawing;

using AForge.Video.DirectShow;
using AForge.Video;
using AForge.Video.FFMPEG;

namespace WebCamVideo
{
class Program
{
    static FilterInfoCollection WebcamColl;
    static VideoCaptureDevice Device;


    static void Main(string[] args)
    {

        WebcamColl = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        Console.WriteLine("Press Any Key To Capture Video !");
        Console.ReadKey();
        Device = new VideoCaptureDevice(WebcamColl[0].MonikerString);
        Device.NewFrame += Device_NewFrame;          
        Console.ReadLine();
    }

    static void Device_NewFrame(object sender, NewFrameEventArgs e)
    {
        int width = 320;
        int height = 240;

        VideoFileWriter FileWriter = new VideoFileWriter();
        FileWriter.Open(@"C:\Users\PCuser\desktop\test.avi", width, height, 25, VideoCodec.MPEG4, 100000);
        FileWriter.WriteVideoFrame((Bitmap)e.Frame.Clone());
        //add code to delay or set timer?
        FileWriter.Close();
        Console.WriteLine("Stopped .");

    }
}
}
Spencer Trinh
  • 743
  • 12
  • 31

0 Answers0