Skip to content

nager/Nager.VideoStream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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