Not sure what gets wrong in your case.
The following example works fine for me. Opencv code reading nvarguscamera and sending to RTP/UDP multicast 224.1.1.1:5000:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
int main ()
{
setenv ("GST_DEBUG", "*:3", 0);
/* Setup capture with gstreamer pipeline from onboard camera converting into BGR frames for app */
const char *gst_cap =
"nvarguscamerasrc ! video/x-raw(memory:NVMM), format=(string)NV12, width=(int)640, height=(int)480, framerate=(fraction)30/1 ! "
"nvvidconv ! video/x-raw, format=(string)BGRx ! "
"videoconvert ! video/x-raw, format=(string)BGR ! "
"appsink";
cv::VideoCapture cap (gst_cap, cv::CAP_GSTREAMER);
if (!cap.isOpened ()) {
std::cout << "Failed to open camera." << std::endl;
return (-1);
}
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);
unsigned int pixels = width * height;
std::cout << " Frame size : " << width << " x " << height << ", " << pixels <<
" Pixels @" << fps << " FPS" << std::endl;
/* video writer to RTP/UDP sink multicast at 224.1.1.1 */
cv::VideoWriter gst_udpsink("appsrc ! video/x-raw, format=BGR, pixel-aspect-ratio=1/1 ! queue ! videoconvert ! video/x-raw, format=BGRx ! nvvidconv ! nvv4l2h264enc insert-vui=1 ! video/x-h264, stream-format=byte-stream, alignment=au ! h264parse ! video/x-h264, stream-format=byte-stream ! rtph264pay pt=96 config-interval=1 ! application/x-rtp, media=video, encoding-name=H264 ! udpsink host=224.1.1.1 port=5000 auto-multicast=true ", 0, fps, cv::Size (width, height));
if (!gst_udpsink.isOpened ()) {
std::cout << "Failed to open gst_udpsink writer." << std::endl;
return (-8);
}
/* Loop for 3000 frames (100s at 30 fps) */
cv::Mat frame_in, frame_out;
int frameCount = 0;
while (frameCount++ < 3000) {
if (!cap.read (frame_in)) {
std::cout << "Capture read error" << std::endl;
break;
}
else {
// Here you would make your processing
// frame_out = YourFrameProcess(frame_in);
// For this example, no processing
frame_out = frame_in;
gst_udpsink.write(frame_out);
}
}
gst_udpsink.release();
cap.release ();
return 0;
}
When running, from any host on same LAN, this works for me:
gst-launch-1.0 -v udpsrc multicast-group=224.1.1.1 auto-multicast=true port=5000 ! application/x-rtp, media=video, encoding-name=H264 ! rtpjitterbuffer ! rtph264depay ! h264parse ! avdec_h264 ! xvimagesink
And it also works from any host with VLC using a sdp file as in my previous post:
vlc test.sdp
If not working, be sure your firewall accepts incoming connection from 224.1.1.1 and to destination port 5000.
[EDIT: you may also try to increase kernel receive socket max buffer size on receiver before with:
sudo sysctl -w net.core.rmem_max=26214400
]