[FFmpeg-trac] #10732(undetermined:new): avcodec_flush_buffers() not resetting E-AC-3 decoder
FFmpeg
trac at avcodec.org
Mon Dec 11 09:30:40 EET 2023
#10732: avcodec_flush_buffers() not resetting E-AC-3 decoder
----------------------------------------+----------------------------------
Reporter: Peter Krefting | Type: defect
Status: new | Priority: minor
Component: undetermined | Version: 5.0.3
Keywords: | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
----------------------------------------+----------------------------------
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
[https://ffmpeg.org/doxygen/trunk/group__lavc__misc.html#gaf60b0e076f822abcb2700eb601d352a6
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:
{{{#!c
#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.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/10732>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list