首页 > 解决方案 > gstreamer 的 appsink 元素可以返回原始 rtp 时间戳吗?

问题描述

我正在使用 gstreamer 从 IP 摄像机中提取 rtsp 流。目前,我正在使用 appsink 从流中获取帧数据,但我还需要与每个帧关联的原始 RTP 时间戳。是否可以获取 rtp 时间戳?在示例中,我使用 GST_BUFFER_TIMESTAMP 宏来获取时间戳,但我认为它不是原始 rtp 时间戳。

#include <gst/gst.h>
#include <gst/app/app.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
  gst_init (&argc, &argv);

  auto pipeline = gst_parse_launch(
      "rtspsrc location=rtsp://10.0.0.171:554/h264/video.sdp name=rtspsrc latency=100 ! queue !     rtpbin buffer-mode=none ! rtph264depay ! h264parse ! appsink name=appsink",
      nullptr);

  auto rtspsrc = gst_bin_get_by_name((GstBin*)pipeline, "rtspsrc");
  if(rtspsrc) {
      g_object_set(rtspsrc, "user-id", "user", nullptr);
      g_object_set(rtspsrc, "user-pw", "password", nullptr);
  }

  auto appsink = (GstAppSink*)gst_bin_get_by_name((GstBin*)pipeline, "appsink");

  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  while(true)
  {
      auto sample = gst_app_sink_pull_sample(appsink);

      if(sample)
      {
          auto buffer = gst_sample_get_buffer(sample);

          GstClockTime timestamp = GST_BUFFER_TIMESTAMP(buffer);

          if(buffer)
          {
              GstMapInfo info;
              gst_buffer_map(buffer, &info, GST_MAP_READ);
              printf("{%lu, %p, %ld}\n",timestamp,info.data,info.size);
          }
      }
      printf(".");
      fflush(stdout);
  }

  auto bus = gst_element_get_bus(pipeline);
  auto msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR     | GST_MESSAGE_EOS));

  if (msg != NULL)
      gst_message_unref(msg);

  gst_object_unref(bus);

  gst_element_set_state(pipeline, GST_STATE_NULL);

  gst_object_unref(pipeline);

  return 0;
}

标签: videogstreamer

解决方案


推荐阅读