Read frame from Gstreamer buffer to SDL_Texture

Hi Everyone,

I would like to have help from You. I (try to) use gstreamer to play video in SDL 2. Here is the code of my function where I want to update SDL_Texture:

Code:

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, 1024, 768};
SDL_Texture *tex = SDL_CreateTexture(RENDER, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, 1024, 768);

if (SDL_UpdateTexture(tex, &r,GST_BUFFER_DATA(sample),4086) == 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;
}

I don’t have any error, but there is nothing in my screen. The Gstreamer Appsink seems to be working, because the video what I play is 2 seconds 30FPS and the on_buffer callback is being called 60 times. Looking forward to your answers kj192