从Gstreamer缓冲区读取帧到SDL_Texture

时间:2014-03-05 15:43:40

标签: c++ sdl

我(尝试)使用gstreamer在SDL 2中播放视频。

以下是我想要更新SDL_Texture的函数代码:

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_buffer回调被调用了60次。

0 个答案:

没有答案