Hi,
I’m currently trying to stream videos perform some opencv operations and republish these jpeg as rtsp streams. What I currently have figured out,
-
I can publish a stream using gstreamer’s videotestsrc and publish jpeg frames to the udp sink, and when I run gstreamer pipeline I can see the exact stream, no issues.
-
Running gstreamer pipeline on the terminal on a webcam, and publish to udp sink and view them on a separate pipeline. The command is as follows,
Sender Pipeline,gst-launch-1.0 v4l2src device=/dev/video0 ! image/jpeg,width=640,height=480,framerate=30/1 ! \ jpegparse ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000
Receiver Pipeline,
gst-launch-1.0 udpsrc port=5000 ! application/x-rtp,encoding-name=JPEG,payload=26 ! \
rtpjpegdepay ! jpegdec ! autovideosink
Right now to the issue that I face, the code is as follows,
#include <iostream>
#include <gst/rtsp-server/rtsp-server.h>
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
VideoCapture cap("videotestsrc pattern=7 ! video/x-raw,format=BGR,width=640,height=480,framerate=30/1 ! appsink",CAP_GSTREAMER);
VideoWriter out("appsrc ! autovideoconvert ! videoscale ! video/x-raw,format=I420,width=1280,height=720,framerate=30/1 ! jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5001",CAP_GSTREAMER,0,30,Size(1280,720),true);
if(!cap.isOpened() || !out.isOpened())
{
cout<<"VideoCapture or VideoWriter not opened"<<endl;
exit(-1);
}
Mat frame;
Mat resized;
while(true) {
cap.read(frame);
cv::resize(frame, resized, cv::Size(1280, 720));
if(frame.empty())
break;
out.write(frame);
// imshow( "Frame", resized);
//
// char c=(char)waitKey(25);
// if(c==27)
// break;
}
cap.release();
}
In the above code in the line where I read frames with gstreamer’s videotestsrc the pipeline works without an issue, but with mp4 it seems to be an issue. I’ll attach a sample image below for reference,
Link to the output with artifacts.
However I don’t see the issue with videotestsrc, I get the same feed. My receiver pipeline is same as above,
gst-launch-1.0 -v udpsrc port=5001 ! application/x-rtp, media=video, clock-rate=90000, encoding-name=JPEG, payload=26 ! rtpjpegdepay ! jpegdec ! xvimagesink sync=0
Please take a look and let me know if I have issues anywhere in the receiver pipeline or the way I’m writing images to the udp sink. Any help would be appreciated. Thanks.