[SOLVED] get resolution of a video file ( QMediaPlayer )



  • Hi, i am trying to acquire the resolution of a video before i play it however this code returns -1, -1:
    @
    mediaPlayer.media().canonicalResource().resolution()
    @

    any suggestions on how to get a files resolution?

    Regards, Tim.



  • for anyone who maybe having the same issue as me:

    I solved my problem by waiting until the user plays the video and as soon as they do so i get the QGraphicsVideoItems class property: nativeSize.



  • I solved it by using the signal metaDataChanged(key, value) when key is "Resolution".
    Create a QMediaPlayer and set its media content, and use that signal. It is not necessory to play the media.



  • I cannot get signal metaDataChanged(key, value) after setMedia from QMediaPlayer. metaDataChanged() signal is workng, though. Does Anyone know the solution?



  • You can use QVideoWidget instance as video output for QMediaPlayer and retrieve native size of video from QVideoWidget::sizeHint.

    QSize MyVideoPlayer::getVideoNativeSize(const QString& videoFilePath)
    {
        m_mediaPlayer = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
        m_mediaPlayer->setVideoOutput(m_videoWidget);
        m_mediaPlayer->setMedia(QUrl::fromLocalFile(videoFilePath));
        connect(m_mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
                this, SLOT(OnMediaStatusChanged(QMediaPlayer::MediaStatus)));
    
        m_isStoppingVideo = false;
        m_videoScreenSize = QSize();
        QEventLoop loop;
        m_mediaPlayer->play();
        while (!m_isStoppingVideo)
        {
            loop.processEvents();
        }
        disconnect(m_mediaPlayer, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
                    this, SLOT(OnMediaStatusChanged(QMediaPlayer::MediaStatus)));
    
        m_mediaPlayer->stop();
        return m_videoWidget->sizeHint();
    }
    
    void MyVideoPlayer::OnMediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus)
    {
        if (mediaStatus == QMediaPlayer::BufferedMedia)
        {
            m_isStoppingVideo = true;
        }
    }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.