The LEADTOOLS video capture SDK contains advanced features that simplify the process of capturing video from devices and cameras. Our SDK provides developers with all the tools necessary to work with different video sources including network cameras, web cams, capture cards, TV tuners, DV cameras, and more. Once the video is captured, developers can easily convert and store the video using a variety of codecs like H.265, H.264, MJPEG, and MPEG-2. LEAD libraries provide the highest compression, speed, and playback quality of any other multimedia SDK on the market.
Working on integrating video capture into your application? Quickly start with the code below or check out Capture from Video Source to File for a full tutorial.
using System.Windows.Forms;
using Leadtools;
using Leadtools.Multimedia;
static void Main(string[] args)
{
UnlockMultimedia();
CaptureVideo();
}
static void CaptureVideo()
{
string outputFile = @"C:\LEADTOOLS21\Resources\Images\captured.avi";
CaptureCtrl capture = new CaptureCtrl(true);
int deviceCount = capture.VideoDevices.Count;
if (deviceCount < 1)
{
Console.WriteLine("No compatible devices found. Exiting.");
return;
}
Console.WriteLine("Select device by typing its number and pressing Enter:");
for (int n = 0; n < deviceCount; n++)
Console.WriteLine(n.ToString() + " : " + capture.VideoDevices[n].FriendlyName);
int deviceIndex = int.Parse(Console.ReadLine());
Console.WriteLine("Preparing to capture . .");
capture.VideoDevices.Selection = deviceIndex;
capture.TargetFile = outputFile;
capture.TargetFormat = TargetFormatType.AVI;
// select a suitable compressor
capture.VideoCompressors.MJpeg.Selected = true;
//use CaptureMode.VideoAndAudio if an audio device is also selected.
capture.StartCapture(CaptureMode.Video);
Console.WriteLine("Capturing to file. Press any key to stop capture...");
while (!Console.KeyAvailable)
{
System.Windows.Forms.Application.DoEvents();
int capMilliSeconds = (int)(1000 * capture.CaptureTime);
if (capMilliSeconds % 1000 == 0) // print a dot every second
{
Console.Write(". ");
System.Threading.Thread.Sleep(1);
}
}
capture.StopCapture();
Console.ReadKey(true);
Console.WriteLine($"\nFinished capturing {capture.CaptureTime} seconds to file {outputFile}. Press any key to continue...");
Console.ReadKey(true);
}
Try it out!
To test this for yourself, make sure to get the latest LEADTOOLS SDK code for free straight from our site if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.
Support
Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.