Qt with opencv and gstreamer not working
-
Hi
I am new to Qt world and am struggling with Qt - opencv - gstreamer pipeline model.
I have a .mov file and I need to send it via udp using gstreamer to receiver side. Both sender and receiver written as Qt Application. This is a small portion of one Qt project, so I need to include both sender and receiver in Qt Application.
I have gstreamer installed on my machine and on command line I am able to send and receive video file using following command.
On sender side:
gst-launch-1.0 filesrc location=path/to/.mov ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoconvert ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000
On receiver side:
gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG,payload=96 ! rtpjpegdepay ! jpegparse ! jpegdec ! videoconvert ! autovideosink
It displays video with flickering. But atleast I am able to send and receive video with flickering.But when I try to include this gstreamer pipeline in Qt application as below its not working:
On sender side:
cap = new cv::VideoCapture("path\to.mov",cv::CAP_GSTREAMER);
unsigned int width = _cap->get(cv::CAP_PROP_FRAME_WIDTH);
unsigned int height = _cap->get(cv::CAP_PROP_FRAME_HEIGHT);
unsigned int fps = _cap->get(cv::CAP_PROP_FPS);
_writer = new cv::VideoWriter("appsrc ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoconvert ! jpegenc !
rtpjpegpay ! udpsink host=127.0.0.1 port=5000",
cv::CAP_GSTREAMER,
0, // fourcc 0 to send raw video
fps, // fps
cv::Size(width, height),
true);
connect(&_timer2, SIGNAL(timeout()), this, SLOT(sendVideoStream()));
void Sender::sendVideoStream()
{
cap->read(frame);
_writer->write(frame);
}
It throws error:
[ WARN:0] global E:\opencv\4_2_with_tracker\opencv\modules\videoio\src\cap_gstreamer.cpp (1665) cv::CvVideoWriter_GStreamer::writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
On Receiver side:
Inside main:
QMediaPlayer* player =new QMediaPlayer;
player->setMedia(QUrl("gst-pipeline: udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG,payload=96 ! rtpjpegdepay ! jpegparse ! jpegdec ! videoconvert ! autovideosink"));
Its not showing anything. Further instead of autovideosink I need to use appsink and display video in HMI using qml. That part also I need to solve.
Any kind help will be highly appreciated.
I am using Qt Creator 4.13.2 - Qt 5.15.1 (MSVC 2019, 64 bit) - opencv 4.2
@SGaist -
Hi and welcome to devnet,
Since you seem to be working on Windows, did you build the QtMultimedia GStreamer backend ?
-
@SGaist Thank you for the kind reply.
I didn't knew it. So I need to build Qt with Gstreamer support.
What about the sender error
[ WARN:0] global E:\opencv\4_2_with_tracker\opencv\modules\videoio\src\cap_gstreamer.cpp (1665) cv::CvVideoWriter_GStreamer::writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline ??
Is the implementation I am using is correct? -
Not the whole of Qt, just the QtMultimedia plugin. I don't think you even need to rebuild QtMultimedia.
As for the OpenCV error, the OpenCV forum will likely be a better place to get an answer about that.
-
@ShahShaj said in Qt with opencv and gstreamer not working:
Instead of using QtMultimedia, qmlglsink will be a better option?
Worth a try indeed.