[Libav-user] Can't read audio from file

Mark McKay mark at kitfox.com
Sat May 11 17:25:47 EEST 2019


Nevermind. The audio data is being read correctly - I was confused by
how my program was handling the
data.

Mark

-------------------------
SUBJECT: [Libav-user] Can't read
audio from file
DATE: Sat, 11 May 2019 08:00:25 -0400
FROM: Mark McKay

TO: "This list is about using libavcodec, libavformat, libavutil,
libavdevice and libavfilter." 
REPLY-TO: "This list is about using
libavcodec, libavformat, libavutil, libavdevice and libavfilter." 

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? 

---
http://www.kitfox.com
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20190511/a1769f19/attachment.html>


More information about the Libav-user mailing list