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 media file information.
Forum Updated to NodeBB v4.3 + New Features

how to get media file information.

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 3 Posters 11.1k Views 1 Watching
  • 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.
  • S saber

    i want to get properties of video and audio file.
    like what is the frame rate , bit rate ,format ,all the bits and pices .
    how can i get this information??

    DiracsbracketD Offline
    DiracsbracketD Offline
    Diracsbracket
    wrote on last edited by
    #2

    @saber
    Hi,
    Did you have a look at the following example?
    https://doc.qt.io/qt-5.10/qtmultimedia-multimediawidgets-player-player-cpp.html

    It uses the QMediaMetaData namespace:
    http://doc.qt.io/qt-5/qmediametadata.html#details

    S 1 Reply Last reply
    2
    • DiracsbracketD Diracsbracket

      @saber
      Hi,
      Did you have a look at the following example?
      https://doc.qt.io/qt-5.10/qtmultimedia-multimediawidgets-player-player-cpp.html

      It uses the QMediaMetaData namespace:
      http://doc.qt.io/qt-5/qmediametadata.html#details

      S Offline
      S Offline
      saber
      wrote on last edited by
      #3

      @Diracsbracket
      yes .
      but don't know how to use that .

      DiracsbracketD 1 Reply Last reply
      0
      • S saber

        @Diracsbracket
        yes .
        but don't know how to use that .

        DiracsbracketD Offline
        DiracsbracketD Offline
        Diracsbracket
        wrote on last edited by Diracsbracket
        #4

        @saber said in how to get media file information.:

        but don't know how to use that

        This is a minimal example you can try out:
        (based on: http://qt.shoutwiki.com/wiki/Using_Qt_Mobility_to_get_metadata_from_media_files)

        1. Define player as a class member:
        private:
            QMediaPlayer *m_player;
        
        1. In your code:
           m_player = new QMediaPlayer(this);
          connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(onMediaStatusChanged(QMediaPlayer::MediaStatus)));
        
           m_player->setMedia(QUrl::fromLocalFile("C:\\yourMovie.avi"));
        
        1. Define the onMediaStatusChanged slot e.g. as follows:
        void MainWindow::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
        {
            if (status == QMediaPlayer::LoadedMedia)
                GetMetaData(m_player);
        }
        
        1. The GetMetaData() method lists all available metadata:
        void MainWindow::GetMetaData(QMediaPlayer *player)
        {
           // Get the list of keys there is metadata available for
           QStringList metadatalist = player->availableMetaData();
        
           // Get the size of the list
           int list_size = metadatalist.size();
        
           //qDebug() << player->isMetaDataAvailable() << list_size;
        
           // Define variables to store metadata key and value
           QString metadata_key;
           QVariant var_data;
        
           for (int indx = 0; indx < list_size; indx++)
           {
             // Get the key from the list
             metadata_key = metadatalist.at(indx);
        
             // Get the value for the key
             var_data = player->metaData(metadata_key);
        
            qDebug() << metadata_key << var_data.toString();
           }
         }
        

        The output on a sample .avi movie on my system is:

        "AudioBitRate" "128000"
        "AudioCodec" "MPEG Audio Layer-3 (MP3)"
        "ChannelCount" "2"
        "Copyright" "SaM"
        "Duration" "5069876"
        "PixelAspectRatio" ""
        "Resolution" ""
        "SampleRate" "48000"
        "VideoBitRate" "1028056"
        "VideoCodec" "MPEG-4 part 2 Video (MP4V)"
        "VideoFrameRate" "24"
        
        S 1 Reply Last reply
        3
        • DiracsbracketD Diracsbracket

          @saber said in how to get media file information.:

          but don't know how to use that

          This is a minimal example you can try out:
          (based on: http://qt.shoutwiki.com/wiki/Using_Qt_Mobility_to_get_metadata_from_media_files)

          1. Define player as a class member:
          private:
              QMediaPlayer *m_player;
          
          1. In your code:
             m_player = new QMediaPlayer(this);
            connect(m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(onMediaStatusChanged(QMediaPlayer::MediaStatus)));
          
             m_player->setMedia(QUrl::fromLocalFile("C:\\yourMovie.avi"));
          
          1. Define the onMediaStatusChanged slot e.g. as follows:
          void MainWindow::onMediaStatusChanged(QMediaPlayer::MediaStatus status)
          {
              if (status == QMediaPlayer::LoadedMedia)
                  GetMetaData(m_player);
          }
          
          1. The GetMetaData() method lists all available metadata:
          void MainWindow::GetMetaData(QMediaPlayer *player)
          {
             // Get the list of keys there is metadata available for
             QStringList metadatalist = player->availableMetaData();
          
             // Get the size of the list
             int list_size = metadatalist.size();
          
             //qDebug() << player->isMetaDataAvailable() << list_size;
          
             // Define variables to store metadata key and value
             QString metadata_key;
             QVariant var_data;
          
             for (int indx = 0; indx < list_size; indx++)
             {
               // Get the key from the list
               metadata_key = metadatalist.at(indx);
          
               // Get the value for the key
               var_data = player->metaData(metadata_key);
          
              qDebug() << metadata_key << var_data.toString();
             }
           }
          

          The output on a sample .avi movie on my system is:

          "AudioBitRate" "128000"
          "AudioCodec" "MPEG Audio Layer-3 (MP3)"
          "ChannelCount" "2"
          "Copyright" "SaM"
          "Duration" "5069876"
          "PixelAspectRatio" ""
          "Resolution" ""
          "SampleRate" "48000"
          "VideoBitRate" "1028056"
          "VideoCodec" "MPEG-4 part 2 Video (MP4V)"
          "VideoFrameRate" "24"
          
          S Offline
          S Offline
          saber
          wrote on last edited by
          #5

          @Diracsbracket
          thank you very much.

          some questions
          why we not getting Resolution,PixelAspectRatio ??

          and we ONLY get the metadata what is Available??

          DiracsbracketD 1 Reply Last reply
          0
          • S saber

            @Diracsbracket
            thank you very much.

            some questions
            why we not getting Resolution,PixelAspectRatio ??

            and we ONLY get the metadata what is Available??

            DiracsbracketD Offline
            DiracsbracketD Offline
            Diracsbracket
            wrote on last edited by Diracsbracket
            #6

            @saber said in how to get media file information.:

            Resolution,PixelAspectRatio

            Probably because this info is not available in the AVI header (maybe not part of the AVI specs?).

            @saber said in how to get media file information.:

            and we ONLY get the metadata what is Available

            You could probably use the metaData() method to query by key all the possible/relevant
            keys defined in the QMediaMetaData namespace, and check if it returns something valid?

            QVariant metaData(const QString &key) const;
            

            Also keep in mind that Qt's Multimedia framework is not as complete as some of the specialized libraries out there.

            S 1 Reply Last reply
            0
            • DiracsbracketD Diracsbracket

              @saber said in how to get media file information.:

              Resolution,PixelAspectRatio

              Probably because this info is not available in the AVI header (maybe not part of the AVI specs?).

              @saber said in how to get media file information.:

              and we ONLY get the metadata what is Available

              You could probably use the metaData() method to query by key all the possible/relevant
              keys defined in the QMediaMetaData namespace, and check if it returns something valid?

              QVariant metaData(const QString &key) const;
              

              Also keep in mind that Qt's Multimedia framework is not as complete as some of the specialized libraries out there.

              S Offline
              S Offline
              saber
              wrote on last edited by saber
              #7

              @Diracsbracket thanks.

              this way can i get image info??
              if yes , how to get that?

              some of the specialized libraries out there.
              

              please give me some suggestion.

              DiracsbracketD 1 Reply Last reply
              0
              • S saber

                @Diracsbracket thanks.

                this way can i get image info??
                if yes , how to get that?

                some of the specialized libraries out there.
                

                please give me some suggestion.

                DiracsbracketD Offline
                DiracsbracketD Offline
                Diracsbracket
                wrote on last edited by Diracsbracket
                #8

                @saber said in how to get media file information.:

                this way can i get image info

                It doesn't seem to work for images (as tested from the minimal example I posted above...)

                But, from searching on this forum (or on Google), the answer for pictures is given here:
                https://forum.qt.io/topic/83259/get-metadata-date-taken-location-from-photo-jpeg/2
                https://github.com/mayanklahiri/easyexif

                @saber said in how to get media file information.:

                please give me some suggestion

                Have a look at:
                http://en.cppreference.com/w/cpp/links/libs

                S 1 Reply Last reply
                0
                • DiracsbracketD Diracsbracket

                  @saber said in how to get media file information.:

                  this way can i get image info

                  It doesn't seem to work for images (as tested from the minimal example I posted above...)

                  But, from searching on this forum (or on Google), the answer for pictures is given here:
                  https://forum.qt.io/topic/83259/get-metadata-date-taken-location-from-photo-jpeg/2
                  https://github.com/mayanklahiri/easyexif

                  @saber said in how to get media file information.:

                  please give me some suggestion

                  Have a look at:
                  http://en.cppreference.com/w/cpp/links/libs

                  S Offline
                  S Offline
                  saber
                  wrote on last edited by saber
                  #9

                  @Diracsbracket
                  hi .
                  i found a library called mediainfo .here is the github
                  it has a example made by qt.
                  but i don't understand how to build it or use it as a lib.
                  can you help?

                  and i tried this but not getting the duration.

                  m_player->metaData(QMediaMetaData::Duration).toString();
                  

                  just giving me this "QVariant(Invalid)"

                  DiracsbracketD 2 Replies Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @saber, that's a question you should ask to the mediainfo authors. At least you should explain exactly what is happening to you.

                    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
                    1
                    • S saber

                      @Diracsbracket
                      hi .
                      i found a library called mediainfo .here is the github
                      it has a example made by qt.
                      but i don't understand how to build it or use it as a lib.
                      can you help?

                      and i tried this but not getting the duration.

                      m_player->metaData(QMediaMetaData::Duration).toString();
                      

                      just giving me this "QVariant(Invalid)"

                      DiracsbracketD Offline
                      DiracsbracketD Offline
                      Diracsbracket
                      wrote on last edited by
                      #11

                      @saber said in how to get media file information.:

                      can you help?

                      As @SGaist suggested, I'm affraid that you will have to ask the authors of that library, as I haven't tried that one yet :-(.

                      @saber said in how to get media file information.:

                      just giving me this "QVariant(Invalid)"

                      Since QMediaMetaData::Duration is a qint64 as per http://doc.qt.io/qt-5/qmediametadata.html, maybe try as follows:

                      QString::number(m_player->metaData(QMediaMetaData::Duration))

                      1 Reply Last reply
                      0
                      • S saber

                        @Diracsbracket
                        hi .
                        i found a library called mediainfo .here is the github
                        it has a example made by qt.
                        but i don't understand how to build it or use it as a lib.
                        can you help?

                        and i tried this but not getting the duration.

                        m_player->metaData(QMediaMetaData::Duration).toString();
                        

                        just giving me this "QVariant(Invalid)"

                        DiracsbracketD Offline
                        DiracsbracketD Offline
                        Diracsbracket
                        wrote on last edited by Diracsbracket
                        #12
                        This post is deleted!
                        S 1 Reply Last reply
                        2
                        • DiracsbracketD Diracsbracket

                          This post is deleted!

                          S Offline
                          S Offline
                          saber
                          wrote on last edited by
                          #13

                          @Diracsbracket
                          Thanks, mediainfo builds fine in my linux system.
                          i want it as a lib(exclude all the gui and extra pieces) so it will be easer to include it in my project.
                          i wanted to make a function that will take the file path >> send it to that lib >>lib will give the all the mediainfo.
                          but i have no idea or programming skills to do that .so if you want the same ,please modify the mideainfo to a library.
                          thanks

                          DiracsbracketD 1 Reply Last reply
                          0
                          • S saber

                            @Diracsbracket
                            Thanks, mediainfo builds fine in my linux system.
                            i want it as a lib(exclude all the gui and extra pieces) so it will be easer to include it in my project.
                            i wanted to make a function that will take the file path >> send it to that lib >>lib will give the all the mediainfo.
                            but i have no idea or programming skills to do that .so if you want the same ,please modify the mideainfo to a library.
                            thanks

                            DiracsbracketD Offline
                            DiracsbracketD Offline
                            Diracsbracket
                            wrote on last edited by Diracsbracket
                            #14

                            @saber said in how to get media file information.:

                            i want it as a lib

                            MediaInfoLib IS the lib. I thought this would have been clear enough...
                            MediaInfo is just an application using it. Study that example to learn how to use it.

                            S 1 Reply Last reply
                            2
                            • DiracsbracketD Diracsbracket

                              @saber said in how to get media file information.:

                              i want it as a lib

                              MediaInfoLib IS the lib. I thought this would have been clear enough...
                              MediaInfo is just an application using it. Study that example to learn how to use it.

                              S Offline
                              S Offline
                              saber
                              wrote on last edited by saber
                              #15

                              @Diracsbracket

                              oh!ok.
                              can you show me the lib folder?
                              and how to include it in .pro .
                              an example will be great!!

                              DiracsbracketD 1 Reply Last reply
                              0
                              • S saber

                                @Diracsbracket

                                oh!ok.
                                can you show me the lib folder?
                                and how to include it in .pro .
                                an example will be great!!

                                DiracsbracketD Offline
                                DiracsbracketD Offline
                                Diracsbracket
                                wrote on last edited by Diracsbracket
                                #16

                                @saber said in how to get media file information.:

                                can you show me the lib folder?
                                and how to include it in .pro .
                                an example will be great!!

                                As I wrote. Study the example. You said MediaInfo builds correctly on your system, so you have access to all the info you need, since it builds perfectly in Qt Creator. Don't expect everything to be done for you...
                                Good luck!

                                1 Reply Last reply
                                2
                                • S Offline
                                  S Offline
                                  saber
                                  wrote on last edited by
                                  #17

                                  after long works i made an app with mediainfo as backend.
                                  here is the app CoreInfo.
                                  thanks.

                                  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