TinkerTailor
TinkerTailor

Reputation: 1

Need to render YUV frame(AVFrame from ffmpeg) using QT QOpenGLWidget

I have an AVFrame from FFMPEG in YUV format. I would like to render it using qt derived class from QOpenGLWidget and QOpenGLFunctions.

I'm a beginner to qt and OpenGL.

Can someone help out with this?

Thanks Aswin

Upvotes: 0

Views: 2424

Answers (2)

Luca Carlon
Luca Carlon

Reputation: 9986

For these cases, I wrote a demo using a custom QQuickItem. YUV data is uploaded to the GPU and converted with a OpenGL shader. This is the repo with the code: https://github.com/carlonluca/qtyuv.

Upvotes: 0

MasterAler
MasterAler

Reputation: 1653

Well, actually, if you'll need to implement a really fast-rendering player, you'll have to mess with buffer optimizations, off-screen rendering, buffer streaming -- something from those. But as far as you are new with Qt, there are simple, yet working solutions:

  1. Try AV_PIX_FMT_RGBA pixel format, rendering a simple texture into some drawing surface rectangle is simple enough.
  2. When I wanted to try the same myself, found this awesome guy, who implemented full working example here.

QFFmpegGLWidget class in the link above is sufficient for you to get the idea. Converting to RGB is done via fragment shader, good old trick with 3 textures applied with GL_LUMINANCE works there.

I struggled with my own, almost similar solution, nevertheless got picture from camera (rtsp) with wrong, messed colors. So, make sure, you are getting frames in YUV420p. In case other pixel format suits you better, check these chineese resources to get it deeper (google translation makes 'em readable):

  1. YUV shader conversions
  2. YUV 2 RGB math

Good luck!

Upvotes: 4

Related Questions