C++ 将帧从Gstreamer缓冲区读取到SDL_纹理

C++ 将帧从Gstreamer缓冲区读取到SDL_纹理,c++,sdl,C++,Sdl,我(尝试)使用gstreamer在SDL2中播放视频 下面是我要更新SDL_纹理的函数代码: static GstFlowReturn on_buffer (GstAppSink * sink, gpointer user_data) { GstBuffer* sample = gst_app_sink_pull_buffer(sink); GstCaps* caps = gst_buffer_get_caps (sample); if (!caps) g_print ("could

我(尝试)使用gstreamer在SDL2中播放视频

下面是我要更新SDL_纹理的函数代码:

static GstFlowReturn on_buffer (GstAppSink * sink, gpointer user_data)
{
  GstBuffer* sample = gst_app_sink_pull_buffer(sink);
  GstCaps* caps = gst_buffer_get_caps (sample);
  if (!caps) g_print ("could not get snapshot format\n");
  GstStructure* s = gst_caps_get_structure (caps, 0);
  gint width, height;
  int res = gst_structure_get_int (s, "width", &width)  | gst_structure_get_int (s, "height", &height);
  if (!res) g_print ("could not get snapshot dimension\n");
  //printf("caps struct=%s\n", gst_caps_to_string(caps));

  SDL_Rect r{0, 0, width, height};
  SDL_Texture *tex = SDL_CreateTexture(RENDER, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, width, height);

  if (SDL_UpdateTexture(tex, &r,GST_BUFFER_DATA(sample),(width*4)) == 0)
  {
      printf("ok texture update\n");
  }
  else
  {
       printf("SDL_textureupdate failed: %s\n", SDL_GetError());
  }

  if ( SDL_RenderCopyEx(RENDER, tex, NULL, &r,ROTATION,NULL,SDL_FLIP_NONE) == 0)
  {
      printf("ok rendercopy \n");
  }
  else
  {
       printf("SDL_ rendercopy failed: %s\n", SDL_GetError());
  }

  SDL_RenderPresent(RENDER);
  gst_buffer_unref(sample);
  SDL_DestroyTexture(tex);
  sleep(0.5);
  return GST_FLOW_OK;
}

我没有任何错误,但我的屏幕上没有任何内容。Gstreamer Appsink似乎正在工作,因为我播放的视频是2秒30FPS,而on_缓冲区回调被调用了60次

为什么
pitch
参数指向
SDL\u UpdateTexture()
4086而不是4096(1024*4)?为什么忽略从GStreamer查询的帧
宽度
/
高度
值?你怎么知道
GST\u BUFFER\u数据(示例)
包含平面YUV?@genpfault说它包含原始视频帧