[SOLVED] get resolution of a video file ( QMediaPlayer )
-
wrote on 28 Aug 2013, 11:51 last edited by
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.
-
wrote on 29 Aug 2013, 10:53 last edited by
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.
-
wrote on 29 Oct 2013, 10:11 last edited by
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. -
wrote on 22 Oct 2015, 08:09 last edited by
I cannot get signal metaDataChanged(key, value) after setMedia from QMediaPlayer. metaDataChanged() signal is workng, though. Does Anyone know the solution?
-
wrote on 1 Sept 2017, 18:47 last edited by
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; } }