- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
系列文章
Gstreamer中获取帧数据的方式
gstreamer中如何使用probe(探针)获取帧数据
gstreamer拉流rtsp使用appsink获取帧数据(预览+截图)
gstreamer中如何使用fakesink获取帧数据(预览+截图)
gstreamer中tee如何实现动态连接(预览+截图+录像)
文章目录
系列文章
功能
概述
数据探针
定义
RGB类型图像格式转换
回调函数
总结
附 ubuntu20.04 qt5.14 工程链接
功能
gstreamer应用程序中提供一种能够监视和控制焊盘上的方式。分为以下几种类型:
be notified when the pad is/becomes idle and make sure the pad stays idle. This is essential to be able to implement dynamic relinking of elements without breaking the dataflow.
be notified when data, events or queries are pushed or sent on a pad. It should also be possible to inspect and modify the data.
be able to drop, pass and block on data based on the result of the callback.
be able to drop, pass data on blocking pads based on methods performed by the application thread.
概述
gst_pad_add_probe()用于将探针添加到pad。
gulong gst_pad_add_probe (GstPad *pad,
GstPadProbeType mask,
GstPadProbeCallback callback,
gpointer user_data,
GDestroyNotify destroy_data);
1
2
3
4
5
mask表示探针类型
typedef enum
{
GST_PAD_PROBE_TYPE_INVALID = 0,
/* flags to control blocking */
GST_PAD_PROBE_TYPE_IDLE = (1 << 0),
GST_PAD_PROBE_TYPE_BLOCK = (1 << 1),
/* flags to select datatypes */
GST_PAD_PROBE_TYPE_BUFFER = (1 << 4),
GST_PAD_PROBE_TYPE_BUFFER_LIST = (1 << 5),
GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM = (1 << 6),
GST_PAD_PROBE_TYPE_EVENT_UPSTREAM = (1 << 7),
GST_PAD_PROBE_TYPE_EVENT_FLUSH = (1 << 8),
GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM = (1 << 9),
GST_PAD_PROBE_TYPE_QUERY_UPSTREAM = (1 << 10),
/* flags to select scheduling mode */
GST_PAD_PROBE_TYPE_PUSH = (1 << 12),
GST_PAD_PROBE_TYPE_PULL = (1 << 13),
} GstPadProbeType;
当添加带有IDLE或BLOCK标志的探针时,该探针将成为阻塞探针。否则,探针将是DATA探针。
数据类型和调度选择器标志用于选择回调中应允许的数据类型和调度模式。
阻止标志必须与触发的探针完全匹配。
回调函数定义为:
GstPadProbeReturn (*GstPadProbeCallback) (GstPad *pad,
GstPadProbeInfo *info,
gpointer user_data);
数据探针
定义
本文主要介绍如何使用探针获取帧数据,下面开始介绍数据探针。
在整个playing状态的管道中,pad上有数据通过时,数据探针会通知你。通过 GST_PAD_PROBE_TYPE_BUFFER和/或GST_PAD_PROBE_TYPE_BUFFER_LIST以 gst_pad_add_probe ()创建这种探头。下面给出在qt应用中的例子。因为qt里的Qimage可以直接操作rgb数据,如果使用gstreamer管道过程中源数据不是rgb格式,可以使用gstreamer中的videoconvert实现转码功能。命令行形式如下
`
gst-launch-1.0 videotestsrc ! videoconvert ! video/x-raw,format=RGB ! fakevideosink
gst-launch-1.0 videotestsrc ! videoconvert ! video/x-raw,format=BGRx ! ximagesink
1
2
将probe位置设置在sink的pad 上。
代码如下`
GstElement *sink = gst_element_factory_make ("ximagesink", "videosink");
//date probe
GstPad *pad = gst_element_get_static_pad (sink, "sink");
gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
(GstPadProbeCallback) cb_have_data, NULL, NULL);
gst_object_unref (pad);
1
2
3
4
5
6
RGB类型图像格式转换
注意:linux下的ximagesink显示会强制成BGRx的格式,xvimagesink则是UYVY格式。在这两个地方插入probe需要注意格式转换。这些都不是常用的BGR或者RGB形式。那么只有自己动手,丰衣足食了。
弄清楚RGB各种格式在内存中的排序方式,自己写一个转换就行。比如BGRx转BGR或者RGB只需要将其中的x分量去掉或者改变R和G的位置就行。代码如下 :
void cvtColorGBRx2GBR(guint8 dst, guint8 src, int width, int height)
{
for (int h = 0; h < height; h++)
{
for (int w = 0, w1 = 0; w < width3; w += 3, w1 += 4)
{
dst[w] = src[w1];
dst[w + 1] = src[w1+1];
dst[w + 2] = src[w1+2];
}
dst += width3;
src += width*4;
}
return;
}
void cvtColorGBRx2RGB(guint8 dst, guint8 src, int width, int height)
{
for (int h = 0; h < height; h++)
{
for (int w = 0, w1 = 0; w < width3; w += 3, w1 += 4)
{
dst[w] = src[w1+2];
dst[w + 1] = src[w1+1];
dst[w + 2] = src[w1];
}
dst += width3;
src += width*4;
}
return;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
回调函数
static GstPadProbeReturn
cb_have_data (GstPad *pad,
GstPadProbeInfo *info,
gpointer user_data){
GstBuffer *buffer = nullptr ;
GstMapInfo map_info;
GstStructure *s;
gint width, height; //图片的尺寸
GstCaps *sink_caps =gst_pad_get_current_caps(pad);
s = gst_caps_get_structure (sink_caps, 0);
gboolean res;
res = gst_structure_get_int (s, "width", &width); //获取图片的宽
res |= gst_structure_get_int (s, "height", &height); //获取图片的高
if (!res) {
g_print ("gst_structure_get_int fail\n");
return GST_PAD_PROBE_DROP;
}
// 使用mapinfo获取图像数据
buffer = GST_PAD_PROBE_INFO_BUFFER (info); //info和buffer中的数据不能直接操作
if (!gst_buffer_map(buffer, &map_info, GST_MAP_READ)) { //映射出数据
g_print("gst_buffer_map() error!");
return GST_PAD_PROBE_DROP;
}
g_print("jpg size = %ld \n", map_info.size);
QString strFile = QString("Capture-%0.jpg").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmssz"));
unsigned char rgb [widthheight3]={0} ;
cvtColorGBRx2GBR(rgb, map_info.data, width, height);
// QImage保存图片
#if 1
QImage img(rgb, width, height, width * 3, QImage::Format_RGB888); //直接操作映射出的数据map_info
img.save(strFile, "jpeg");
#endif
//也可以使用GDK的方式保存图片
#if 0
GError error = NULL;
GdkPixbuf * pixbuf = gdk_pixbuf_new_from_data (rgb, GDK_COLORSPACE_RGB, FALSE, 8, width, height,GST_ROUND_UP_4 (width * 3), NULL, NULL); //将数据保存到GdkPixbuf
/ save the pixbuf */
gdk_pixbuf_save (pixbuf, strFile.toStdString().c_str(), "jpeg", &error, NULL); //把GdkPixbuf保存成jpeg格式
g_object_unref(pixbuf); //释放掉GdkPixbuf
#endif
g_print("save %s succese\n",strFile.toStdString().c_str());
gst_buffer_unmap (buffer, &map_info);
return GST_PAD_PROBE_OK;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
根据官方应用手册描述probe适合检测数据或者在当前probe插入的位置修改数据时使用。上面演示只是从里面拿取数据。
也可以将map出来的数据做修改后还回管道中。修改后还回数据只需要解除GstBuffe映射后将GstBuffer的内容给GstPadProbeInfo就行。代码如下:
GST_PAD_PROBE_INFO_DATA (info) = buffer;
1
总结
probe只适合内部获取数据并处理的场景使用。如需要导出大量帧数据在外部应用使用时怎么办?gstreamer则是给出了appsink用来处理。后面会介绍appsink使用方法。
附 ubuntu20.04 qt5.14 工程链接
qt+gstreamer中如何使用probe(探针)获取帧数据
————————————————
版权声明:本文为CSDN博主「此心安处是吾鄉」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_41563600/article/details/117158554
我需要您在以下方面提供帮助。近一个月来,我一直在阅读有关任务和异步的内容。 我想尝试在一个简单的 wep api 项目中实现我新获得的知识。我有以下方法,并且它们都按预期工作: public Htt
我的可执行 jar 中有一个模板文件 (.xls)。不需要在运行时我需要为这个文件创建 100 多个副本(稍后将唯一地附加)。用于获取 jar 文件中的资源 (template.xls)。我正在使用
我在查看网站的模型代码时对原型(prototype)有疑问。我知道这对 Javascript 中的继承很有用。 在这个例子中... define([], function () { "use
影响我性能的前三项操作是: 获取滚动条 获取偏移高度 Ext.getStyle 为了解释我的应用程序中发生了什么:我有一个网格,其中有一列在每个单元格中呈现网格。当我几乎对网格的内容做任何事情时,它运
我正在使用以下函数来获取 URL 参数。 function gup(name, url) { name = name.replace(/[\[]/, '\\\[').replace(/[\]]/,
我最近一直在使用 sysctl 来做很多事情,现在我使用 HW_MACHINE_ARCH 变量。我正在使用以下代码。请注意,当我尝试获取其他变量 HW_MACHINE 时,此代码可以完美运行。我还认为
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 要求提供代码的问题必须表现出对所解决问题的最低限度的理解。包括尝试过的解决方案、为什么
由于使用 main-bower-files 作为使用 Gulp 的编译任务的一部分,我无法使用 node_modules 中的 webpack 来require 模块code> dir 因为我会弄乱当
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我使用 Gridlayout 在一行中放置 4 个元素。首先,我有一个 JPanel,一切正常。对于行数变大并且我必须能够向下滚动的情况,我对其进行了一些更改。现在我的 JPanel 上添加了一个 J
由于以下原因,我想将 VolumeId 的值保存在变量中: #!/usr/bin/env python import boto3 import json import argparse import
我正在将 MSAL 版本 1.x 更新为 MSAL-browser 的 Angular 。所以我正在尝试从版本 1.x 迁移到 2.X.I 能够成功替换代码并且工作正常。但是我遇到了 acquireT
我知道有很多关于此的问题,例如 Getting daily averages with pandas和 How get monthly mean in pandas using groupby但我遇到
This is the query string that I am receiving in URL. Output url: /demo/analysis/test?startDate=Sat+
我正在尝试使用 javascript 中的以下代码访问 Geoserver 层 var gkvrtWmsSource =new ol.source.ImageWMS({ u
API 需要一个包含授权代码的 header 。这就是我到目前为止所拥有的: var fullUrl = 'https://api.ecobee.com/1/thermostat?json=\{"s
如何获取文件中的最后一个字符,如果是某个字符,则删除它而不将整个文件加载到内存中? 这就是我目前所拥有的。 using (var fileStream = new FileStream("file.t
我是这个社区的新手,想出了我的第一个问题。 我正在使用 JSP,我成功地创建了 JSP-Sites,它正在使用jsp:setParameter 和 jsp:getParameter 具有单个字符串。
在回答 StoreStore reordering happens when compiling C++ for x86 @Peter Cordes 写过 For Acquire/Release se
我有一个函数,我们将其命名为 X1,它返回变量 Y。该函数在操作 .on("focusout", X1) 中使用。如何获取变量Y?执行.on后X1的结果? 最佳答案 您可以更改 Y 的范围以使其位于函
我是一名优秀的程序员,十分优秀!