Raw audio sample from QAudioInput to .mp3 file

  • Hello, smart people,

    I need an advice. I am sampling audio using QAudioInput with codec "audio/pcm" for segmentation and computation (Hamming window, FFT, etc.). I am creating chunks of 256 segments (approximately 3 seconds of audio). Every these 3 second I need to write to separate mp3 file. I am pretty able to write these samples to raw binary file, witch can be easily played with Audacity but I really need to save it as mp3. I didn't find any mechanism in Qt (maybe I am just blind). I have to use "audio/pcm" codec because of the computations. Can you please advice me some magic QMultimedia class or something else that can convert QVector<short> to mp3 file... I am desperate. Thank you in advance.

  • Moderators

    This should help you with the file format. From there you just write out the proper header for the sound bytes you have and write it to a file.


    I don't work with sound much in Qt so there may be an easier way but I looked at the Qt Multimedia classes like QAudioBuffer/QAudioFormat/etc and none of them looked like they could convert raw bytes to an mp3. So that means you will have to write a small class that takes raw bytes and makes mp3 packets out of it.

    With that file format and description in the wiki page you should have plenty of info to do it. You may also want to search the web for a class that can do it that someone else may have done and open sourced already.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.