Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to get QImage from QVideoSink in Android ?
Forum Updated to NodeBB v4.3 + New Features

How to get QImage from QVideoSink in Android ?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 2 Posters 105 Views 2 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.
  • S Offline
    S Offline
    squareroot13
    wrote last edited by
    #1

    Hello, i made the code, which works perfectly in Windows, but doesn't work in Android. I need an advice how to get QImage as preview image in QMediaPlayer.
    My code is below:

                    pplayer->stop();
                    pplayer->setSource(url);
                    int attempts = 25;
                    bool isBroken = (pplayer->mediaStatus() == QMediaPlayer::LoadedMedia) &&
                                    (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                    while(isBroken && pplayer) {
                        QThread::msleep(20);
                        if (!attempts)
                            break;
                        attempts--;
                        isBroken = (pplayer->mediaStatus() == QMediaPlayer::LoadedMedia) &&
                                    (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                    }
                    if (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia) {
                        qWarning() << "No preview for:" << abspath << " QMediaPlayer::InvalidMedia";
                        break;
                    }
                    m_alreadyFrame = false;
                    qWarning() << "before wait:";
                    pplayer->pause();
                    QCoreApplication::processEvents();
                    QThread::msleep(10);
                    attempts = 20;
                    isBroken = (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                    while (!m_alreadyFrame && !isBroken && attempts) {
                        QCoreApplication::processEvents();
                        QThread::msleep(10);
                        isBroken = (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                        attempts--;
                    }
                    qWarning() << "after wait:";
                    QCoreApplication::processEvents();
                    if (m_alreadyFrame) {
                        frame = psink->videoFrame();
                        frame.map(QVideoFrame::ReadOnly);
                        image = frame.toImage().copy();
                        qWarning() << "format:" << image.format();
                        frame.unmap();
                        if (image.format() == QImage::Format_Invalid) {
                            qWarning() << "QImage::Format_Invalid";
                            isBroken = true;
                        }
                    }
                    pplayer->stop();
                    m_alreadyFrame = false;
                    if (isBroken || !attempts) {
                        qWarning() << "No preview for:" << abspath ;
                        qWarning() << "attempts:" << attempts << " isBroken:" << isBroken;
                        break;
                    }
                    //setState(TPrevStates::eIdle);
                    //break;
                    QString key = fileName;
                    qWarning() << "key is:" << key << " width is:" << image.width();
    
        connect(psink.get(), &QVideoSink::videoFrameChanged, this,
                             [&](const QVideoFrame & _frame){
                    if (!_frame.isValid()) {
                        qWarning() << "frame is not valid";
                        return;
                    }
                    m_alreadyFrame = true;
        });
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Which version of Qt are you using ?

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

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt are you using ?

        S Offline
        S Offline
        squareroot13
        wrote last edited by
        #3

        @SGaist 6.9.0

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

          You are not checking that the mapping is successful. That would be a first step to identify the issue.
          Also, which version of Android are you using ?
          What kind of video are you playing ?

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

          S 2 Replies Last reply
          0
          • SGaistS SGaist

            You are not checking that the mapping is successful. That would be a first step to identify the issue.
            Also, which version of Android are you using ?
            What kind of video are you playing ?

            S Offline
            S Offline
            squareroot13
            wrote last edited by squareroot13
            #5

            @SGaist Android 11. mp4 file and h264 codec - most popular case

            1 Reply Last reply
            0
            • SGaistS SGaist

              You are not checking that the mapping is successful. That would be a first step to identify the issue.
              Also, which version of Android are you using ?
              What kind of video are you playing ?

              S Offline
              S Offline
              squareroot13
              wrote last edited by squareroot13
              #6

              @SGaist I did a map check. result is false. (for android only)
              Where i'm wrong ?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                squareroot13
                wrote last edited by
                #7

                I have changed my code in order it was more correct.

                                pplayer->stop();
                                pplayer->setSource(url);
                                int attempts = 25;
                                bool isBroken = (pplayer->mediaStatus() == QMediaPlayer::LoadedMedia) &&
                                                (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                                while(isBroken && pplayer) {
                                    QThread::msleep(20);
                                    if (!attempts)
                                        break;
                                    attempts--;
                                    isBroken = (pplayer->mediaStatus() == QMediaPlayer::LoadedMedia) &&
                                                (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                                }
                                if (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia) {
                                    qWarning() << "No preview for:" << abspath << " QMediaPlayer::InvalidMedia";
                                    break;
                                }
                                m_alreadyFrame = false;
                                qWarning() << "before wait:";
                                pplayer->pause();
                                QCoreApplication::processEvents();
                                QThread::msleep(10);
                                attempts = 20;
                                isBroken = (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                                while (!m_alreadyFrame && !isBroken && attempts) {
                                    QCoreApplication::processEvents();
                                    QThread::msleep(10);
                                    isBroken = (pplayer->mediaStatus() == QMediaPlayer::InvalidMedia);
                                    attempts--;
                                }
                                qWarning() << "after wait:";
                                QCoreApplication::processEvents();
                                if (m_alreadyFrame) {
                                    const QVideoFrame& vf = psink->videoFrame();
                                    if (psink->videoFrame().map(QVideoFrame::ReadOnly)) {
                                        image = psink->videoFrame().toImage();
                                        psink->videoFrame().unmap();
                                    }
                                    else {
                                        qWarning() << "QVideoFrame psink is not mapped";
                                        break;
                                    }
                                    if (image.format() == QImage::Format_Invalid) {
                                        qWarning() << "QImage::Format_Invalid";
                                        isBroken = true;
                                    }
                                }
                                pplayer->stop();
                                m_alreadyFrame = false;
                                if (isBroken || !attempts) {
                                    qWarning() << "No preview for:" << abspath ;
                                    qWarning() << "attempts:" << attempts << " isBroken:" << isBroken;
                                    break;
                                }
                                //setState(TPrevStates::eIdle);
                                //break;
                                QString key = fileName;
                                qWarning() << "key is:" << key << " width is:" << image.width();
                
                

                But i have the same result as before: success on windows and a failure on Android. Windows successfully mapped current frame.
                Chunk of log on Android device is below:

                ....
                W/default (24221): after wait:
                W/default (24221): Error transferring the data to system memory: -38
                W/default (24221): QVideoFrame psink is not mapped
                
                W/default (24221): start of processing for: "Trie Data Structure and Aho-Corasick Algorithm – Trie-дерево и Алгоритм Ахо-Корасик.mp4"
                W/default (24221): before wait:
                W/default (24221): frame is not valid
                W/default (24221): after wait:
                W/default (24221): Error transferring the data to system memory: -38
                W/default (24221): QVideoFrame psink is not mapped
                
                W/default (24221): start of processing for: "videoplayback.mp4"
                W/default (24221): before wait:
                W/default (24221): frame is not valid
                W/default (24221): after wait:
                W/default (24221): Error transferring the data to system memory: -38
                W/default (24221): QVideoFrame psink is not mapped
                W/default (24221): return to Idle
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  squareroot13
                  wrote last edited by
                  #8

                  Partial solution is found: https://bugreports.qt.io/browse/QTBUG-138915

                  1 Reply Last reply
                  1
                  • S squareroot13 has marked this topic as solved

                  • Login

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