The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_UpdateTexture and NV12
yoa.gauthier


Joined: 29 Nov 2016
Posts: 3
Hi everyone,

I have a SDL_PIXELFORMAT_NV12 texture that I would like to fill with an ffmpeg AVFrame with AV_PIX_FMT_NV12 pixel format.
Passing the frame data with SDL_UpdateTexture(texture, NULL, frame->data[0], frame->linesize[0]) seems to work for the Y plane since I can see my image but mixes up UV channel, I have red and green images blinking alternatively on my screen.

Even if I have created my texture with SDL_PIXELFORMAT_NV12, have I to split my UV pixel data into different planes for SDL_UpdateTexture to process it ?

Yoann
rodebiet


Joined: 16 Jan 2017
Posts: 1
I had the same problem. I have a solution that works, but it involves a memcpy. I hope to find a zero-copy method.

You have to allocate some memory to store the Y and the UV plane together.

After the frame is finished with avcodec_receive_frame, you memcpy the Y plane to the allocated memory, and the memcpy the UV plane tot the allocated memory, right after the Y plane.
Then you do a SDL_UpdateTexture and pass the point to the allocated memory and frame->linesize[0].

That works, but again, I hate the memcpys.