OpenCV 中的 GStreamer API:autovideosink 与 appsink
GStreamer API in OpenCV: autovideosink vs appsink
当我在终端上 运行 以下 Gstreamer Receiver 命令工作正常。
gst-launch-1.0 -v udpsrc port=5004 !
'application/x-rtp,payload=96,encoding-name=H264' ! rtpjitterbuffer
mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert !
autovideosink
我需要捕获这些帧并使用 OpenCV 的 Gstreamer 进行一些处理 API。我在我的 C++ 代码中使用了确切的管道,但 VideoCapture 无法启动。代码如下:
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main()
{
VideoCapture cap("udpsrc port=5004 ! application/x-rtp,payload=96,encoding-name=H264 ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! autovideosink", CAP_GSTREAMER);
if (!cap.isOpened()) {
cerr <<"VideoCapture not opened"<<endl;
exit(-1);
}
while (true) {
Mat frame;
cap.read(frame);
imshow("receiver", frame);
// Process the frame.
if (waitKey(1) == 27) {
break;
}
}
return 0;
}
当我尝试编译时 运行 我收到:
(Receiver_Teal:2292): GStreamer-CRITICAL **: gst_element_get_state:
assertion 'GST_IS_ELEMENT (element)' failed
VideoCapture not opened
尝试将末尾的 autovideosink
替换为 appsink
VideoCapture cap("udpsrc port=5004 ! application/x-rtp,payload=96,encoding-name=H264 ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! appsink", CAP_GSTREAMER);
当我在终端上 运行 以下 Gstreamer Receiver 命令工作正常。
gst-launch-1.0 -v udpsrc port=5004 ! 'application/x-rtp,payload=96,encoding-name=H264' ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! autovideosink
我需要捕获这些帧并使用 OpenCV 的 Gstreamer 进行一些处理 API。我在我的 C++ 代码中使用了确切的管道,但 VideoCapture 无法启动。代码如下:
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;
#include <iostream>
using namespace std;
int main()
{
VideoCapture cap("udpsrc port=5004 ! application/x-rtp,payload=96,encoding-name=H264 ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! autovideosink", CAP_GSTREAMER);
if (!cap.isOpened()) {
cerr <<"VideoCapture not opened"<<endl;
exit(-1);
}
while (true) {
Mat frame;
cap.read(frame);
imshow("receiver", frame);
// Process the frame.
if (waitKey(1) == 27) {
break;
}
}
return 0;
}
当我尝试编译时 运行 我收到:
(Receiver_Teal:2292): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
VideoCapture not opened
尝试将末尾的 autovideosink
替换为 appsink
VideoCapture cap("udpsrc port=5004 ! application/x-rtp,payload=96,encoding-name=H264 ! rtpjitterbuffer mode=1 ! rtph264depay ! h264parse ! decodebin ! videoconvert ! appsink", CAP_GSTREAMER);