This project supports the sources listed below as input, it triggers an event for each frame in one of the following formats (jpg, png, bmp).
The library requires ffmpeg. You can download the ffmpeg binary here, they are needed to access the video stream. Just copy the ffmpeg.exe
into the execution directory.
The package is available on nuget
PM> install-package Nager.VideoStream
var inputSource = new StreamInputSource("rtsp://videoserver.example/testvideo.mp4");
var cancellationTokenSource = new CancellationTokenSource();
var client = new VideoStreamClient();
client.NewImageReceived += NewImageReceived;
var task = client.StartFrameReaderAsync(inputSource, OutputImageFormat.Bmp, cancellationTokenSource.Token);
//wait for exit
Console.ReadLine();
client.NewImageReceived -= NewImageReceived;
void NewImageReceived(byte[] imageData)
{
File.WriteAllBytes($@"{DateTime.Now.Ticks}.bmp", imageData);
}
You can find out the name of your webcam in the Windows Device Manager
in the section Cameras
var inputSource = new WebcamInputSource("HP HD Camera");
var cancellationTokenSource = new CancellationTokenSource();
var client = new VideoStreamClient();
client.NewImageReceived += NewImageReceived;
var task = client.StartFrameReaderAsync(inputSource, OutputImageFormat.Bmp, cancellationTokenSource.Token);
//wait for exit
Console.ReadLine();
client.NewImageReceived -= NewImageReceived;
void NewImageReceived(byte[] imageData)
{
File.WriteAllBytes($@"{DateTime.Now.Ticks}.bmp", imageData);
}
var inputSource = new CustomInputSource("-rtsp_transport tcp -i rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4 -vf transpose=dir=1");
var cancellationTokenSource = new CancellationTokenSource();
var client = new VideoStreamClient();
client.NewImageReceived += NewImageReceived;
var task = client.StartFrameReaderAsync(inputSource, OutputImageFormat.Bmp, cancellationTokenSource.Token);
//wait for exit
Console.ReadLine();
client.NewImageReceived -= NewImageReceived;
void NewImageReceived(byte[] imageData)
{
File.WriteAllBytes($@"{DateTime.Now.Ticks}.bmp", imageData);
}