[Libav-user] Can't read audio from file
Mark McKay
mark at kitfox.com
Sat May 11 15:00:25 EEST 2019
I'm trying to decode the audio track from an mp4 file that can play
audio in other media players. However, when I look at the audio in the
frame that I decode, it's all set to 0 (or sometimes -0. The format type
is AV_SAMPLE_FMT_FLTP).
I've been using decode_audio.c to help guild me
in writing the code. My packet decoding looks like:
int err =
avcodec_send_packet(aCodecCtx, &packet);
if (err < 0)
{
qDebug() =
0)
{
err = avcodec_receive_frame(aCodecCtx, aFrame);
if (err ==
AVERROR(EAGAIN) || err == AVERROR_EOF)
return;
if (err < 0)
{
qDebug() nb_samples; i++)
for (int ch = 0; ch < aCodecCtx->channels;
ch++)
{
float val = 0;
switch (aCodecCtx->sample_fmt)
{
...
case
AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
{
uint8_t *byteBuffer =
aFrame->data[ch];
float* buffer = (float *)byteBuffer;
val =
buffer[i];
break;
}
...
}
_audioBuffer.write((const char *)&val,
sizeof(float));
}
}
Basically I'm trying to write the audio data as a
series of floats to an output file. I'm not getting any error codes, but
the data is all 0 or values with small exponents.
The nm_samples is
1024, the data format is AV_SAMPLE_FMT_FLTP and there are 2 channels. Is
there something I'm doing wrong here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190511/27dc92c4/attachment.html>
More information about the Libav-user
mailing list