Nager.VideoStream Save

Get images from a network camera stream or webcam

Project README

Nager.VideoStream

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).

  • Network Camera Stream (e.x. RTSP)
  • Webcam
  • Video File

Requirements

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.

How can I use it?

The package is available on nuget

PM> install-package Nager.VideoStream

Examples of use

Network Camera (RTSP Stream)

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);
}

Webcam

You can find out the name of your webcam in the Windows Device Manager in the section Cameras
Windows Device Manager

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);
}

Custom Input Source - Select manual attributes

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);
}
Open Source Agenda is not affiliated with "Nager.VideoStream" Project. README Source: nager/Nager.VideoStream

Open Source Agenda Badge

Open Source Agenda Rating