Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is update() fast enough for smooth animation?



  • I'm trying to play an Ffmpeg video by reading a video frame from a stream, dumping it into a QImage buffer and then using a component I've created to draw the image onscreen. My widget is passed the QImage I want to draw and then update() is called to redraw it.

    While this works, it leads to a choppy animation. I was wondering if this is due to the Qt UI pipeline I've created being not very efficient, or if the problem may lie elsewhere. Is there a more efficient way to draw a stream of images to a widget?


  • Lifetime Qt Champion

    Hi,

    Indeed that's not optimal. Are you using ffmpeg to read that video file ?



  • @SGaist Yes, I'm using the ffmpeg 3rd party library.


  • Lifetime Qt Champion

    In that case, you should rather implement a QtMultimedia backend to integrate with its pipeline.

    Otherwise, VLC could be a good alternative as they provide Qt integration and also use ffmpeg IIRC.


  • Lifetime Qt Champion

    @kitfox why not using a dedicated media player?



  • Unfortunately, QtMultimedia does not work with Windows. Also, I'm doing this as prep for a more complex project where I can splice together several videos, so I need more control than QtMultimedia gives me.

    I've been thinking using OpenGL might solve my problem if waiting for the UI update is what is causing the pausing.



  • @kitfox I did something similar using FFMS2 to get decoded frames from video files, and https://doc.qt.io/qt-5/qopengltextureblitter.html to draw to a QOpenGLWidget. It's theoretically less efficient than if I was doing decode on the GPU and keeping the decoded frames from ever touching CPU memory, but it didn't cause me any performance issues. Just be very careful with how many times you copy the pixel data between the decoder and the screen -- that's the easiest/most-obvious place to waste a tone of CPU time for no reason.


Log in to reply