1

I'm a software engineer in South Korea.

I'm trying to open webm video using GStreamer pipeline in opencv program But I can't find any solution to figure out it.

I'm using OpenCV 3.4.1 in Visual Studio 19 Community IDE.

Below is my code.

#include <opencv2/opencv.hpp>

int main()

{

std::string pipeline = "playbin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm";
std::cout << "Using pipeline: \n" << pipeline << "\n";

cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);

if (!cap.isOpened()) {
    std::cout << "Failed to open camera." << std::endl;
    return (-1);
}

cv::namedWindow("CSI Camera", cv::WINDOW_AUTOSIZE);
cv::Mat img;

std::cout << "Hit ESC to exit" << "\n";
while (true)
{
    if (!cap.read(img)) {
        std::cout << "Capture read error" << std::endl;
        break;
    }

    cv::imshow("CSI Camera", img);
    int keycode = cv::waitKey(10) & 0xff;
    if (keycode == 27) break;
}

cap.release();
cv::destroyAllWindows();
return 0;

}


It is very simple code like Tutorial. But I can't open VieoCapure cap...

Anybody have tried this project or figured out?

Best regard

SleaveArea
  • 11
  • 2

1 Answers1

0

To use a GStreamer pipeline in a cv::VideoCapture it must end in an appsink. The appsink is a GStreamer element that allows an application (in this case OpenCV) to take buffers out of the pipeline.

Modify your pipeline to look like the following:

std::string pipeline = "uridecodebin uri=https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm ! videoconvert ! video/x-raw,format=RGB ! appsink";
Michael Gruner
  • 487
  • 4
  • 7
  • Thank you for reply. I change pipeline string value to your suggested. buit have another problem like below. =========== [ WARN:0] global C:\opencv4.2.0\opencv-4.2.0\modules\videoio\src\cap_gstreamer.cpp (1759) cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module source reported: Secure connection setup failed. =========== cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline. =========== cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created. ========== how can i fix it? – SleaveArea May 09 '22 at 00:37
  • Thank you for your hint. I success play video using this pipeline "videotestsrc ! video/x-raw,format=BGR ! autovideoconvert ! appsink". but I still have problem in playing URI video... – SleaveArea May 09 '22 at 01:03
  • can you set the GST_DEBUG=2 env variable and run your OpenCV app again? That should print a hint of what the error could be – Michael Gruner May 09 '22 at 15:32