cv::Mat VideoFrameProcessing::getFrameFromGST()
{
cv::Mat _temp_frame;
int w, h;
int num, den;
GstStructure* structure;
GstMapInfo map;
current_gst.sink = gst_bin_get_by_name(GST_BIN(current_gst.pipeline), "stream");
if (!current_gst.sink)
logNeuralAndPrint("ERROR: Sink es nulo");
current_gst.appsink = GST_APP_SINK(current_gst.sink);
if (!current_gst.appsink)
{
logNeuralAndPrint("ERROR: Appsink es nulo");
gst_object_unref(current_gst.sink);
}
current_gst.sample = gst_app_sink_pull_sample(current_gst.appsink);
if (!current_gst.sample)
{
logNeuralAndPrint("ERROR: Sample es nulo");
gst_object_unref(current_gst.sink);
}
current_gst.buffer = gst_sample_get_buffer(current_gst.sample);
if (!current_gst.buffer)
{
logNeuralAndPrint("ERROR: El buffer es nulo");
gst_sample_unref(current_gst.sample);
gst_object_unref(current_gst.sink);
}
current_gst.caps = gst_sample_get_caps(current_gst.sample);
structure = gst_caps_get_structure(current_gst.caps, 0);
if(gst_structure_get_fraction(structure, "framerate", &num, &den))
current_gst.framecount = static_cast(num) / static_cast(den);
memset(&map, 0, sizeof(map));
if (gst_buffer_map(current_gst.buffer, &map, GST_MAP_READ))
{
gst_structure_get_int(structure, "width", &w);
gst_structure_get_int(structure, "height", &h);
_temp_frame = cv::Mat(h, w, CV_8UC3, (void*)map.data, w * 3).clone();
gst_buffer_unmap(current_gst.buffer, &map);
}
else
logNeuralAndPrint("ERROR: No se puede mapear el buffer");
gst_sample_unref(current_gst.sample);
gst_object_unref(current_gst.sink);
return _temp_frame;
}
< /code>
Моя проблема в том, что функция < /p>
current_gst.sample = gst_app_sink_pull_sample(current_gst.appsink);
занимает слишком много времени, чтобы выполнить (но только первый раз выступает в начале программы). Кто -нибудь знает, почему и как я могу сократить время, которое это нужно? < Br /> Для справки, некоторые другие части этого же кода занимают около 0,002 мс, в то время как эта строка занимает 5000,00 мс. < /p>
Я сделал следующий код для извлечения данных буфера из потока: < /p> [code]cv::Mat VideoFrameProcessing::getFrameFromGST() { cv::Mat _temp_frame;
int w, h; int num, den; GstStructure* structure; GstMapInfo map;
current_gst.sink = gst_bin_get_by_name(GST_BIN(current_gst.pipeline), "stream"); if (!current_gst.sink) logNeuralAndPrint("ERROR: Sink es nulo");
current_gst.appsink = GST_APP_SINK(current_gst.sink); if (!current_gst.appsink) { logNeuralAndPrint("ERROR: Appsink es nulo"); gst_object_unref(current_gst.sink); }
current_gst.sample = gst_app_sink_pull_sample(current_gst.appsink); if (!current_gst.sample) { logNeuralAndPrint("ERROR: Sample es nulo"); gst_object_unref(current_gst.sink); }
current_gst.buffer = gst_sample_get_buffer(current_gst.sample); if (!current_gst.buffer) { logNeuralAndPrint("ERROR: El buffer es nulo"); gst_sample_unref(current_gst.sample); gst_object_unref(current_gst.sink); }
_temp_frame = cv::Mat(h, w, CV_8UC3, (void*)map.data, w * 3).clone(); gst_buffer_unmap(current_gst.buffer, &map); } else logNeuralAndPrint("ERROR: No se puede mapear el buffer");
return _temp_frame; } < /code> Моя проблема в том, что функция < /p> current_gst.sample = gst_app_sink_pull_sample(current_gst.appsink); [/code] занимает слишком много времени, чтобы выполнить (но только первый раз выступает в начале программы). Кто -нибудь знает, почему и как я могу сократить время, которое это нужно? < Br /> Для справки, некоторые другие части этого же кода занимают около 0,002 мс, в то время как эта строка занимает 5000,00 мс. < /p>