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. How to get dimensions of video files [Solved]
QtWS25 Last Chance

How to get dimensions of video files [Solved]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.8k 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.
  • SeishinS Offline
    SeishinS Offline
    Seishin
    wrote on last edited by
    #1

    Hi everyone,

    I have a dialog box which has a button to call QFileDialog::getOpenFileName() to choose a video file.
    And the Phonon::VideoPlayer will use the path to play the video.
    Now I want to get the width and height of the video. I try to use VideoPlayer->sizeHint() to get the size while the file path is set. The code is like:

    @void VideoDialog::addVideo() // A slot called by clicked() signal of the button
    {
    QMessageBox::information(this, "0", QString::number(m_videoPlayer->sizeHint().width()) + " x " + QString::number(m_videoPlayer->sizeHint().height()));
    QString videoFile = QFileDialog::getOpenFileName(.....); // The function arguments are removed
    if(!videoFile.isEmpty()){
    m_videoPlayer->mediaObject()->clear();
    m_videoPlayer->mediaObject()->setCurrentSource(videoFile);
    QMessageBox::information(this, "1", QString::number(m_videoPlayer->sizeHint().width()) + " x " + QString::number(m_videoPlayer->sizeHint().height()));
    }
    }@
    The 1st problem is that after I set the video path, the sizeHint is not updated. But if I press the button again, the sizeHint will be the right value. Is there a way to get the sizeHint immediately?

    And the 2nd problem is when I hide the VideoPlayer widget, I only get 1 x 1 every time on sizeHint.
    I see the doc says "The default implementation of sizeHint() returns an invalid size if there is no layout for this widget. "
    But I do need to hide the widget on initial. Any help please?
    Thanks in advance.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      akrynski
      wrote on last edited by
      #2

      Absolute positioning has many disadvantages:
      • The user cannot resize the window.
      • Some text may be truncated if the user chooses an unusually large font or
      if the application is translated into another language.
      • The widgets might have inappropriate sizes for some styles.
      • The positions and sizes must be calculated manually. This is tedious and
      error-prone, and makes maintenance painful.

      So use i.e QStackedLayout and than add to it your hidden widgets!

      --
      Pozdrawiam i do następnego...
      Greetings and till next...

      1 Reply Last reply
      0
      • SeishinS Offline
        SeishinS Offline
        Seishin
        wrote on last edited by
        #3

        Thanks for your suggestion. But the problem here is how to get the dimensions of a video.
        And QStackedLayout is not very suitable for my UI.
        Btw I'm using QGridLayout which is relative positioning I think.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          akrynski
          wrote on last edited by
          #4

          I am not sure if I understood your problem, but if so, I would try to load your media as QMovie and then obtain data from QMovie::currentImage.width (...).height if it is a simple animation, or simply use QVideoFrame.width (...).height if it is a 'normal' video.
          Have you seen videowidgetsurface.cpp example?

          --
          Pozdrawiam i do następnego...
          Greetings and till next...

          1 Reply Last reply
          0
          • SeishinS Offline
            SeishinS Offline
            Seishin
            wrote on last edited by
            #5

            Yes I just want to get the video width and height of a video file, like avi, wmv or mp4, etc. QMovie looks work for me. And I'll try both of them.

            Currently I found a tricky way to do this with phonon. I update the dimensions using sizeHint after state changed signal since very time I reload a new movie will change the state of the media object. This works very well, too.

            Thanks for your help.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              akrynski
              wrote on last edited by
              #6

              Done with pleasure ;)
              Then, please mark the topic as [solved].

              --
              Pozdrawiam i do następnego...
              Greetings and till next...

              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