PR #23508 opened by James Almer (jamrial) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23508 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23508.patch
The encoder was letting the generic code set the duration based on the input frame, disregarding the fact it had output 256 samples of initial padding at the beginning. >From e9709b5b7b8dac5e75601284cd6e9a6c7432e16e Mon Sep 17 00:00:00 2001 From: James Almer <[email protected]> Date: Tue, 16 Jun 2026 21:32:14 -0300 Subject: [PATCH] avcodec/ac3enc: take into account the priming samples in the last packet duration The encoder was letting the generic code set the duration based on the input frame, disregarding the fact it had output 256 samples of initial padding at the beginning. Signed-off-by: James Almer <[email protected]> --- libavcodec/ac3enc.c | 14 ++++++++++++++ tests/ref/fate/autorotate | 2 +- tests/ref/fate/ffmpeg-filter_complex_audio | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 5a1a3ab63a..f8f773d45a 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -2016,6 +2016,20 @@ int ff_ac3_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (frame->pts != AV_NOPTS_VALUE) avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding); + if (frame->duration > 0) { + avpkt->duration = frame->duration; + if (frame->duration != ff_samples_to_time_base(avctx, frame->nb_samples)) + avpkt->duration += ff_samples_to_time_base(avctx, avctx->initial_padding); + + int discard_padding = avctx->frame_size - ff_samples_from_time_base(avctx, avpkt->duration); + if (discard_padding > 0) { + uint8_t *side_data = + av_packet_new_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, 10); + if (!side_data) + return AVERROR(ENOMEM); + AV_WL32(side_data + 4, discard_padding); + } + } *got_packet_ptr = 1; return 0; diff --git a/tests/ref/fate/autorotate b/tests/ref/fate/autorotate index ec2044f7eb..1166bb63fc 100644 --- a/tests/ref/fate/autorotate +++ b/tests/ref/fate/autorotate @@ -1,4 +1,4 @@ -c57662975b92b9403341271944e2645d *tests/data/fate/autorotate.mov +bb03affe94dfbe39c8cad8eb69dc367c *tests/data/fate/autorotate.mov 197366 tests/data/fate/autorotate.mov #extradata 0: 34, 0x9d7d073f #tb 0: 1/15360 diff --git a/tests/ref/fate/ffmpeg-filter_complex_audio b/tests/ref/fate/ffmpeg-filter_complex_audio index 4b6c73545c..5b42ab1b8a 100644 --- a/tests/ref/fate/ffmpeg-filter_complex_audio +++ b/tests/ref/fate/ffmpeg-filter_complex_audio @@ -6,4 +6,4 @@ 0, -256, -256, 1536, 416, 0x3001fb2d 0, 1280, 1280, 1536, 418, 0xba72fc16 0, 2816, 2816, 1536, 418, 0xba72fc16 -0, 4352, 4352, 3, 418, 0xba72fc16, S=1, Skip Samples, 10, 0x06070102 +0, 4352, 4352, 259, 418, 0xba72fc16, S=1, Skip Samples, 10, 0x06020101 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
