How to write OpenCV frames into Gstreamer pipeline?

Zheng superxingzheng at gmail.com
Wed Jan 13 20:06:15 PST 2016


I want to stream video which is processed by opencv through network. I have
working codes capturing frames from gstreamer appsink using opencv's
VideoCapture with Gstreamer enabled when building opencv.
But writing opencv Mat frames into gst pipeline seems to be tricky.
Here is a piece of code to show you what I want to do. I hope some one who
has similar experiences can give me some hint. Thanks in advance!

#include <iostream>
#include <iomanip>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main(int argc, char** argv) {
	/*
	 * TODO: figure out a working pipeline.
	 */
	string test_pipe = "appsrc ! autovideosink";
	
	VideoCapture cap(0);
	if (!cap.isOpened())
		return -1;
	Mat frame;

	VideoWriter writer(test_pipe, VideoWriter::fourcc('Y', 'U', 'Y', 'V'),
30.0, Size(640, 480), true);
	if (!writer.isOpened())
		return -1;
	
	//namedWindow("test", 1);
	double t = 0.0;
	while(1) {
		t = (double)getTickCount();
		cap >> frame;

		// TODO: do some process here

		writer << frame;
		//imshow("test", frame);
		if (waitKey(1) == 27)
			break;
		t = ((double)getTickCount() - t) / getTickFrequency(); // in millisecond.
		cout << "Frame Rate = " << setw(8) << 1.0 / t << " fps" << '\r';
	}
	return 0;
}




--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/How-to-write-OpenCV-frames-into-Gstreamer-pipeline-tp4675258.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list