如何通过gstreamer获取视频流的宽度/高度?

问题描述 投票:0回答:3

如何通过gstreamer获取视频流的宽度/高度?我有一个用C ++编写的管道,结构如下:

rtspsrc -> rtpjitterbuffer -> rtph264depay -> mpegtsmux -> filesink

我的任务是:当我得到第一个图像数据(h264编码或mjpeg)时,我需要从中查询宽度和高度。可能吗?我试图从rtph264depay的'src'垫获取当前的上限并从其结构中获得宽度/高度,但未能做到最后一次。

谢谢!

gstreamer
3个回答
0
投票

您可以使用typefind元素,该元素用于查找流的媒体类型并从中获取大写字母。

希望有所帮助!


0
投票

你使用的是0.10吗?它已经陈旧,过时且无人值守多年。请移至1.0。

也就是说,在0.10中,您可以在元素的填充中注册notify:caps信号的回调。所以你可以在h264depay中做到这一点并检查它是否有宽度/高度字段。如果没有,你可以添加一个h264parse,它应该可以找到你的宽度和高度,你可以在它的源垫中使用notify:caps。

在1.0中它应该工作相同,但在pad上使用事件探测器并查找CAPS事件。


0
投票

我对RTP H264流有相同的任务。用C ++编码。

我将为未来的开发人员提供一个简短的代码片段。

我的烟斗看起来像这样。

auto source = gst_element_factory_make("udpsrc", nullptr);
auto rtpJitterBuffer = gst_element_factory_make("rtpjitterbuffer", nullptr);
auto depay = gst_element_factory_make("rtph264depay", nullptr);
auto h264parse = gst_element_factory_make("h264parse", nullptr);
auto decode = gst_element_factory_make("openh264dec", nullptr);
auto sinkV = gst_element_factory_make("glimagesink", nullptr);

我用了一个探针垫来解码。因此你需要一个

GstPadProbeCallback

喜欢

static GstPadProbeReturn pad_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data) {

    GstEvent *event = GST_PAD_PROBE_INFO_EVENT(info);
    if (GST_EVENT_CAPS == GST_EVENT_TYPE(event)) {
      GstCaps * caps = gst_caps_new_any();
      int width, height;
      gst_event_parse_caps(event, &caps);

      GstStructure *s = gst_caps_get_structure(caps, 0);

      gboolean res;
      res = gst_structure_get_int (s, "width", &width);
      res |= gst_structure_get_int (s, "height", &height);
      if (!res) {
          qWarning() << "no dimenions";
      }
      qDebug() << "GST_EVENT_CAPS" << width << height;
   }
   return GST_PAD_PROBE_OK;
}

您可以将探头添加到您的打击垫中

auto *pad = gst_element_get_static_pad(decode, "src");

gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_EVENT_BOTH, pad_cb, &customData_, nullptr);
gst_object_unref(pad);

每次格式更改时都会调用此回调。你不需要检查两个方向,但我还是做了。

© www.soinside.com 2019 - 2024. All rights reserved.