Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] get resolution of a video file ( QMediaPlayer )
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 5.7k Views
  • 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
    Timmoth
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      Timmoth
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deepakiitr
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jim_tkb
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            David A. Osipyan
            wrote on last edited by
            #5

            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;
                }
            }
            
            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