Solved Generating a waveform from an audio (or video) file?
-
I'm trying to understand how I can generate a waveform from an audio (or video) file to display to the user.
I've been googling around for quite a while now and can't determine if this is even possible in Qt without using something like FFmpeg. I've seen all of these classes:QMediaPlayer, QMediaContent, QMediaResource, QAudioProbe and experimented with the Qt Media Player Example but am just not seeing where I can access the actual audio buffer.
So I have 2 questions:
- Is what I want to do even possible without 3rd party libraries?
- If it is possible, can some kind soul outline what I need to read and understand in order to access the audio data
I have tried the suggestions from this question Audio visualization with QMediaPlayer but the result of
audioProbe->setSource(player)
is always false and the methodprocessBuffer
never gets called.audioProbe = new QAudioProbe(this); bool success = audioProbe->setSource(player); qDebug() << success; connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer)));
-
Hi,
Are you by any chance running Windows ?
-
-
@TOMATO_QT
Hello,
It would be helpful to check these things:- Have you made sure you have the
Q_OBJECT
macro on top of your class declaration (this is needed for signal-slot connections)? - Does
player
support probing for audio? - Do you have any debug output in your debug window relating to the
QObject::connect
you're invoking (connections are made in runtime)? - What does your media object return as availability, do you get QMultimedia::Available?
- Have you made sure you have the
-
Hi, thanks for the reply.
-
For testing/learning I am using the Media Player Example which ships with Qt, so it is set up correctly with
Q_OBJECT
etc. -
For audio, I tested with both .mp3 and .wav files. FWIW, the
player
example won't play video for some reason (.mp4, .avi were tested) -
The
player
in the code is QMediaPlayer – which inherits fromQMediaObject
. The example code for thePlayer
class is here. I added my code (in original comment above) right after the player is instantiated. I also tried adding it once media is loaded. -
I tried declaring my slot first as private, then as public – either way, it is never called.
-
Finally, I test for
QMediaPlayer.availability()
and it always reports "0": QMultimedia::Available 0 The service is operating correctly.
Frustrating that such a simple thing is so hard.
-
-
@TOMATO_QT
Hello,
I'd venture to guess you are missing a plugin or a codec, although I have not worked with the multimedia classes, so this is speculative. From what I can see here OS X's backend does not support audio probing.PS:
I tried declaring my slot first as private, then as public – either way, it is never called.
The access you declare for your slots is inconsequential when you connect them in the old style, because no compile time checks are done and calling each corresponding function is done through
QMetaObject::invokeMethod
. -
Thanks for digging that chart up. I tripped over that same info just now indirectly on another of my endless google searches on this issue
http://comments.gmane.org/gmane.comp.lib.qt.user/10973
Re: QAudioProbe and QMediaPlayer
On Feb 3, 2014, at 5:40 PM, Ziggy Uszkurat wrote:I’m trying to attach a QAudioProbe to QMediaPlayer but I’m having no luck. When I setSource >>it returns false. Can anyone give me a clue where I might be going wrong?
You are not doing anything wrong, not all multimedia APIs are supported on all platforms. QAudioProbe is currently supported only on Linux (with the GStreamer backend) and Windows (with the WMF backend, which is available only when Qt is built with MSVC)
Yoann Lopes
Senior Software Engineer - Digia, Qt
Visit us on: http://qt.digia.comWhat a GD waste of my time. WHY doesn't the QAudioProbe class SAY it isn't supported on OSX.
This is why I have ditched Qt in the past – it is NOT "Qt Everywhere" – it often ends up being a huge and pointless time sink.And I still have no way of accessing the audio data. Even GD HTML5 exposes it.
-
@TOMATO_QT said:
WHY doesn't the QAudioProbe class SAY it isn't supported on OSX.
This is why I have ditched Qt in the past – it is NOT "Qt Everywhere" – it often ends up being a huge and pointless time sink.It actually does, by returning false. Take a look at the documentation page I attached in one of my previous posts. Qt depends on the OS X's ability to provide the API needed for probing, it's a wrapper around the system functions, so you'll have to ask Apple why this is not implemented ... The same goes for many other components of Qt, by the way, you can't expect to have threads on a system that does not support them, right?
-
It should say it in the documentation for QAudioProbe, as well as other classes where support varies by platform – same for the examples: what is the point or learning value of an "example" if it doesn't state what the limitations or differences are per platform.
OR – just include a link to that chart in the classes where support varies by platform – it's not a hard thing to do.
-
@TOMATO_QT
That's my point, it is in the documentation of the QAudioProbe::setSource method. Also this is the second list item of my first post, the link is pointing right there. :)If the media object does not support monitoring audio, this function will return false.
-
Yes it is "there" – in a rather (cough) subtle way. I see no reason why the docs are not explicit: "Not supported on OSX" or whatever, within classes like QAudioProbe – rather than in some chart – then one could tell at a glance.
"oh well"
-
I don't write the documentation, but if I had to guess, probably because it depends on the OS and the backend used (some systems have multiple backends), which may change at any one time.