Opened 5 months ago
Last modified 2 months ago
#10732 new defect
avcodec_flush_buffers() not resetting E-AC-3 decoder
Reported by: | Peter Krefting | Owned by: | |
---|---|---|---|
Priority: | minor | Component: | undetermined |
Version: | 6.1 | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
I am reusing the same AVCodecContext to decode several parallel E-AC-3 audio streams. As per documentation I am calling avcodec_flush_buffers() between each decoding run. This seems to work for most codecs, but when used with the E-AC-3 decoder the output is not identical between runs
How to reproduce:
#include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <stdio.h> #include <assert.h> int main(int argc, char *argv[]) { const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_EAC3); AVCodecContext *decoder = avcodec_alloc_context3(codec); avcodec_open2(decoder, codec, NULL); assert(decoder->sample_fmt == AV_SAMPLE_FMT_FLTP); for (int l = 0; l < 2; ++ l) { printf("[%d] Reading file\n", l); avcodec_flush_buffers(decoder); AVFormatContext *avf_ctx = NULL; avformat_open_input(&avf_ctx, "file:i28553p303t610156395819694.ac3", NULL, NULL); avformat_find_stream_info(avf_ctx, NULL); AVPacket avpkt = { 0 }; while (av_read_frame(avf_ctx, &avpkt) == 0) { avcodec_send_packet(decoder, &avpkt); AVFrame *frame = av_frame_alloc(); avcodec_receive_frame(decoder, frame); printf("Got %d samples in %d channels\n", frame->nb_samples, frame->channels); for (int i = 0; i < frame->nb_samples; ++ i) { printf("%4d:", i); for (int j = 0; j < frame->channels; ++ j) { printf(" [%d]%f", j, ((float *) frame->data[j])[i]); } printf("\n"); } av_frame_free(&frame); } avformat_close_input(&avf_ctx); } avcodec_free_context(&decoder); return 0; }
The test file is available here: https://e.pcloud.link/publink/show?code=XZS8y1ZlEryJIDYU0yIzDTUhw1sDfHDRtUV and contains a ten-second extract of an audio track from an MPEGTS container, captured off-air while looking at a problem where the encoder suddenly only outputs silence.
I expect the output to be identical on the first and second run, but that is not what I am seeing:
$ ./decode |grep -A5 'Reading file' [eac3 @ 0x55fc4b0a5ec0] Estimating duration from bitrate, this may be inaccurate [0] Reading file Got 1536 samples in 6 channels 0: [0]0.000000 [1]0.000000 [2]0.000000 [3]0.000000 [4]0.000000 [5]0.000000 1: [0]0.000000 [1]0.000000 [2]0.000000 [3]0.000000 [4]0.000000 [5]0.000000 2: [0]0.000000 [1]0.000000 [2]0.000000 [3]0.000000 [4]0.000000 [5]0.000000 3: [0]0.000000 [1]0.000000 [2]0.000000 [3]0.000000 [4]0.000000 [5]0.000000 [eac3 @ 0x55fc4b11a840] Estimating duration from bitrate, this may be inaccurate -- [1] Reading file Got 1536 samples in 6 channels 0: [0]0.000000 [1]0.000000 [2]0.000000 [3]0.000000 [4]0.000000 [5]0.000000 1: [0]-0.000000 [1]0.000000 [2]-0.000000 [3]-0.000000 [4]-0.000000 [5]-0.000000 2: [0]0.000000 [1]0.000000 [2]0.000000 [3]0.000000 [4]0.000000 [5]0.000000 3: [0]-0.000000 [1]-0.000000 [2]-0.000000 [3]-0.000000 [4]-0.000000 [5]-0.000000
In real life we are also interleaving other E-AC-3 audio streams from the same MPEGTS between decodes, and see that the initial decoded samples differ even more than when just redecoding the same sample over and over.
Change History (3)
comment:1 by , 5 months ago
comment:2 by , 5 months ago
Also verified that the I see the same issue in the 6.1 release version. Updating the build framework is fairly heavy process, and I have not tested the latest git master.
comment:3 by , 2 months ago
Version: | 5.0.3 → 6.1 |
---|
We are also seeing a similar issue in an unrelated case using the HEVC decoder (AV_CODEC_ID_H265). When multiplexing several streams into the same AVCodecContext object, calling avcodec_flush_buffers() between each call, we sometimes fail to get frames decoded, but if we change to having a dedicated AVCodecContext for each of the streams it decodes fine.