目录
1. appsink元素介绍
appsink 元素作为gstreamer的sink节点,它可以实现pipeline中的流媒体数据与其他应用程序的交换,比如实现gstreamer与CUDA交互,gstreamer与OpenCV交互,等等。
主要作用是借助gstreamer pipeline的 media streaming, 我们通过appsink用一个buffer来收集流媒体的数据,提供给其他应用程序来处理使用。
2. appsink 元素结合cv::Mat保存图片
2.1 开发环境
硬件:NVIDIA jetson xavier agx
软件:Qt5.9、Opencv4.1.1、Deepstream 5.0、GStreamer-1.0
2.2 软件代码与说明
queue元素和nvvideoconvert元素创建省略,只说明保存元素的核心内容。
Qt配置opencv不在此说明。
- 创建appsink元素,并且设置其caps,此caps满足nvvideoconvert元素的src输出格式:
char caps[1024] = "video/x-raw,format=RGBA";
GstCaps *video_caps;
video_caps = gst_caps_from_string (caps);
if(!video_caps){
qCritical()<< "gst_caps_from_string fail";
return false;
}
g_object_set (m_sinkBin.sub_bins[index].sink, "caps", video_caps, NULL);
- 设置appsink元素的信号及其信号响应函数
// link signal new-sample
g_object_set(m_sinkBin.sub_bins[index].sink, "emit-signals", TRUE, "async", FALSE, NULL);
g_signal_connect(m_sinkBin.sub_bins[index].sink, "new-sample", G_CALLBACK(SinkElement::newSample), NULL);
- 在new-sample响应函数中保存当前视频帧为图片
GstSample *sample = gst_app_sink_pull_sample(appsink); //need free sample handle
caps = gst_sample_get_caps (sample);
if (!caps) {
g_print ("gst_sample_get_caps fail\n");
gst_sample_unref (sample);
return GST_FLOW_ERROR;
}
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) {

本文介绍了如何在Gstreamer pipeline中使用appsink与OpenCV配合,实现实时图片采集、转换和保存,重点展示了如何设置caps、信号处理以及cv::Mat操作的步骤。
最低0.47元/天 解锁文章
2804





