问题描述
我正在尝试使用Opencv VideoWriter传输h264流,以使用VideoCapture在网络上的另一台PC上获取它.但是,我被困在VideoWriter上.该代码的执行将返回错误,并且out.isOpened()始终为false.
I am trying to transfer a h264 stream using Opencv VideoWriter to get it on another pc on the network using VideoCapture. However, I am stuck on VideoWriter. Execution of this code returns with an error and out.isOpened () is always false.
int FOURCC = cv::VideoWriter::fourcc('H', '2', '6', '4');
cv::VideoWriter out;
out.open ("appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000",
cv::CAP_GSTREAMER,
FOURCC,
16,
cv::Size (640, 480),
true);
if (!out.isOpened ()) {
qDebug () << "\ n ***** Failed to open videowriter *****";
return -1;
}
[ WARN:0] global D:\Libs\opencv-4.3.0\modules\videoio\src\cap_gstreamer.cpp (1274) cv::CvVideoWriter_GStreamer::close_ OpenCV | GStreamer warning: No source in GStreamer pipeline. Ignore
[ERROR:0] global D:\Libs\opencv-4.3.0\modules\videoio\src\cap.cpp (527) cv::VideoWriter::open VIDEOIO(GSTREAMER): raised OpenCV exception:
OpenCV(4.3.0) D:\Libs\opencv-4.3.0\modules\videoio\src\cap_gstreamer.cpp:144: error: (-215:Assertion failed) ptr in function 'cv::`anonymous-namespace'::GSafePtr<struct _GstElement>::get'
***** Failed open videowriter *****
即使是一个简单的示例,也会向我返回错误,而out.isOpened()为false.
Even a simple example returns me an error and out.isOpened() false.
out.open("autovideosrc ! videoconvert ! appsink",
cv::CAP_GSTREAMER,
FOURCC,
16,
cv::Size(640, 480),
true);
[ WARN:0] global D:\Libs\opencv-4.3.0\modules\videoio\src\cap_gstreamer.cpp (1500) cv::CvVideoWriter_GStreamer::open OpenCV | GStreamer warning: OpenCV backend does not support this file type (extension): autovideosrc ! videoconvert ! appsink
[ WARN:0] global D:\Libs\opencv-4.3.0\modules\videoio\src\cap_gstreamer.cpp (1274) cv::CvVideoWriter_GStreamer::close_ OpenCV | GStreamer warning: No source in GStreamer pipeline. Ignore
***** Failed to open videowriter *****
opencv 4.3.0的版本是从具有gstreamer支持的源代码编译而来的.cv :: getBuildInformation()说:
The version of opencv 4.3.0 is compiled from source code with gstreamer support.cv::getBuildInformation () says:
Video I/O:
DC1394: NO
FFMPEG: YES (prebuilt binaries)
avcodec: YES (58.54.100)
avformat: YES (58.29.100)
avutil: YES (56.31.100)
swscale: YES (5.5.100)
avresample: YES (4.0.0)
GStreamer: YES (1.16.2)
DirectShow: YES
Media Foundation: YES
DXVA: YES
如何流式传输流?VideoWriter应该指定哪些参数?我尝试了Google的各种技巧,但没有一个对我有帮助.我将很高兴看到一个简单的示例,该示例如何从一侧的VideoWriter发送流,而从另一侧的VideoCapture接收流.我正在使用Windows 10 x64和Qt5.13 MSVC2017
How can I stream the stream? What parameters should be specified by VideoWriter? I tried various tips from google, but none of them helped me. I would be grateful for a simple example of how to send a stream from VideoWriter on one side and receive it from VideoCapture on the other.I am using Windows 10 x64 and Qt5.13 MSVC2017
推荐答案
您需要将原始视频提供给 appsrc
.将 fourcc
设置为 h264
会强制 VideoWriter
对视频进行编码,而不是对gstreamer管道进行编码.您可以将 fourcc
设置为0,以推送原始视频.以下应该起作用.
You need to feed raw video to appsrc
. Setting fourcc
to h264
forces VideoWriter
to encode video instead of gstreamer pipe. You can set your fourcc
to 0 to push raw video. The following should work.
cv::VideoWriter out;
out.open ("appsrc ! videoconvert ! x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! rtph264pay ! udpsink host=127.0.0.1 port=5000",
cv::CAP_GSTREAMER,
0,
16,
cv::Size (640, 480),
true);
这篇关于如何在GStreamer中使用Opencv VideoWriter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!