'How to open GStreamer pipeline in OpenCV
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
Solution 1:[1]
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";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Michael Gruner |