EmguCv stream Mat frames as RTSP pipeline

I’m doing a C# application with some image processing from RealSense camera using EmguCv and I want to stream images to RTSP pipeline to allow other (multiple) clients to view RTSP stream.

At the moment I have frames as Mat objects. I know that it’s possible to create an RTSP server using LibVlc or GStreamer but I don’t know what is the best way and how to convert Mat frames into a video streaming.
Platform: Windows 10.

In LibVlc

How can I write Mat objets to MemoryStream?
Also this constructor o LibVLC doesn’t seems to work and running RTSP server.

var ms = new MemoryStream()
var libVlc = new LibVLC("--sout-rtp-dst=rtsp://:8553/rtsp", "--sout-keep");
var media = new Media(libVlc, new StreamMediaInput(ms));
var player = new MediaPlayer(media);

I have also try to write Mat objects to VideoWriter and I can’t create VideoWriter because I don’t know which codec I have to use. I have try with MJPG, H264, XVID, DIVX … no one seems to work on my platform.

Maybe it’s possible to use GStreamer instead of LibVlc?
Do you have any example of that?
Thanks for your help.

we can’t help with EMGU at all, however, IF you want to use opencv’s VideoWriter for this, – the GStreamer backend is your only option

Thanks for your reply.
I’m using EmguCv but I supose that is so similar to OpenCv because it’s a wrapper.
Do you have an example with GsStreamer and Emgu or OpenCv? I’m not very familiar with GsStreamer.

But also I think I’m having a problem with VideoWriter because it seems never find codec in VideoWriter constructor.
It’s necessary to install some codec pack in Windows platform or something like that?
Thanks for your help.

afaik, prebuilt opencv on windows comes only with ffmpeg support, so you’d have to 1) get a dev gstreamer install on your box 2) rebuild opencv libs with gstreamer videocapture backend 3) try out with your c# wrapper

If you can explain that thing, maybe we can help. however, Emgu really isn’t just a wrapper. personally, I have no experience with C#, so I can only speculate. You should browse Emgu docs for all the ways to get at the data pointer in the Mat (e.g. ptr() method in C++).