Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. fakesink vs autovideosink in gstreamer pipeline
Forum Update on Monday, May 27th 2025

fakesink vs autovideosink in gstreamer pipeline

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 494 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rtvideo
    wrote on last edited by rtvideo
    #1

    I want co change fakesink (the last part of the pipeline) to autovideosink to produce a gstreamer pop up, but when I do so I get errors which I am assuming that are related to

       g_object_get (data->sink, "last-sample", &from_sample, NULL); 
    

    and the gst_video_convert_sample. Any suggestions on how to implement autovideosink without getting errors?

    int main(int argc, char *argv[]) {
    
      CustomData data;
      GstBus *bus;
      GstMessage *msg;
      GstStateChangeReturn ret;
    
      data.terminate = FALSE;
    
      /* Initialize GStreamer */
      gst_init (&argc, &argv);
    
      /* Create the elements */
      data.pipeline = gst_parse_launch ("v4l2src device=/dev/video0 ! videoconvert ! videoscale ! "
                 "video/x-raw,framerate=30/1,width=2592,height=600 ! fakesink enable-last-sample=true name=sink ", NULL);
    
    
      data.sink = gst_bin_get_by_name( GST_BIN( data.pipeline), "sink");
    
      if (!data.pipeline) {
        g_printerr ("Not all elements could be created.\n");
        return -1;
      }
    
    /* Start playing */
      ret = gst_element_set_state (data.pipeline, GST_STATE_PLAYING);
        if (ret == GST_STATE_CHANGE_FAILURE) {
          g_printerr ("Unable to set the pipeline to the playing state.\n");
          gst_object_unref (data.pipeline);
          return -1;
        }
    
        /* Listen to the bus */
        bus = gst_element_get_bus (data.pipeline);
        do {
    
          msg = gst_bus_timed_pop_filtered (bus, 2 * GST_SECOND,(GstMessageType)(GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
          /* Parse message */
          if (msg != NULL) {
            handle_message (&data, msg);
          }else {
            g_print ("\nCapturing image\n");
            send_trigger();
    
            process a;
            a.take_pic (&data);
          }
        } while (!data.terminate);
    
        /* Free resources */
        gst_object_unref (bus);
        gst_element_set_state (data.pipeline, GST_STATE_NULL);
        gst_object_unref (data.pipeline);
        return 0;
      }
    
    static void handle_message (CustomData *data, GstMessage *msg) {
    GError *err;
    gchar *debug_info;
    
    switch (GST_MESSAGE_TYPE (msg)) {
      case GST_MESSAGE_ERROR:
        gst_message_parse_error (msg, &err, &debug_info);
        g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
        g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
        g_clear_error (&err);
        g_free (debug_info);
              data->terminate = TRUE;
              break;
            case GST_MESSAGE_EOS:
              g_print ("End-Of-Stream reached.\n");
              data->terminate = TRUE;
              break;
            case GST_MESSAGE_STATE_CHANGED:{
              GstState old_state, new_state, pending_state;
              gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);
              g_print ("%s state changed from %s to %s:\n", GST_OBJECT_NAME (GST_MESSAGE_SRC (msg)),
                   gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));
              } break;
            default:
              /* We should not reach here */
              g_printerr ("Unexpected message received.\n");
              break;
          }
          gst_message_unref (msg);
        }
    
    
    
    void process::take_pic(CustomData *data)
    {
        GstCaps *caps;
        GstSample *from_sample, *to_sample;
        GError *err = NULL;
        GstBuffer *buf;
        GstMapInfo map_info;
    
        data->terminate = TRUE;
    
        g_object_get (data->sink, "last-sample", &from_sample, NULL); 
        if (from_sample == NULL) {
    
            GST_ERROR ("Error getting last sample form sink");
            return;
        }
    
        caps = gst_caps_from_string ("image/bmp");
        to_sample = gst_video_convert_sample (from_sample, caps, GST_CLOCK_TIME_NONE, &err);
        gst_caps_unref (caps);
        gst_sample_unref (from_sample);
    
        if (to_sample == NULL && err) {
            GST_ERROR ("Error converting frame: %s", err->message);
            g_error_free (err);
            return;
        }
    
    
        buf = gst_sample_get_buffer (to_sample);
        if (gst_buffer_map (buf, &map_info, GST_MAP_READ)) {
            
            if (!g_file_set_contents (PIC_LOCATION, (const char *) map_info.data,
                                      100000, &err)) {
                GST_WARNING ("Could not save thumbnail: %s", err->message);
                g_error_free (err);
            }
        }
    
        //This line will cause error
        //gst_sample_unref (to_sample);
        gst_buffer_unmap (buf, &map_info);
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Shouldn't you rather post that on the GStreamer forum ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved