如何在 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   

解决方法

我可以通过监听 GstMessage 使用 GST_MESSAGE_ELEMENT 类型的 GstBus 获取视频位置。发生视频分割时,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