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. QMediaPlayer resolution returns (-1x-1)
QtWS25 Last Chance

QMediaPlayer resolution returns (-1x-1)

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 5.3k 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.
  • C Offline
    C Offline
    CandyManJ
    wrote on last edited by
    #1

    Hi,

    I have the following code:

    @
    QMediaPlayer * Player = new QMediaPlayer(this,QMediaPlayer::StreamPlayback);

    Player->setMedia(QUrl::fromLocalFile(Filename));

    Player->setVideoOutput(Screen);
    Player->play();
    Screen->show();

    Screen->setGeometry(0,0,Player->media().canonicalResource().resolution().width(),Player->media().canonicalResource().resolution().height());
    @

    When calling Player->media().canonicalResource().resolution().width() for example, it returns -1 instead of the video's original width, I tried changing the order of the code lines and calling SIGNALS but that didn't help. I can set the video to the size I want, but I actually want the video to be set to its original sizes when played. (By the way the audio plays with no problems)

    So Is that a bug or have I done something wrong?

    Best,
    MJaoune

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CandyManJ
      wrote on last edited by
      #2

      Please tell me if I did something wrong or this is a bug so I can submit a detailed bug report to the QT team.

      1 Reply Last reply
      0
      • T3STYT Offline
        T3STYT Offline
        T3STY
        wrote on last edited by
        #3

        Could you provide a full-working source code with all the includes and so?

        Anyway, I think you might be using the wrong class. The "QMediaPlayer":http://qt-project.org/doc/qt-5.1/qtmultimedia/qmediaplayer.html#details class only provides the functionality of a media player, but nothing related to a GUI is actually implemented - so you can get no size out of a non-GUI object (widget). The "QtMultimediaWidgets":http://qt-project.org/doc/qt-5.1/qtmultimediawidgets/qtmultimediawidgets-index.html class (and its derivatives) instead provides GUI widgets - and these can be used to get widget size references.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CandyManJ
          wrote on last edited by
          #4

          I actually want to get the original resolution of the video file itself.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CandyManJ
            wrote on last edited by
            #5

            UPDATE: I figured out that the problem is with getting the Metadata of the video, since when using connect with SIGNAL MetaDataChanged(bool) it just returns false, also, when trying to read the resolution manually from the metadata it also returns -1, any help?

            1 Reply Last reply
            0
            • C Offline
              C Offline
              CandyManJ
              wrote on last edited by
              #6

              bump....

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CandyManJ
                wrote on last edited by
                #7

                its really funny how no one knows the answer... even the developers themselves since I already submitted a bug report...

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

                  Hi,

                  Could you share the link to the bug report ? So others interested in the same problem can find it more easily

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

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    CandyManJ
                    wrote on last edited by
                    #9

                    Here it is:

                    "https://bugreports.qt-project.org/browse/QTBUG-33757":https://bugreports.qt-project.org/browse/QTBUG-33757

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      schiktol
                      wrote on last edited by
                      #10

                      You can get the video's native resolution once the media has loaded.
                      Say you have a slot called
                      void handleMediaStatusChange(QMediaPlayer::MediaStatus)

                      @
                      connect(
                      &player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
                      this, SLOT(handleMediaStatusChange(QMediaPlayer::MediaStatus))
                      );

                      void YourApp::handleMediaStatusChange(QMediaPlayer::MediaStatus s) {
                      if ( s == QMediaPlayer::LoadedMedia) {
                      qDebug() << "native resolution:" << Screen.nativeSize();
                      qDebug() << "total duration:" << player.duration() << "msec";
                      }
                      }
                      @

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        CandyManJ
                        wrote on last edited by
                        #11

                        Hi.

                        Screen is of type QVideoWidget, and so it doesn't have nativeSize() function.
                        I tried setting the Screen to QGraphicsVideoItem and then getting the nativeSize but it still returns -1x-1

                        As for the duration, I was able to obtain it after the Media was Loaded successfully.

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          CandyManJ
                          wrote on last edited by
                          #12

                          I think I discovered the problem, and its a critical problem...

                          The problem was using MingW as the compiler... When using VS2012 x64, the media's Meta Data was found and I could get the resolution of the video.

                          To be more specific, when using MingW, the SIGNAL metaDataAvailableChanged(bool) always returns false, which means it can never find the MetaData of the Media, but when using VS2012, everything works perfectly, including the SIGNAL.

                          That's a very critic bug and I hope it gets fixed soon since I prefer MingW over VS2012 since MingW is based on GNU's GCC and is cross-platform.

                          I will open another bug ticket including the new important information, but if anyone still knows a solution, please provide it here so we can help Qt users.

                          EDIT: Here is the Bug ticket: "https://bugreports.qt-project.org/browse/QTBUG-33888":https://bugreports.qt-project.org/browse/QTBUG-33888

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

                            You should rather add your findings to the existing bug report since it's related so everything is in only one place. Otherwise it complicates the task for the maintainers to gather all the information to fix it

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

                            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