Search code examples
c++cgstreamergstreamer-1.0

How to get current video location name in splitmuxsink?


I'm using splitmuxsink element to save videos based on size, I can use format-location signal to set the next video name to be used for dumping video.

static gchararray
format_location_callback (GstElement * splitmux,
                          guint fragment_id,
                          gpointer udata)
{
  static int i =0;
  gchararray myarray = g_strdup_printf("myvid%d.mp4", i);
  i += 1;

  return myarray;
}

# add a callback signal
g_signal_connect (G_OBJECT (bin->sink), "format-location",
          G_CALLBACK (format_location_callback), bin);

How do I get the current video name that's being dumped by the splitmuxsink? I think that might be possible using the GstMessages, but I'm not sure how to get the message related to particular plugin.

In fact, when I use the DEBUG_MODE=4, I can see the message that video name changed when the video split happens in splitmuxsink.

0:00:06.238114046 31488 0x55928d253d90 INFO            splitmuxsink gstsplitmuxsink.c:2389:set_next_filename:<sink_sub_bin_sink1> Setting file to myvid0.mp4
0:00:06.238149341 31488 0x55928d253d90 INFO                filesink gstfilesink.c:294:gst_file_sink_set_location:<sink> filename : myvid0.mp4
0:00:06.238160223 31488 0x55928d253d90 INFO                filesink gstfilesink.c:295:gst_file_sink_set_location:<sink> uri   

Solution

  • I'm able to get video location using GstMessage of type GST_MESSAGE_ELEMENT by listening on the GstBus. The splitmuxsink has message with name splitmuxsink-fragment-opened when video split takes place.

          const gchar * location;
          const GstStructure* s = gst_message_get_structure(message);
          if (gst_structure_has_name(s, "splitmuxsink-fragment-opened"))
          {
            g_message ("get message: %s",
                  gst_structure_to_string (gst_message_get_structure(message)));
            location = gst_structure_get_string(s, "location");
            cout << location << endl;
          }
    
          break;
        }
    

    Output

    ** Message: 12:00:27.618: get message: splitmuxsink-fragment-opened, location=(string)myvid0.mp4, running-time=(guint64)1199530439;
    myvid0.mp4