PR #20721 opened by cenzhanquan1 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20721 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20721.patch
Previously, the LC3 encoder only accepted planar float (AV_SAMPLE_FMT_FLTP). This change extends support to packed float (AV_SAMPLE_FMT_FLT) by properly handling channel layout and sample stride. The pcm data pointer and stride are now calculated based on the sample format: for planar, use frame->data[ch]; for packed, use frame->data[0] with channel offset. The stride is set to 1 for planar and number of channels for packed layout. This enables encoding from common packed audio sources without requiring a prior planar conversion, improving usability and efficiency. Signed-off-by: cenzhanquan1 <[email protected]> >From cbf757c112f67b8835ee56718954a697a7c06330 Mon Sep 17 00:00:00 2001 From: cenzhanquan1 <[email protected]> Date: Mon, 20 Oct 2025 12:04:01 +0800 Subject: [PATCH] avcodec/liblc3enc: support packed float (AV_SAMPLE_FMT_FLT) input. Previously, the LC3 encoder only accepted planar float (AV_SAMPLE_FMT_FLTP). This change extends support to packed float (AV_SAMPLE_FMT_FLT) by properly handling channel layout and sample stride. The pcm data pointer and stride are now calculated based on the sample format: for planar, use frame->data[ch]; for packed, use frame->data[0] with channel offset. The stride is set to 1 for planar and number of channels for packed layout. This enables encoding from common packed audio sources without requiring a prior planar conversion, improving usability and efficiency. Signed-off-by: cenzhanquan1 <[email protected]> --- libavcodec/liblc3enc.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libavcodec/liblc3enc.c b/libavcodec/liblc3enc.c index 72c117b993..2c4dff7761 100644 --- a/libavcodec/liblc3enc.c +++ b/libavcodec/liblc3enc.c @@ -138,8 +138,13 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, int block_bytes = liblc3->block_bytes; int channels = avctx->ch_layout.nb_channels; uint8_t *data_ptr; + size_t sample_size; + int is_planar; int ret; + is_planar = av_sample_fmt_is_planar(avctx->sample_fmt); + sample_size = av_get_bytes_per_sample(avctx->sample_fmt); + if ((ret = ff_get_encode_buffer(avctx, pkt, block_bytes, 0)) < 0) return ret; @@ -155,10 +160,15 @@ static int liblc3_encode(AVCodecContext *avctx, AVPacket *pkt, data_ptr = pkt->data; for (int ch = 0; ch < channels; ch++) { - const float *pcm = frame ? (const float*)frame->data[ch] : (const float[]){ 0 }; - int stride = !!frame; // use a stride of zero to send a zero frame int nbytes = block_bytes / channels + (ch < block_bytes % channels); + const void *pcm = frame ? + (is_planar ? frame->data[ch] : + (uint8_t *)frame->data[0] + ch * sample_size) : + (const void *)(const float[]){ 0 }; + + int stride = frame ? (is_planar ? 1 : channels) : 0; + lc3_encode(liblc3->encoder[ch], LC3_PCM_FORMAT_FLOAT, pcm, stride, nbytes, data_ptr); @@ -198,7 +208,7 @@ const FFCodec ff_liblc3_encoder = { .p.priv_class = &class, .p.wrapper_name = "liblc3", CODEC_SAMPLERATES(96000, 48000, 32000, 24000, 16000, 8000), - CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP), + CODEC_SAMPLEFMTS(AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_FLT), .priv_data_size = sizeof(LibLC3EncContext), .init = liblc3_encode_init, .close = liblc3_encode_close, -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
