GstPadProbeReturn gstcapture::cb_have_data (GstPad *pad, GstPadProbeInfo *info, ImageStruct *user_data) { if((user_data->image_flag) == 1) { user_data->image_flag =0; 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); //获取图片的高 const char *data= gst_structure_get_string(s, "format"); //获取图片的高 string format = data; g_print("format: %s", data); 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("bmp size = %ld \n", map_info.size); g_print("bmp max size = %ld \n", map_info.maxsize); g_print("bmp size = %ld \n", map_info.size); g_print("width = %d \n", width); g_print("height = %d \n", height); g_print("format = %s \n", format.c_str()); memset(map_info.data, map_info.size, 0); // for(int i= 0; i< width* height* 2; ++i) // { // g_print("pixel = %d ", map_info.data[i]); // } // unsigned char *rgb24 = new unsigned char[width * height * 3]; // NV12_T_RGB(map_info.data, rgb24, width, height); // QImage保存图片 QImage img(map_info.data, width, height, width * 3, QImage::Format_RGBA8888); if(img.save(user_data->filePath, "bmp") == true) g_print("save %s succeed\n",user_data->filePath.toStdString().c_str()); // delete rgb24; gst_buffer_unmap (buffer, &map_info); //info= GST_PAD_PROBE_INFO_DATA( buffer); } return GST_PAD_PROBE_OK; }