Search code examples
visual-studioopencvgstreamerrtspvcpkg

Gstreamer binaries not included in build output directory when application built with vcpkg


I'm using Visual Studio 2022 with VCPKG to build a simple test program that opens a OpenCV VideoCapture object with a gstreamer pipeline to a RTSP feed.

#include <iostream>
#include <opencv2/opencv.hpp>

int main()
{
    auto path = "rtspsrc location=rtsp://username:[email protected] ! rtph264depay ! h264parse ! nvh264dec ! videoconvert ! appsink";
    auto cap = new cv::VideoCapture(path, cv::CAP_GSTREAMER);
    std::cout << "Hello World!\n";
}

This is my vcpkg manifest

{
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
  "name": "opencvtest",
  "version": "0.0.1",
    "dependencies": [
        {
            "name": "opencv",
            "default-features": true,
            "features": [ "gstreamer" ]
        },
        {
            "name": "gstreamer",
            "default-features": true,
            "features": [ "plugins-good","plugins-base","plugins-ugly","x264" ]
        }
    ]
}

I can build the program just fine but when run, it complains about not finding the rtspsrc element.

[ WARN:[email protected]] global H:\vcpkg\buildtrees\opencv4\src\4.5.5-923325adf5.clean\modules\videoio\src\cap_gstreamer.cpp (1127) cv::GStreamerCapture::open OpenCV | GStreamer warning: Error opening bin: no element "rtspsrc"
[ WARN:[email protected]] global H:\vcpkg\buildtrees\opencv4\src\4.5.5-923325adf5.clean\modules\videoio\src\cap_gstreamer.cpp (862) cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

This seems reasonable since the build output directory doesn't seem to have all the seemingly necessary gstreamer dll's present, such as gstrtsp*.dll.

How can I get vcpkg to include all the necessary gstreamer dlls into my build output directory? What is the correct way to use OpenCV/gstreamer with vcpkg?


Solution

  • The vcpkg port of gstreamer does not build the rtsp plugin (which includes the rtspsrc element) by default. You will need to edit the portfile.cmake.

    Doing this in a production environment requires you to create your own vcpkg repository, where you can adjust the portfile.cmake and thus the build options how ever you want.

    If this is something you will need to do I can describe this in more detail.

    Short version: add -Dgst-plugins-good:rtsp=enabled to the vcpkg_configure_meson build step described in the portfile.cmake of gstreamer.