Question

I am working on some code with the help of this tutorial and using the latest development libraries of ffmpeg and SDL. I am stuck at the point where I have to display the decoded frame (AVFrame) on the screen. I am inclined to do the above task i.e, Displaying the AVFrame on screen using the latest API of SDL 2.0 (Using Renderers and Textures alongside the usage of SDL_Window). Frankly speaking, I am not an expert in SDL_Renderer, SDL_Texture and the functions associated with them. But I am reading the documentation in the official site of SDL 2.0 and working my way through them.

Is there a way to do the following using SDL 2.0 API :

  • Convert the native frame format to a flavour of YUV and display it.

    (OR)

  • If it is possible, display the frame without having to convert it from native format.

I want to do the above using Renderers and Textures. There doesn't seem to be an easy way to work with them.

Can anyone guide me through the steps to do the above tasks?

PS : Though I have not explicitly tried it, I came across some ways to display AVFrame on the screen by converting the AVFrame format(native) to RGB. But I do not want the native frame format (which is mostly YUV) to RGB conversion, as it is computationally expensive.

Converting between formats is done by sws_scale()

Was it helpful?

Solution

Try one of SDL2's YUV pixel formats.

They have several planar and packed variants:

SDL_PIXELFORMAT_YV12: planar mode: Y + V + U (3 planes)

SDL_PIXELFORMAT_IYUV: planar mode: Y + U + V (3 planes)

SDL_PIXELFORMAT_YUY2: packed mode: Y0+U0+Y1+V0 (1 plane)

SDL_PIXELFORMAT_UYVY: packed mode: U0+Y0+V0+Y1 (1 plane)

SDL_PIXELFORMAT_YVYU: packed mode: Y0+V0+Y1+U0 (1 plane)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top