QMediaPlayer doesn't recognize duration of mono-CBR of mp3, but mono VBR does.
-
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); } }
-
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. -
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. -
Try to read the file using the GStreamer CLI to see if it handles the file and if it provides some more information.
-
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/sffmpeg -i metronom-mono.mp3 2>&1 | grep Duration
Duration: 00:01:11.48, start: 0.000000, bitrate: 128 kb/sffmpeg -i metronom-mono-vbr.mp3 2>&1 | grep Duration
Duration: 00:01:11.47, start: 0.025057, bitrate: 39 kb/sWhere start of ffmpeg is zeroed these files gst_element_query_duration fails to get duration.
-
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/sffmpeg -i metronom-mono.mp3 2>&1 | grep Duration
Duration: 00:01:11.48, start: 0.000000, bitrate: 128 kb/sffmpeg -i metronom-mono-vbr.mp3 2>&1 | grep Duration
Duration: 00:01:11.47, start: 0.025057, bitrate: 39 kb/sWhere start of ffmpeg is zeroed these files gst_element_query_duration fails to get duration.
-
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.