Congratulations to our 2022 Qt Champions!

How to create a .mp4 Video from a collection of QOpenGLFramebufferObjects /QImages / Glunit textures

  • I am developing a Qt app for iOS, Android & OSX.

    I have an std::vector of QOpenGLFramebufferObjects. Each QOpenGLFramebufferObject can of course provide its own QImage or a GLunit texture by doing a takeTexture. So you can also say that I have a collection of QImages or GLunit textures.

    I want to create a .mp4 video file out of these QImages/QOpenGLFramebufferObjects which works on iOS, Android & OSX.

    How should I do this? Any examples doing this with Qt? Which classes in Qt should I be looking into?

    I am thinking to use ffmpeg or GStreamer whatever works best in Qt. But I want to know how to pass these QImages or Glunit textures to create the video. Is there Qt support to do this without having to use a 3d party library?

    Should I use QVideoEncoderSettings to create the video?
    Are there any examples in Qt doing this?
    Which classes/components in Qt I should be looking into?

    Is there something in Qt Multimedia that I can use?
    If not then what is the best option wrt to making this work on Android & iOS?

    PS :
    I am using Qt 5.9.1 commercial version on Android & iOS

  • Lifetime Qt Champion


    Something is not clear from your description, do you want your application to record a video file on all three platforms ? Or do you want to generate video files that can be played on all these platforms ?

    If the former, what is the source of images ? Are you using widgets or QtQuick ?

  • @SGaist I want to generate video files that can be played on all 3 platforms.

    The source QImages are are some are QOpenGLFramebufferObjects which are populated after some processing using OpenGL.

    I am using Qt Quick commercial version for Android & iOS. And working on Qt 5.9.1.

    Simplistically saying, I just want to create a video file from QImages or Glunit textures whichever option works with Qt.

  • Lifetime Qt Champion

    Well, I'm sorry to say that it's still not that clear, so let me rephrase that: will your application create these video files on iOS and Android ? Or are you creating a desktop only application that should create these video files ?

    In any case, QOpenGLFramebufferObject has a toImage method that returns a QImage.

  • @SGaist Yes. My application will create these video files on iOS and Android. It is not a desktop only application. It is primarily for iOS & Android. But the application runs on MacOS as well which is my development environment.

    Yes. QOpenGLFramebufferObject has toImage method to return a QImage. I already know that. But my question starts after this.

    Rephrasing my question here again:
    Consider you have 15 QOpenGLFramebufferObjects in memory. Each one of course can return a QImage. I wan to create a video (.mp4) out of these 15 QImages. How do I do this with Qt.

    And of course, as I said I am running commercial paid version of Qt based Qt latest 5.9.1 released recently. It is a Qt quick based application.

  • Lifetime Qt Champion

    QMediaRecorder would be the starting point.

    Note that there's no system encoder for h264, it's a non free-format.

  • @SGaist How can I pass QImages into QMediaRecorder & create a video out of it?
    Is there a example or some code snippet you could point to?

    Note that I don't need audio. I just want to programmatically create a video out of multiple QImages. And, this is has nothing to do with the camera . I am not trying to get images from camera.

    Trying to see the examples of QMediaRecorder, all of them hooking on to the camera which I don't need to do with my program . Simply, I have some QImages in memory. Want to create a video from say 10 QImages.

  • Lifetime Qt Champion

    You need to create a QMediaObject that will provide the images to QMediaRecorder.

  • @SGaist said in How to create a .mp4 Video from a collection of QOpenGLFramebufferObjects /QImages / Glunit textures:


    Is there an example doing something similar? would be really helpful if you could point to an example doing something close

  • Lifetime Qt Champion

    AFAIK, no. You will have to take some inspiration from the Qt Multimedia sources.

Log in to reply