[Libav-user] How to read in planar data?
Mark McKay
mark at kitfox.com
Sat Dec 7 00:05:07 EET 2019
Just reposting with properly formatted code:
void AudioReader::loadAudioFrame(AVPacket& packet)
{
int err = avcodec_send_packet(aCodecCtx, &packet);
if (err < 0)
{
qDebug("Error sending packet to decoder");
return;
}
int numChannels = aCodecCtx->channels;
while (err >= 0)
{
err = avcodec_receive_frame(aCodecCtx, aFrame);
if (err == AVERROR(EAGAIN) || err == AVERROR_EOF)
return;
if (err < 0)
{
qDebug() << "Error decoding packet: " << err;
return;
}
int bytesPerSample =
av_get_bytes_per_sample(aCodecCtx->sample_fmt);
if (bytesPerSample < 0) {
/* This should not occur, checking just for paranoia */
fprintf(stderr, "Failed to calculate data size\n");
exit(1);
}
int bufferSize = av_samples_get_buffer_size(NULL,
aCodecCtx->channels,
aFrame->nb_samples,
aCodecCtx->sample_fmt,
1);
switch(aCodecCtx->sample_fmt)
{
...
case AV_SAMPLE_FMT_FLTP:
{
//Serial format - change to interleaved order
for (int i = 0; i < aFrame->nb_samples; i++)
{
for (int ch = 0; ch < numChannels; ch++)
{
_audioBytes.append((const char *)aFrame->data[ch] +
i * sizeof(float), sizeof(float));
}
}
break;
}
}
}
On 2019-12-06 15:55, Mark McKay wrote:
> I'm having trouble trying to figure out how to read in planar data. I
> have a file that has data in the AV_SAMPLE_FMT_FLTP format with two
> channels. Below is my attempt to read in the data. This will crash
> with a memory problem if I try to read in the second channel (but it
> will complete if I bypass the second and just read from channel 0). Am
> I doing this right?
More information about the Libav-user
mailing list