Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QVideoSink doesn't handle alpha channel
Forum Updated to NodeBB v4.3 + New Features

QVideoSink doesn't handle alpha channel

Scheduled Pinned Locked Moved Unsolved Qt 6
10 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheEnigmist
    wrote on last edited by
    #1

    I've a WebM (VP9) video with alpha channel on it. I can open correctly the video on OBS and it shows as intended, but if I try to use it in QVideoSink using videoFrameChanged to show video frame by frame it shows a black background instead of transparent. I'm using Qt 6.3.0 RC

    Here ffmpeg file info :
    00bd09c1-be28-4da9-afa3-a8333973c833-image.png

    PixelFormat of each QVideoFrame is Format_BGRA8888 , when converted to QImage becomes Format_ARGB32_Premultiplied , all of them has an alpha channel so why my video show transparency as a black pixel?

    EDIT: If I check alpha channel with hasAlpha() on frame.image() is true, QPixmap::fromImage(frame.image) returns false!

    connect(videoSink, &QVideoSink::videoFrameChanged, [=](const QVideoFrame& frame) {
    		qDebug() << QPixmap::fromImage(frame.toImage()).hasAlpha(); //FALSE
    		qDebug() << frame.toImage().hasAlphaChannel(); // TRUE
    		videoLabel->setPixmap(QPixmap::fromImage(frame.toImage()));
    	});
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      On which do you see this result ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        On which do you see this result ?

        T Offline
        T Offline
        TheEnigmist
        wrote on last edited by
        #3

        @SGaist Hi,
        Actually I'm showing that image on videoLabel wich is a QLabel . I'm using this method since I want to manipulate video with OpenCV or do some image transformation, so my first step is to split video frame by frame

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why not use OpenCV to read the video stream directly ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          0
          • SGaistS SGaist

            Why not use OpenCV to read the video stream directly ?

            T Offline
            T Offline
            TheEnigmist
            wrote on last edited by
            #5

            @SGaist Well because that would be a future work, but maybe it is more simple to start directly with OpenCV than try to do the same first with native Qt code and then add OpenCV to it. I will build OpenCV and try to use it.
            How can I set the output of OpenCV frames in my QLabel?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Convert the cv::Mat to a QImage.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 1 Reply Last reply
              0
              • SGaistS SGaist

                Convert the cv::Mat to a QImage.

                T Offline
                T Offline
                TheEnigmist
                wrote on last edited by
                #7

                @SGaist I figured out how to show an image with alpha correctly. But I still cannot show a video/gif with alpha. I'm able to load it without problem in Qt but not with opencv. The only problem with Qt is a video with alpha (webm) that it shown with a background instead of transparency.
                While learning how use properly opencv, how can I show videos with alpha channel in Qt?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  From a cursorary look, I think the frame is rendered on a black background in the backend code. You would have to modify this code to achieve what you want.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  T 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    From a cursorary look, I think the frame is rendered on a black background in the backend code. You would have to modify this code to achieve what you want.

                    T Offline
                    T Offline
                    TheEnigmist
                    wrote on last edited by
                    #9

                    @SGaist well I think I cannot edit Qt backend source code...
                    In OpenCV i've a similar problem with video opened in RGB instead of RGBA

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Sure you can. You can clone the QtMultimedia sources.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved