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 doesn't recognize duration of mono-CBR of mp3, but mono VBR does.
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer doesn't recognize duration of mono-CBR of mp3, but mono VBR does.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 484 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.
  • liscoL Offline
    liscoL Offline
    lisco
    wrote on last edited by
    #1

    subj, this happened in Linux, but on Windows duration is very well of any mp3.

    some code of modified player example is here

    connect(m_player, &QMediaPlayer::durationChanged, this, &Player::durationChanged);
    
    fileDialog.setDirectory(QStandardPaths::standardLocations(QStandardPaths::MusicLocation).value(0, QDir::homePath()));
    openFile(fileDialog.getOpenFileName());
    
    void Player::openFile(const QString fileName)
    {
    	QFile file(fileName);
    	if (!file.open(QIODevice::ReadOnly))
    		return;
    	m_data = file.readAll();
    
    	m_buffer = new QBuffer(this);
    	m_buffer->setData(m_data);
    	m_buffer->open(QIODevice::ReadOnly);
    
    	QMediaContent content;
    	m_player->setMedia(QMediaContent(), m_buffer); 
    }
    
    void Player::durationChanged(qint64 duration)
    {
    	auto status = m_player->mediaStatus();
    	if (status == QMediaPlayer::LoadedMedia || status == QMediaPlayer::LoadingMedia) {
    		m_duration = duration / 1000;
    		m_slider->setMaximum(m_duration);
    
    		updateDurationInfo(m_duration);
    	}
    }
    
    1 Reply Last reply
    0
    • liscoL Offline
      liscoL Offline
      lisco
      wrote on last edited by
      #2

      Windows uses directshow for duration, linux uses gstreamer, maybe something is wrong with it , the gst_element_query_duration method I try to debug.

      1 Reply Last reply
      0
      • liscoL Offline
        liscoL Offline
        lisco
        wrote on last edited by
        #3

        durationChanged doesn't event at all on mono mp3 CBR.

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

          Hi,

          Does GStreamer handle it properly ?
          Which version of GStreamer is it ?
          On a side note, since Qt 6.5, the default backend is ffmpeg. You might have better results with it.

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

          liscoL 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Does GStreamer handle it properly ?
            Which version of GStreamer is it ?
            On a side note, since Qt 6.5, the default backend is ffmpeg. You might have better results with it.

            liscoL Offline
            liscoL Offline
            lisco
            wrote on last edited by
            #5

            @SGaist said in QMediaPlayer doesn't recognize duration of mono-CBR of mp3, but mono VBR does.:

            Does GStreamer handle it properly ?

            How to know?
            ldd doesn't show any missing.

            Version is such that was in Debian 10.
            Qt5.15.2

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

              Try to read the file using the GStreamer CLI to see if it handles the file and if it provides some more information.

              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
              • liscoL Offline
                liscoL Offline
                lisco
                wrote on last edited by lisco
                #7
                if (m_pipeline && qt_gst_element_query_duration(m_pipeline, GST_FORMAT_TIME, &gstDuration))
                

                returns gstDuration=-1 on mono-cbr mp3

                @SGaist Did you mean to run gst-launch with pipeline to mp3?

                ffmpeg -i metronom.mp3 2>&1 | grep Duration
                Duration: 00:01:11.45, start: 0.000000, bitrate: 128 kb/s

                ffmpeg -i metronom-mono.mp3 2>&1 | grep Duration
                Duration: 00:01:11.48, start: 0.000000, bitrate: 128 kb/s

                ffmpeg -i metronom-mono-vbr.mp3 2>&1 | grep Duration
                Duration: 00:01:11.47, start: 0.025057, bitrate: 39 kb/s

                Where start of ffmpeg is zeroed these files gst_element_query_duration fails to get duration.

                JoeCFDJ 1 Reply Last reply
                0
                • liscoL lisco
                  if (m_pipeline && qt_gst_element_query_duration(m_pipeline, GST_FORMAT_TIME, &gstDuration))
                  

                  returns gstDuration=-1 on mono-cbr mp3

                  @SGaist Did you mean to run gst-launch with pipeline to mp3?

                  ffmpeg -i metronom.mp3 2>&1 | grep Duration
                  Duration: 00:01:11.45, start: 0.000000, bitrate: 128 kb/s

                  ffmpeg -i metronom-mono.mp3 2>&1 | grep Duration
                  Duration: 00:01:11.48, start: 0.000000, bitrate: 128 kb/s

                  ffmpeg -i metronom-mono-vbr.mp3 2>&1 | grep Duration
                  Duration: 00:01:11.47, start: 0.025057, bitrate: 39 kb/s

                  Where start of ffmpeg is zeroed these files gst_element_query_duration fails to get duration.

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by JoeCFD
                  #8

                  @lisco use gst_discoverer_new to find duration of media files before pipeline starts.
                  qt_gst_element_query_duration is used after pipeline is started and may take some time. Therefore, the result can be wrong.

                  1 Reply Last reply
                  0
                  • liscoL Offline
                    liscoL Offline
                    lisco
                    wrote on last edited by
                    #9

                    Before callling qt_gst_element_query_duration the application uses 50-100ms delay after buffer is filled by setMedia, but result fails, except stereo or mono vbr.

                    JoeCFDJ 1 Reply Last reply
                    0
                    • liscoL lisco

                      Before callling qt_gst_element_query_duration the application uses 50-100ms delay after buffer is filled by setMedia, but result fails, except stereo or mono vbr.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by
                      #10

                      @lisco It is not reliable to use qt_gst_element_query_duration. If your media file is short(for example a beep sound file), you will not be able to get duration. Try to use gst_discoverer_new.

                      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