我应该如何解释gstreamer multifilesink时间戳属性?

时间:2019-04-01 20:14:21

标签: c timestamp gstreamer glib

我在C中使用multifilesink元素。multifilesink创建带有索引的文件名,但是我需要带有时间戳的文件名。方便地,在写入每个文件之后,multifilesink发送一条总线消息,并且在消息数据中,它提供了一个glib结构,其中包含文件名和时间戳。我已经设置了代码来监视消息并调用一个函数来重命名每个文件,如下所示:

“ file-01.jpg”成为“ file-DDMMYYYY_HHMMSS.sss.jpg”

每次写入文件时,我都可以成功接收消息并调用函数。

问题是我不了解时间戳的值。它似乎不是统一的纪元时间,也不是单调的,并且通常为负或零。

// My function to handle multifilesink messages
static gboolean HandleElementMessages( GstMessage *MessagePtr )
{
    const GstStructure* MessageStructurePtr;
    gboolean success = TRUE;

    MessageStructurePtr = gst_message_get_structure( MessagePtr );
    g_print( "Received an element message from an element of type \"%s\" at time %ld\n", 
        gst_structure_get_name( MessageStructurePtr ), 
        GST_MESSAGE_TIMESTAMP( MessageStructurePtr ) 
        );

    return success;
} // End of HandleElementMessages()

我希望GST_MESSAGE_TIMESTAMP()应该返回一个单调递增的值,该值与纪元或我可以理解的某个起点有关。相反,我看到这样的结果:

Received an element message from an element of type "GstMultiFileSink" at time 3282
Received an element message from an element of type "GstMultiFileSink" at time 0
Received an element message from an element of type "GstMultiFileSink" at time 2
Received an element message from an element of type "GstMultiFileSink" at time 0
Received an element message from an element of type "GstMultiFileSink" at time 0
Received an element message from an element of type "GstMultiFileSink" at time 140662536522192
Received an element message from an element of type "GstMultiFileSink" at time -3543839906708188932
...

2 个答案:

答案 0 :(得分:1)

以下是将什么结构发送到总线的代码:

  s = gst_structure_new ("GstMultiFileSink",
      "filename", G_TYPE_STRING, filename,
      "index", G_TYPE_INT, multifilesink->index,
      "timestamp", G_TYPE_UINT64, timestamp,
      "stream-time", G_TYPE_UINT64, stream_time,
      "running-time", G_TYPE_UINT64, running_time,
      "duration", G_TYPE_UINT64, duration,
      "offset", G_TYPE_UINT64, offset,
      "offset-end", G_TYPE_UINT64, offset_end, NULL);

因此,当您获得结构时,应使用某些GstStructure函数来获取您感兴趣的数据:

guint64 timestamp;

gst_structure_get_uint64(MessageStructurePtr, "timestamp", &timestamp);

答案 1 :(得分:0)

您可以使用一个函数来定期(例如,每60秒一次)对multifilesink的接收器填充探针中的(墙上时钟时间<-> gstreamer pts时间戳)进行匹配。然后,在您的“ HandleElementMessages”函数中,将方便地计算文件处理时的挂钟时间,并且可以忍受长时间。