[Libav-user] How to get raw audio frames from an audio file

Matthieu Regnauld mregnauld at gmail.com
Sat Oct 20 13:30:23 EEST 2018


Hello,

I try to extract raw audio frames from an audio file, using the following
example: http://ffmpeg.org/doxygen/3.4/decode_audio_8c-example.html

As far as I understand, I get these frames in the decode() function, in the
frame->data array.

That said, I need to convert the frames into floats between -1 and 1. Here
is what I tried (in my test, dataSize == 4):

// here is where I want to get my frame:
float myFrame;

// first try:
memcpy(&myFrame, &frame->data[ch][i], dataSize * sizeof(uint8_t));

// second try:
myFrame = (frame->data[ch][i]<<0) | (frame->data[ch][i + 1]<<8) |
(frame->data[ch][i + 2]<<16) | (frame->data[ch][i + 3]<<24);

// third try:
myFrame = (frame->data[ch][i + 3]<<0) | (frame->data[ch][i + 2]<<8) |
(frame->data[ch][i + 1]<<16) | (frame->data[ch][i]<<24);

But the problem is; it doesn't work, all I got so far is some kind of white
noice.

So what is the proper way to extract audio frames and convert them to float
amplitudes?

Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20181020/c6cb329f/attachment.html>


More information about the Libav-user mailing list