如何在 splitmuxsink 中获取当前视频位置名称?

How to get current video location name in splitmuxsink?

我正在使用 splitmuxsink 元素根据大小保存视频,我可以使用 format-location 信号来设置要用于转储视频的下一个视频名称。

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);

如何获取 splitmuxsink 转储的当前视频名称?我认为使用 GstMessages 可能是可行的,但我不确定如何获取与特定插件相关的消息。

事实上,当我使用 DEBUG_MODE=4 时,我可以看到在 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   

我可以通过在 GstBus 上收听使用 GST_MESSAGE_ELEMENT 类型的 GstMessage 获取视频位置。当视频拆分发生时,splitmuxsink 有名称为 splitmuxsink-fragment-opened 的消息。

      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;
    }

输出

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