From 3440a901baaf3307cc1f37b0590458bc08162e94 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Thu, 10 Apr 2025 22:20:33 +0200 Subject: [PATCH 13/15] avcodec/mpegaudioenc: Don't pad one bit at a time Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/mpegaudioenc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/mpegaudioenc.c b/libavcodec/mpegaudioenc.c index 9a6aae6f78..49255b7f29 100644 --- a/libavcodec/mpegaudioenc.c +++ b/libavcodec/mpegaudioenc.c @@ -743,9 +743,12 @@ static void encode_frame(MpegAudioContext *s, av_assert1(put_bits_left(p) == padding); + /* flush */ + flush_put_bits(p); + /* padding */ - for(i=0;i<padding;i++) - put_bits(p, 1, 0); + if (put_bytes_left(p, 0)) + memset(put_bits_ptr(p), 0, put_bytes_left(p, 0)); } static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, @@ -778,9 +781,6 @@ static int MPA_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, encode_frame(s, bit_alloc, padding); - /* flush */ - flush_put_bits(&s->pb); - if (frame->pts != AV_NOPTS_VALUE) avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding); -- 2.45.2