To display the RTSP video stream (MPEG4), the existing WinForms application uses the libvlc library, which is part of the popular VLC . However, in the code of the library itself there are defects that make it difficult to use this approach in 24/7 mode. These defects in particular include: resource leaks, the accidental creation of parasitic windows and deadlocks.

As an alternative, the gstreamer library was considered, but as I understood, it is problematic to use it as part of a WinForms application.

There is also the option of using DirectDraw, but it is not yet clear how things will go with getting the stream via RTSP.

It requires advice: how (with the help of some technologies) is it more optimal, from the point of view of stability of work in the first place, to implement the functionality of displaying an RTSP video stream in a WinForms application? The complexity of implementation is secondary, but, of course, I would not like to invent a scooter, but to use ready-made high-level libraries.

    2 answers 2

    Hello, I myself recently faced a similar task and came to the option using the GStreamer framework.

    You can implement the interaction between C # WinForms and the GStreamer framework using P / Invoke . As far as I understand, you can also use C ++ / CLI , but I did not use this method, and P / Invoke is implemented faster and is more suitable for prototyping, and you can later jump down to C ++ / CLI if you need to decorate the architecture and / or make an extra layer of abstraction.

    If more, it is implemented as follows: the whole GStreamer backend is in the C ++ library, in turn, the front-end - C # WinForms application calling the GStreamer functionality from the C ++ library. The main problem that may arise is the display of the video stream in the desired window / widget / controller. Draft Solution:

    C #:

     [DllImport("gstTest.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] public extern static void play_file(StringBuilder path, IntPtr hwnd); //... void playFile(){ IntPtr hwnd = outputWidget.Handle; play_file(new StringBuilder().Append("file:///A:/test.mp4"), hwnd); } 

    C ++:

     void play_file(char* path, void* hwnd_ptr){ gst_init(NULL, NULL); HWND hwnd = (HWND)hwnd_ptr; GstElement *pipeline = gst_element_factory_make("playbin", "player"); g_object_set (G_OBJECT (pipeline), "uri", path, NULL); gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(pipeline), (guintptr)hwnd); //... } 
    • @alexolut all use of GObject types remains behind the doors of our library. What exactly do you mean by как наложить концепцию GObject ? Converting GObject types to CLR types? Then marshaling. The entire implementation of the GStreamer library itself, except for the nuance with the window handler, comes down to the development of the usual GStreamer application / library. Or are you talking about some specific things? - don-prog
    • When I looked at the option with gstreamer , I did not see gst_video_overlay_set_window_handle . Probably because I watched version 0.1 , not 1.0 . Tell me, please, what document did you use when building under windows, as well as the version of gstreamer and the compiler. - αλεχολυτ
    • @alexolut most likely, a similar function in 0.10 is: gst_x_overlay_set_window_handle () . But version 0.10 is outdated and you should use 1.0 (I think you already know this, but it is better to say). All documentation is on the official site , in particular, this , as well as the translation of several parts in Russian ... - don-prog
    • @alexolut ... Something specifically under Windows found only this (here and there is a compiler), you can also use tutorials for 0.10 on the site 0.10 , there will be more for them to start. - don-prog
    • I managed to build / run c++ test cases under vs2013 . But it is still not clear how to integrate the gstreamer message processing loop into the main (gui) WinForms thread. - αλεχολυτ

    If the RTSP stream is in mjpeg format, then you can try the Capture class from the Emgu CV.

    If the RTSP stream is transmitted in H.264 format, then the image is almost not displayed at all without lags.

    • Stream to MPEG4 (added to the question). And what kind of lags do they appear? - αλεχολυτ
    • @alexolut did not come across mpeg4. Lags - instead of the bottom of the image, either noise is displayed, or a copy of the lowest pixel layer that has been loaded - Schullz