I’m trying to do the following: receive video stream using gstreamer and process it with opencv. I’ve found few solutions, and one of them is to write video into (from gstreamer) fifo and then read it using opencv. (OPTION3 here MJPEG streaming and decoding). The problem is I cant open pipe. cvCreateFileCapture just never returns. Here is a part code I wrote:
if(mkfifo("fifo.avi", S_IRUSR| S_IWUSR) == -1)
{
cout<<"Cant create fifo"<<endl;
cout<<errno<<endl;
}
loop = g_main_loop_new(NULL, false);
fsink = gst_element_factory_make("filesink", "fsink");
g_object_set(G_OBJECT(fsink), "location", "fifo.avi", NULL);
playbin = gst_element_factory_make("playbin2", "play");
g_object_set(G_OBJECT(playbin), "uri", uri.c_str(), NULL);
g_object_set(G_OBJECT(playbin), "video-sink", fsink, NULL);
bus = gst_pipeline_get_bus(GST_PIPELINE(playbin));
gst_bus_add_signal_watch(bus);
g_signal_connect(bus, "message::buffering", G_CALLBACK(&set_playbin_state), playbin);
gst_object_unref(bus);
cvNamedWindow("output", CV_WINDOW_AUTOSIZE);
capture = cvCreateFileCapture("fifo.avi");
The program stacks in the last line.
PS: I’m using opencv 2.3.1.
So. After searching a while, I’ve found a solution, which involves retrieving data from buffer. So the idea is to create playbin and set appsink as “video-sink”. Here is code sample:
this works.
PS. There’s a lot of info about this method, but I spent a lot of time searching for it. So I decided to post it here in order to provide at least some keywords to search.
UPDATE.
And a bit more information about connecting gstreamer and opencv. It’s about converting buffer to iplimage now.
First of all, we need to receive rgb buffer, to make conversion as easy, as possible. In order to do this we’ll replace appsinks with appsink, connected to ffmpegcolorspace
I hope this will help somebody.