video - 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;
}
解决方案
推荐阅读
- r - 写入 Excel 工作表时,如何在每次运行脚本时添加新行?
- r - N 个最近值的汇总
- postgresql - 如何使用 Ecto 在 Postgres 表上获得排他锁?
- c - 使用 Cabal 从 C 调用 Haskell
- google-apps-script - 应用程序脚本 - 通过 Google 表单填充 Google 文档模板并通过电子邮件以 pdf 格式发送
- c++ - C++ 中的 .NET async-await 之类的延续风格调用?
- python - _tkinter.TclError:图像“pyimage”不存在
- r - 如何根据特定要求分隔字符串
- c# - 为什么不能从 EntityLayer.SomeClass 转换为 DataLayer.SomeTable?
- java - NullPointerException 在 @Produces 方法中获取 bean 类名