Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7918247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:26:23+00:00 2026-06-03T15:26:23+00:00

I’m trying to do the following: receive video stream using gstreamer and process it

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:26:24+00:00Added an answer on June 3, 2026 at 3:26 pm

    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:

    cout<<"Creating appsink"<<endl;
    appsink = gst_element_factory_make("appsink", "asink");
    gst_app_sink_set_emit_signals((GstAppSink*)appsink, true);
    gst_app_sink_set_drop((GstAppSink*)appsink, true);
    gst_app_sink_set_max_buffers((GstAppSink*)appsink, 1);
    
    //creating and initialising pipeline
    
    g_object_set(G_OBJECT(playbin), "video-sink", appsink, NULL);
    
    g_signal_connect(appsink, "new-buffer", G_CALLBACK(DisplayFrame), (gpointer) mark);
    
    //callback function looks like this
    
    gboolean Core::DisplayFrame(GstAppSink *fks, gpointer mark)
    {
    static bool init = false;
    static IplImage *frame;
    GstBuffer* buf;
    Mark* mk = (Mark*) mark;
    
    if(!init)
    {
        init = true;
        frame = cvCreateImage(cvSize(mk->frame_w, mk->frame_h), IPL_DEPTH_8U, 1);
    }
    buf = gst_app_sink_pull_buffer(fks);
    frame->imageData = (char*)GST_BUFFER_DATA(buf);
    
    ProcessFrame(frame);
    gst_buffer_unref(buf);
    return true;
    }
    

    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

    cout<<"Creating appsink"<<endl;
    appsink = gst_element_factory_make("appsink", "asink");
    gst_app_sink_set_emit_signals((GstAppSink*)appsink, true);
    gst_app_sink_set_drop((GstAppSink*)appsink, true);
    gst_app_sink_set_max_buffers((GstAppSink*)appsink, 1);
    csp = gst_element_factory_make("ffmpegcolorspace", "csp");
    sinkpipe = gst_pipeline_new("sinkp");
    gst_bin_add_many(GST_BIN(sinkpipe), csp, appsink, NULL);
    gst_element_link_filtered(csp, appsink, gst_caps_new_simple("video/x-raw-rgb", NULL));
    pad = gst_element_get_static_pad(csp, "sink");
    gst_element_add_pad(sinkpipe, gst_ghost_pad_new("ghost", pad));
    g_object_unref(pad);
    
    //...
    
    g_object_set(G_OBJECT(playbin), "video-sink", sinkpipe, NULL);
    
    //...
    
    g_signal_connect(appsink, "new-buffer", G_CALLBACK(GetFrame), (gpointer) mark);
    
    //...
    
    //caps_struct can be retrieved via writing data probe
    //search for it in streamer manual
    
    cout<<"Getting frame resolution"<<endl;
    gst_structure_get_int(caps_struct, "width", &(mark->frame_w));
    gst_structure_get_int(caps_struct, "height", &(mark->frame_h));
    gst_structure_get_int(caps_struct, "depth", &depth);
    
    mark->GeneratePoints();
    frame = cvCreateImage(cvSize(mark->frame_w, mark->frame_h), depth/3, 3);
    
    
    //callback function
    
    gboolean Core::GetFrame(GstAppSink *fks, gpointer frame)
    {
    
    IplImage* frame_temp = frame
    IplImage* frame_temp_two = cvCloneImage(frame_temp);
    
    GstBuffer* buf;
    buf = gst_app_sink_pull_buffer(fks);
    frame_temp_two->imageData = (char*) GST_BUFFER_DATA(buf);
    cvConvertImage(frame_temp_two, frame_temp, CV_CVTIMG_SWAP_RB);
    ProcessFrame(frame_temp);
    gst_buffer_unref(buf);
    return true;
    }
    

    I hope this will help somebody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.