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 method processBuffer
never gets called.
audioProbe = new QAudioProbe(this);
bool success = audioProbe->setSource(player);
qDebug() << success;
connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer)));
Update: Adding some additional detail in the hope of clarifying things.
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.
Frustrating that such a simple thing is so hard.