Hi,
I'm having troubles using avcodec_decode_audio3 when trying to decode all
audio packets in an MP3. It works fine with Flac files: I get the correct
number of samples (when dividing them by 44100, its sample rate, I get the
correct duration in seconds).
So basically, my code has this main loop:
while (av_read_frame(fmt_ctx, &pkt) >= 0) {
if (pkt.stream_index == aid) {
int r = process_audio_pkt(a_codec_ctx, &pkt);
if (r == -1)
fprintf(stderr, "Error while processing packet\n");
}
}
And the process_audio_pkt function looks like this:
static int process_audio_pkt(AVCodecContext *ctx, AVPacket *pkt)
{
uint8_t audio_buf[AVCODEC_MAX_AUDIO_FRAME_SIZE];
int16_t *data = (int16_t *)audio_buf;
int data_size, len;
static int total_samples;
while (pkt->size > 0) {
data_size = sizeof(audio_buf);
len = avcodec_decode_audio3(ctx, data, &data_size, pkt);
if (len < 0) {
pkt->size = 0;
return -1;
}
total_samples += len / 2;
printf("total_samples=%d\n", total_samples);
// process samples...
pkt->data += len;
pkt->size -= len;
}
return 0;
}
Using this code, I get 6592545 samples with my Flac audio (which is correct)
and 1146768 in the MP3 version (same sample rate, same duration, same number of
channels, ...)
Of course I tested with different audio files, and everytime MP3 files
look incompletes. I've also tried with the latest FFmpeg SVN just in case,
and it's the same.
The only message I get is "[mp3 @ ...] max_analyze_duration reached", but I
don't think it's related.
Did I missed something?
Thanks,
--
Clément B.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user