Screencast SDL window

Hi all,
I’m working on an Windows application that use the SDL for rendering.
I use hardware renderer and it works well.

Now, I would like to add a feature to my application : screencasting its content.

So, first of all, I’m looking for an efficient way to get the renderer framebuffer to encode it in H264 then send it in RTMP.

I tried different solutions :

  • Using the SDL_RenderReadPixels() function.
    => it is too slow. Between 80 and 120fps on my hardware

  • Using a software renderer then get the window surface with SDL_GetWindowSurface() and display it to the screen with SDL_UpdateWindowSurface().
    => it is too slow too. Max 95fps on my hardware (The GPU usage is high with the csrss.exe and dwm.exe process)

  • Creating two renderers : one software and one hardware. Using the software one to draw my application on it. Get the window surface with SDL_GetWindowSurface() and create a texture from this surface to SDL_RenderCopy() and SDL_RenderPresent() to the hardware renderer.
    => it is too slow too. Max 70fps on my hardware

For information, with hardware renderer, I have 230fps on my hardware.

Is there another way to get the screen buffer without killing the performances ?

Thanks for your help.

SDL_RenderReadPixels() works much more faster using opengl renderer than direct3d.
It’s weird because I’m on Windows…