Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105169

videoFrame.toImage() does not work in a different thread than the video rendering thread

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.4
    • 6.4
    • Multimedia
    • None
    • All

    Description

      Video frame converter invoked by frame.toImage() crashes when working with video frame textures on a different thread than the thread rendering pictures from QVideoOutput.

      Example app

      #include <QApplication>
      #include <QMediaPlayer>
      #include <QVideoFrame>
      #include <QVideoWidget>
      #include <QVideoSink>
      #include <QWindow>
      #include <QThread>
      #include <QTimer>
      #include <QLabel>
      #include <QPixmap>
      
      class SecondThread : public QThread
      {
          Q_OBJECT
      
      public slots:
          void convertFrame(const QVideoFrame &frame) 
          {
            emit newImage(frame.toImage()); 
          }
      signals:
          void newImage(const QImage &img);
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);    
          QLabel label;
          label.show();
          QVideoWidget widget;
          widget.show();
          QMediaPlayer player;
          player.setVideoOutput(&widget);
          QTimer::singleShot(500, [&](){
            player.setSource(QUrl("somemovie.mp4"));
            player.play();
          });    
      
          SecondThread t2;
          t2.start();
          t2.moveToThread(&t2);
          QObject::connect(widget.videoSink(), &QVideoSink::videoFrameChanged, &t2, &SecondThread::convertFrame);
          QObject::connect(&t2, &SecondThread::newImage, &a, [&](const QImage &img){
              label.setPixmap(QPixmap::fromImage(img));
          });
           return a.exec();
      }
      
      #include "main.moc"
      
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              artemiy Artem Dyomin
              piotr Piotr Srebrny (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: