Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
       [not found] <63F985BE.06260C.50083@loongson.cn>
@ 2023-02-27  1:22 ` JonHGee
  2023-02-28 14:10   ` Martin Storsjö
  0 siblings, 1 reply; 7+ messages in thread
From: JonHGee @ 2023-02-27  1:22 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: JonHGee

Added basic DRC options and ref levels to AV options. 
If any options are selected, metadata mode is set accordingly 
and metadata is added to input buffer per FDK encoder API.

---
 libavcodec/libfdk-aacenc.c | 72 ++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 14 deletions(-)

diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 54549de473..4e67b1ece3 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -46,6 +46,12 @@ typedef struct AACContext {
     int latm;
     int header_period;
     int vbr;
+    int drc_profile;
+    int drc_target_ref;
+    int comp_profile;
+    int comp_target_ref;
+    int prog_ref;
+    AACENC_MetaData metaDataSetup;
 
     AudioFrameQueue afq;
 } AACContext;
@@ -64,6 +70,11 @@ static const AVOption aac_enc_options[] = {
     { "latm", "Output LATM/LOAS encapsulated data", offsetof(AACContext, latm), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     { "header_period", "StreamMuxConfig and PCE repetition period (in frames)", offsetof(AACContext, header_period), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xffff, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     { "vbr", "VBR mode (1-5)", offsetof(AACContext, vbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+        { "drc_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, drc_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "drc_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, drc_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "comp_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, comp_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "comp_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, comp_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "prog_ref", "The program reference level or dialog level in dB", offsetof(AACContext, prog_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     FF_AAC_PROFILE_OPTS
     { NULL }
 };
@@ -127,6 +138,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     AACENC_ERROR err;
     int aot = FF_PROFILE_AAC_LOW + 1;
     int sce = 0, cpe = 0;
+    int metadata_mode = 0;
 
     if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
         av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
@@ -319,6 +331,29 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
         }
     }
 
+    if (s->prog_ref) {
+        metadata_mode = 1;
+        s->metaDataSetup.prog_ref_level_present = 1;
+        s->metaDataSetup.prog_ref_level = s->prog_ref << 16;
+    }
+    if (s->drc_profile) {
+        metadata_mode = 1;
+        s->metaDataSetup.drc_profile = s->drc_profile;
+        s->metaDataSetup.drc_TargetRefLevel = s->drc_target_ref << 16;
+        if (s->comp_profile) {
+            // Including the comp_profile means that we need to set the mode to ETSI
+            metadata_mode = 2;
+            s->metaDataSetup.comp_profile = s->comp_profile;
+            s->metaDataSetup.comp_TargetRefLevel = s->comp_target_ref << 16;
+        }
+    }
+
+    if ((err = aacEncoder_SetParam(s->handle, AACENC_METADATA_MODE, metadata_mode)) != AACENC_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to set metadata mode to %d: %s\n",
+                metadata_mode, aac_get_error(err));
+        goto error;
+    }
+
     if ((err = aacEncEncode(s->handle, NULL, NULL, NULL, NULL)) != AACENC_OK) {
         av_log(avctx, AV_LOG_ERROR, "Unable to initialize the encoder: %s\n",
                aac_get_error(err));
@@ -363,11 +398,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     AACENC_BufDesc in_buf   = { 0 }, out_buf = { 0 };
     AACENC_InArgs  in_args  = { 0 };
     AACENC_OutArgs out_args = { 0 };
-    int in_buffer_identifier = IN_AUDIO_DATA;
-    int in_buffer_size, in_buffer_element_size;
+    void* inBuffer[] = { 0, &s->metaDataSetup };
+    int in_buffer_identifiers[] = { IN_AUDIO_DATA, IN_METADATA_SETUP };
+    int in_buffer_element_sizes[]   = { 2, sizeof(AACENC_MetaData) };
+    int in_buffer_sizes[] = { 0 , sizeof(s->metaDataSetup) };
+    void *out_ptr;
     int out_buffer_identifier = OUT_BITSTREAM_DATA;
     int out_buffer_size, out_buffer_element_size;
-    void *in_ptr, *out_ptr;
     int ret;
     uint8_t dummy_buf[1];
     AACENC_ERROR err;
@@ -376,27 +413,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if (!frame) {
         /* Must be a non-null pointer, even if it's a dummy. We could use
          * the address of anything else on the stack as well. */
-        in_ptr               = dummy_buf;
-        in_buffer_size       = 0;
+        inBuffer[0]               = dummy_buf;
 
         in_args.numInSamples = -1;
     } else {
-        in_ptr               = frame->data[0];
-        in_buffer_size       = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
+        inBuffer[0]               = frame->data[0];
+        in_buffer_sizes[0]       = 2 * avctx->channels * frame->nb_samples;
 
-        in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
+        in_args.numInSamples = avctx->channels * frame->nb_samples;
 
         /* add current frame to the queue */
         if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
             return ret;
     }
 
-    in_buffer_element_size   = 2;
-    in_buf.numBufs           = 1;
-    in_buf.bufs              = &in_ptr;
-    in_buf.bufferIdentifiers = &in_buffer_identifier;
-    in_buf.bufSizes          = &in_buffer_size;
-    in_buf.bufElSizes        = &in_buffer_element_size;
+    // Only use audio input data if metadata mode is none.
+    if (aacEncoder_GetParam(s->handle, AACENC_METADATA_MODE) == 0) {
+        in_buf.numBufs           = 1;
+        in_buf.bufs              = &inBuffer[0];
+        in_buf.bufferIdentifiers = &in_buffer_identifiers[0];
+        in_buf.bufSizes          = &in_buffer_sizes[0];
+        in_buf.bufElSizes        = &in_buffer_element_sizes[0];
+    } else {
+        in_buf.numBufs           = 2;
+        in_buf.bufs              = (void**)&inBuffer;
+        in_buf.bufferIdentifiers = &in_buffer_identifiers;
+        in_buf.bufSizes          = &in_buffer_sizes;
+        in_buf.bufElSizes        = &in_buffer_element_sizes;
+    }
 
     /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
     ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels));
-- 
2.39.2.637.g21b0678d19-goog

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
  2023-02-27  1:22 ` [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata JonHGee
@ 2023-02-28 14:10   ` Martin Storsjö
  2023-02-28 21:25     ` JonHGee
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Storsjö @ 2023-02-28 14:10 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: JonHGee

On Mon, 27 Feb 2023, JonHGee wrote:

> Added basic DRC options and ref levels to AV options.
> If any options are selected, metadata mode is set accordingly
> and metadata is added to input buffer per FDK encoder API.
>
> ---
> libavcodec/libfdk-aacenc.c | 72 ++++++++++++++++++++++++++++++--------
> 1 file changed, 58 insertions(+), 14 deletions(-)
>
> diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
> index 54549de473..4e67b1ece3 100644
> --- a/libavcodec/libfdk-aacenc.c
> +++ b/libavcodec/libfdk-aacenc.c
> @@ -46,6 +46,12 @@ typedef struct AACContext {
>     int latm;
>     int header_period;
>     int vbr;
> +    int drc_profile;
> +    int drc_target_ref;
> +    int comp_profile;
> +    int comp_target_ref;
> +    int prog_ref;
> +    AACENC_MetaData metaDataSetup;
>
>     AudioFrameQueue afq;
> } AACContext;
> @@ -64,6 +70,11 @@ static const AVOption aac_enc_options[] = {
>     { "latm", "Output LATM/LOAS encapsulated data", offsetof(AACContext, latm), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
>     { "header_period", "StreamMuxConfig and PCE repetition period (in frames)", offsetof(AACContext, header_period), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xffff, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
>     { "vbr", "VBR mode (1-5)", offsetof(AACContext, vbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +        { "drc_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, drc_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },

The indentation of this line is a bit off

> +    { "drc_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, drc_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +    { "comp_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, comp_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +    { "comp_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, comp_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +    { "prog_ref", "The program reference level or dialog level in dB", offsetof(AACContext, prog_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
>     FF_AAC_PROFILE_OPTS
>     { NULL }
> };
> @@ -127,6 +138,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>     AACENC_ERROR err;
>     int aot = FF_PROFILE_AAC_LOW + 1;
>     int sce = 0, cpe = 0;
> +    int metadata_mode = 0;
>
>     if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
>         av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
> @@ -319,6 +331,29 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>         }
>     }
>
> +    if (s->prog_ref) {
> +        metadata_mode = 1;
> +        s->metaDataSetup.prog_ref_level_present = 1;
> +        s->metaDataSetup.prog_ref_level = s->prog_ref << 16;
> +    }
> +    if (s->drc_profile) {
> +        metadata_mode = 1;
> +        s->metaDataSetup.drc_profile = s->drc_profile;
> +        s->metaDataSetup.drc_TargetRefLevel = s->drc_target_ref << 16;
> +        if (s->comp_profile) {
> +            // Including the comp_profile means that we need to set the mode to ETSI
> +            metadata_mode = 2;
> +            s->metaDataSetup.comp_profile = s->comp_profile;
> +            s->metaDataSetup.comp_TargetRefLevel = s->comp_target_ref << 16;
> +        }
> +    }
> +
> +    if ((err = aacEncoder_SetParam(s->handle, AACENC_METADATA_MODE, metadata_mode)) != AACENC_OK) {
> +        av_log(avctx, AV_LOG_ERROR, "Unable to set metadata mode to %d: %s\n",
> +                metadata_mode, aac_get_error(err));
> +        goto error;
> +    }
> +
>     if ((err = aacEncEncode(s->handle, NULL, NULL, NULL, NULL)) != AACENC_OK) {
>         av_log(avctx, AV_LOG_ERROR, "Unable to initialize the encoder: %s\n",
>                aac_get_error(err));
> @@ -363,11 +398,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>     AACENC_BufDesc in_buf   = { 0 }, out_buf = { 0 };
>     AACENC_InArgs  in_args  = { 0 };
>     AACENC_OutArgs out_args = { 0 };
> -    int in_buffer_identifier = IN_AUDIO_DATA;
> -    int in_buffer_size, in_buffer_element_size;
> +    void* inBuffer[] = { 0, &s->metaDataSetup };
> +    int in_buffer_identifiers[] = { IN_AUDIO_DATA, IN_METADATA_SETUP };
> +    int in_buffer_element_sizes[]   = { 2, sizeof(AACENC_MetaData) };

Weird extra whitespace here

> +    int in_buffer_sizes[] = { 0 , sizeof(s->metaDataSetup) };
> +    void *out_ptr;
>     int out_buffer_identifier = OUT_BITSTREAM_DATA;
>     int out_buffer_size, out_buffer_element_size;
> -    void *in_ptr, *out_ptr;
>     int ret;
>     uint8_t dummy_buf[1];
>     AACENC_ERROR err;
> @@ -376,27 +413,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>     if (!frame) {
>         /* Must be a non-null pointer, even if it's a dummy. We could use
>          * the address of anything else on the stack as well. */
> -        in_ptr               = dummy_buf;
> -        in_buffer_size       = 0;
> +        inBuffer[0]               = dummy_buf;
>
>         in_args.numInSamples = -1;

The whitespace (for keeping the = vertically aligned) end up weird here, 
please remove whitespace to keep them aligned (or remove the extra 
whitespace altogether).


>     } else {
> -        in_ptr               = frame->data[0];
> -        in_buffer_size       = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
> +        inBuffer[0]               = frame->data[0];
> +        in_buffer_sizes[0]       = 2 * avctx->channels * frame->nb_samples;
>
> -        in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
> +        in_args.numInSamples = avctx->channels * frame->nb_samples;

Your patch reverts the changes to the new channel layout API, which causes 
warnings when compiling, saying that the channels field is deprecated; 
please remove such unrelated changes from the patch.

>
>         /* add current frame to the queue */
>         if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
>             return ret;
>     }
>
> -    in_buffer_element_size   = 2;
> -    in_buf.numBufs           = 1;
> -    in_buf.bufs              = &in_ptr;
> -    in_buf.bufferIdentifiers = &in_buffer_identifier;
> -    in_buf.bufSizes          = &in_buffer_size;
> -    in_buf.bufElSizes        = &in_buffer_element_size;
> +    // Only use audio input data if metadata mode is none.
> +    if (aacEncoder_GetParam(s->handle, AACENC_METADATA_MODE) == 0) {

Is it better/more convenient to keep track of this value, what we set it 
to, in our context, instead of having to query the encoder library each 
time? Not sure, but maybe..?

> +        in_buf.numBufs           = 1;
> +        in_buf.bufs              = &inBuffer[0];
> +        in_buf.bufferIdentifiers = &in_buffer_identifiers[0];
> +        in_buf.bufSizes          = &in_buffer_sizes[0];
> +        in_buf.bufElSizes        = &in_buffer_element_sizes[0];
> +    } else {
> +        in_buf.numBufs           = 2;
> +        in_buf.bufs              = (void**)&inBuffer;
> +        in_buf.bufferIdentifiers = &in_buffer_identifiers;
> +        in_buf.bufSizes          = &in_buffer_sizes;
> +        in_buf.bufElSizes        = &in_buffer_element_sizes;
> +    }

The & in e.g. &in_buffer_identifiers here, causes these compile warnings 
with Clang:

src/libavcodec/libfdk-aacenc.c:440:34: warning: incompatible pointer types 
assigning to 'INT *' (aka 'int *') from 'int (*)[2]' 
[-Wincompatible-pointer-types]
         in_buf.bufferIdentifiers = &in_buffer_identifiers;
                                  ^ ~~~~~~~~~~~~~~~~~~~~~~

Additionally - &in_buffer_identifiers[0] and in_buffer_identifiers 
evaluate to essentially the same thing. So as long as the first element of 
the arrays have been initialized properly, there's no need to keep these 
assignments within the if/else - just set the same pointers to arrays in 
either case, and just set numBufs to 1 or 2 depending on the case.

Apart from that, the change seems mostly reasonable from a functional 
point of view.

// Martin

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
  2023-02-28 14:10   ` Martin Storsjö
@ 2023-02-28 21:25     ` JonHGee
  2023-02-28 21:34       ` Martin Storsjö
  0 siblings, 1 reply; 7+ messages in thread
From: JonHGee @ 2023-02-28 21:25 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: JonHGee

Signed-off-by: JonHGee <JonHGee@gmail.com>
---
 libavcodec/libfdk-aacenc.c | 69 +++++++++++++++++++++++++++++++-------
 1 file changed, 56 insertions(+), 13 deletions(-)

diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 54549de473..123dabf3ae 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -46,6 +46,13 @@ typedef struct AACContext {
     int latm;
     int header_period;
     int vbr;
+    int drc_profile;
+    int drc_target_ref;
+    int comp_profile;
+    int comp_target_ref;
+    int prog_ref;
+    int metadata_mode;
+    AACENC_MetaData metaDataSetup;
 
     AudioFrameQueue afq;
 } AACContext;
@@ -64,6 +71,11 @@ static const AVOption aac_enc_options[] = {
     { "latm", "Output LATM/LOAS encapsulated data", offsetof(AACContext, latm), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     { "header_period", "StreamMuxConfig and PCE repetition period (in frames)", offsetof(AACContext, header_period), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xffff, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     { "vbr", "VBR mode (1-5)", offsetof(AACContext, vbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+        { "drc_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, drc_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "drc_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, drc_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "comp_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, comp_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "comp_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, comp_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "prog_ref", "The program reference level or dialog level in dB", offsetof(AACContext, prog_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     FF_AAC_PROFILE_OPTS
     { NULL }
 };
@@ -319,6 +331,30 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
         }
     }
 
+    s->metadata_mode = 0;
+    if (s->prog_ref) {
+        s->metadata_mode = 1;
+        s->metaDataSetup.prog_ref_level_present = 1;
+        s->metaDataSetup.prog_ref_level = s->prog_ref << 16;
+    }
+    if (s->drc_profile) {
+        s->metadata_mode = 1;
+        s->metaDataSetup.drc_profile = s->drc_profile;
+        s->metaDataSetup.drc_TargetRefLevel = s->drc_target_ref << 16;
+        if (s->comp_profile) {
+            /* Including the comp_profile means that we need to set the mode to ETSI */
+            s->metadata_mode = 2;
+            s->metaDataSetup.comp_profile = s->comp_profile;
+            s->metaDataSetup.comp_TargetRefLevel = s->comp_target_ref << 16;
+        }
+    }
+
+    if ((err = aacEncoder_SetParam(s->handle, AACENC_METADATA_MODE, s->metadata_mode)) != AACENC_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to set metadata mode to %d: %s\n",
+                s->metadata_mode, aac_get_error(err));
+        goto error;
+    }
+
     if ((err = aacEncEncode(s->handle, NULL, NULL, NULL, NULL)) != AACENC_OK) {
         av_log(avctx, AV_LOG_ERROR, "Unable to initialize the encoder: %s\n",
                aac_get_error(err));
@@ -363,11 +399,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     AACENC_BufDesc in_buf   = { 0 }, out_buf = { 0 };
     AACENC_InArgs  in_args  = { 0 };
     AACENC_OutArgs out_args = { 0 };
-    int in_buffer_identifier = IN_AUDIO_DATA;
-    int in_buffer_size, in_buffer_element_size;
+    void* inBuffer[] = { 0, &s->metaDataSetup };
+    int in_buffer_identifiers[] = { IN_AUDIO_DATA, IN_METADATA_SETUP };
+    int in_buffer_element_sizes[]   = { 2, sizeof(AACENC_MetaData) };
+    int in_buffer_sizes[] = { 0 , sizeof(s->metaDataSetup) };
+    void *out_ptr;
     int out_buffer_identifier = OUT_BITSTREAM_DATA;
     int out_buffer_size, out_buffer_element_size;
-    void *in_ptr, *out_ptr;
     int ret;
     uint8_t dummy_buf[1];
     AACENC_ERROR err;
@@ -376,13 +414,12 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if (!frame) {
         /* Must be a non-null pointer, even if it's a dummy. We could use
          * the address of anything else on the stack as well. */
-        in_ptr               = dummy_buf;
-        in_buffer_size       = 0;
+        inBuffer[0]          = dummy_buf;
 
         in_args.numInSamples = -1;
     } else {
-        in_ptr               = frame->data[0];
-        in_buffer_size       = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
+        inBuffer[0]          = frame->data[0];
+        in_buffer_sizes[0]   = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
 
         in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
 
@@ -391,12 +428,18 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             return ret;
     }
 
-    in_buffer_element_size   = 2;
-    in_buf.numBufs           = 1;
-    in_buf.bufs              = &in_ptr;
-    in_buf.bufferIdentifiers = &in_buffer_identifier;
-    in_buf.bufSizes          = &in_buffer_size;
-    in_buf.bufElSizes        = &in_buffer_element_size;
+    /* Only use audio input data if metadata mode is none. */
+    if (s->metadata_mode == 0) {
+        in_buf.numBufs       = 1;
+
+    } else {
+        in_buf.numBufs       = 2;
+    }
+
+    in_buf.bufs              = (void**)inBuffer;
+    in_buf.bufferIdentifiers = in_buffer_identifiers;
+    in_buf.bufSizes          = in_buffer_sizes;
+    in_buf.bufElSizes        = in_buffer_element_sizes;
 
     /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
     ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels));
-- 
2.39.2.722.g9855ee24e9-goog

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
  2023-02-28 21:25     ` JonHGee
@ 2023-02-28 21:34       ` Martin Storsjö
  2023-02-28 22:08         ` Jonathan Gee
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Storsjö @ 2023-02-28 21:34 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: JonHGee

On Tue, 28 Feb 2023, JonHGee wrote:

> Signed-off-by: JonHGee <JonHGee@gmail.com>
> ---
> libavcodec/libfdk-aacenc.c | 69 +++++++++++++++++++++++++++++++-------
> 1 file changed, 56 insertions(+), 13 deletions(-)
>
> diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
> index 54549de473..123dabf3ae 100644
> --- a/libavcodec/libfdk-aacenc.c
> +++ b/libavcodec/libfdk-aacenc.c
> @@ -46,6 +46,13 @@ typedef struct AACContext {
>     int latm;
>     int header_period;
>     int vbr;
> +    int drc_profile;
> +    int drc_target_ref;
> +    int comp_profile;
> +    int comp_target_ref;
> +    int prog_ref;
> +    int metadata_mode;
> +    AACENC_MetaData metaDataSetup;
>
>     AudioFrameQueue afq;
> } AACContext;
> @@ -64,6 +71,11 @@ static const AVOption aac_enc_options[] = {
>     { "latm", "Output LATM/LOAS encapsulated data", offsetof(AACContext, latm), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
>     { "header_period", "StreamMuxConfig and PCE repetition period (in frames)", offsetof(AACContext, header_period), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xffff, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
>     { "vbr", "VBR mode (1-5)", offsetof(AACContext, vbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +        { "drc_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, drc_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },

The indentation is still off here

> +    { "drc_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, drc_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +    { "comp_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, comp_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +    { "comp_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, comp_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
> +    { "prog_ref", "The program reference level or dialog level in dB", offsetof(AACContext, prog_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
>     FF_AAC_PROFILE_OPTS
>     { NULL }
> };
> @@ -319,6 +331,30 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
>         }
>     }
>
> +    s->metadata_mode = 0;
> +    if (s->prog_ref) {
> +        s->metadata_mode = 1;
> +        s->metaDataSetup.prog_ref_level_present = 1;
> +        s->metaDataSetup.prog_ref_level = s->prog_ref << 16;
> +    }
> +    if (s->drc_profile) {
> +        s->metadata_mode = 1;
> +        s->metaDataSetup.drc_profile = s->drc_profile;
> +        s->metaDataSetup.drc_TargetRefLevel = s->drc_target_ref << 16;
> +        if (s->comp_profile) {
> +            /* Including the comp_profile means that we need to set the mode to ETSI */
> +            s->metadata_mode = 2;
> +            s->metaDataSetup.comp_profile = s->comp_profile;
> +            s->metaDataSetup.comp_TargetRefLevel = s->comp_target_ref << 16;
> +        }
> +    }
> +
> +    if ((err = aacEncoder_SetParam(s->handle, AACENC_METADATA_MODE, s->metadata_mode)) != AACENC_OK) {
> +        av_log(avctx, AV_LOG_ERROR, "Unable to set metadata mode to %d: %s\n",
> +                s->metadata_mode, aac_get_error(err));
> +        goto error;
> +    }
> +
>     if ((err = aacEncEncode(s->handle, NULL, NULL, NULL, NULL)) != AACENC_OK) {
>         av_log(avctx, AV_LOG_ERROR, "Unable to initialize the encoder: %s\n",
>                aac_get_error(err));
> @@ -363,11 +399,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>     AACENC_BufDesc in_buf   = { 0 }, out_buf = { 0 };
>     AACENC_InArgs  in_args  = { 0 };
>     AACENC_OutArgs out_args = { 0 };
> -    int in_buffer_identifier = IN_AUDIO_DATA;
> -    int in_buffer_size, in_buffer_element_size;
> +    void* inBuffer[] = { 0, &s->metaDataSetup };
> +    int in_buffer_identifiers[] = { IN_AUDIO_DATA, IN_METADATA_SETUP };
> +    int in_buffer_element_sizes[]   = { 2, sizeof(AACENC_MetaData) };

Still have the extra weird whitespace here

> +    int in_buffer_sizes[] = { 0 , sizeof(s->metaDataSetup) };

Extra space before comma

> +    void *out_ptr;
>     int out_buffer_identifier = OUT_BITSTREAM_DATA;
>     int out_buffer_size, out_buffer_element_size;
> -    void *in_ptr, *out_ptr;
>     int ret;
>     uint8_t dummy_buf[1];
>     AACENC_ERROR err;
> @@ -376,13 +414,12 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>     if (!frame) {
>         /* Must be a non-null pointer, even if it's a dummy. We could use
>          * the address of anything else on the stack as well. */
> -        in_ptr               = dummy_buf;
> -        in_buffer_size       = 0;
> +        inBuffer[0]          = dummy_buf;
>
>         in_args.numInSamples = -1;
>     } else {
> -        in_ptr               = frame->data[0];
> -        in_buffer_size       = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
> +        inBuffer[0]          = frame->data[0];
> +        in_buffer_sizes[0]   = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
>
>         in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
>
> @@ -391,12 +428,18 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
>             return ret;
>     }
>
> -    in_buffer_element_size   = 2;
> -    in_buf.numBufs           = 1;
> -    in_buf.bufs              = &in_ptr;
> -    in_buf.bufferIdentifiers = &in_buffer_identifier;
> -    in_buf.bufSizes          = &in_buffer_size;
> -    in_buf.bufElSizes        = &in_buffer_element_size;
> +    /* Only use audio input data if metadata mode is none. */
> +    if (s->metadata_mode == 0) {
> +        in_buf.numBufs       = 1;
> +

Weird leftover empty line here. And the comment above feels oddly worded - 
I don't feel it's needed at all anymore.

> +    } else {
> +        in_buf.numBufs       = 2;
> +    }
> +
> +    in_buf.bufs              = (void**)inBuffer;
> +    in_buf.bufferIdentifiers = in_buffer_identifiers;
> +    in_buf.bufSizes          = in_buffer_sizes;
> +    in_buf.bufElSizes        = in_buffer_element_sizes;
>
>     /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
>     ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels));
> -- 
> 2.39.2.722.g9855ee24e9-goog

Looks mostly good to me now, thanks. I guess I can clean up the remaining 
few nitpicks without you having to resubmit the patch. So unless you 
disagree with the comments, I can push it with the minor touch-ups.

// Martin

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
  2023-02-28 21:34       ` Martin Storsjö
@ 2023-02-28 22:08         ` Jonathan Gee
  2023-02-28 22:16           ` Martin Storsjö
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Gee @ 2023-02-28 22:08 UTC (permalink / raw)
  To: FFmpeg development discussions and patches; +Cc: martin

> Looks mostly good to me now, thanks. I guess I can clean up the remaining
> few nitpicks without you having to resubmit the patch. So unless you
> disagree with the comments, I can push it with the minor touch-ups.
>
> // Martin
>

Sounds good to me.  No disagreements here.  Thank you for going over
the patch!
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
  2023-02-28 22:08         ` Jonathan Gee
@ 2023-02-28 22:16           ` Martin Storsjö
  0 siblings, 0 replies; 7+ messages in thread
From: Martin Storsjö @ 2023-02-28 22:16 UTC (permalink / raw)
  To: Jonathan Gee; +Cc: FFmpeg development discussions and patches

On Tue, 28 Feb 2023, Jonathan Gee wrote:

>> Looks mostly good to me now, thanks. I guess I can clean up the remaining
>> few nitpicks without you having to resubmit the patch. So unless you
>> disagree with the comments, I can push it with the minor touch-ups.
>>
>> // Martin
>>
>
> Sounds good to me.  No disagreements here.  Thank you for going over
> the patch!

Ok, pushed this one now then.

// Martin

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
@ 2023-02-25  3:39 JonHGee
  0 siblings, 0 replies; 7+ messages in thread
From: JonHGee @ 2023-02-25  3:39 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: JonHGee

Added basic DRC options and ref levels to AV options. If any options are selected, metadata mode is set accordingly and metadata is added to input buffer per FDK encoder API.

---
 libavcodec/libfdk-aacenc.c | 72 ++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 14 deletions(-)

diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index 54549de473..4e67b1ece3 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -46,6 +46,12 @@ typedef struct AACContext {
     int latm;
     int header_period;
     int vbr;
+    int drc_profile;
+    int drc_target_ref;
+    int comp_profile;
+    int comp_target_ref;
+    int prog_ref;
+    AACENC_MetaData metaDataSetup;
 
     AudioFrameQueue afq;
 } AACContext;
@@ -64,6 +70,11 @@ static const AVOption aac_enc_options[] = {
     { "latm", "Output LATM/LOAS encapsulated data", offsetof(AACContext, latm), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     { "header_period", "StreamMuxConfig and PCE repetition period (in frames)", offsetof(AACContext, header_period), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 0xffff, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     { "vbr", "VBR mode (1-5)", offsetof(AACContext, vbr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 5, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+        { "drc_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, drc_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "drc_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, drc_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "comp_profile", "The desired compression profile for AAC DRC", offsetof(AACContext, comp_profile), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 256, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "comp_target_ref", "Expected target reference level at decoder side in dB (for clipping prevention/limiter)", offsetof(AACContext, comp_target_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
+    { "prog_ref", "The program reference level or dialog level in dB", offsetof(AACContext, prog_ref), AV_OPT_TYPE_INT, { .i64 = 0.0 }, -31.75, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
     FF_AAC_PROFILE_OPTS
     { NULL }
 };
@@ -127,6 +138,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
     AACENC_ERROR err;
     int aot = FF_PROFILE_AAC_LOW + 1;
     int sce = 0, cpe = 0;
+    int metadata_mode = 0;
 
     if ((err = aacEncOpen(&s->handle, 0, avctx->ch_layout.nb_channels)) != AACENC_OK) {
         av_log(avctx, AV_LOG_ERROR, "Unable to open the encoder: %s\n",
@@ -319,6 +331,29 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
         }
     }
 
+    if (s->prog_ref) {
+        metadata_mode = 1;
+        s->metaDataSetup.prog_ref_level_present = 1;
+        s->metaDataSetup.prog_ref_level = s->prog_ref << 16;
+    }
+    if (s->drc_profile) {
+        metadata_mode = 1;
+        s->metaDataSetup.drc_profile = s->drc_profile;
+        s->metaDataSetup.drc_TargetRefLevel = s->drc_target_ref << 16;
+        if (s->comp_profile) {
+            // Including the comp_profile means that we need to set the mode to ETSI
+            metadata_mode = 2;
+            s->metaDataSetup.comp_profile = s->comp_profile;
+            s->metaDataSetup.comp_TargetRefLevel = s->comp_target_ref << 16;
+        }
+    }
+
+    if ((err = aacEncoder_SetParam(s->handle, AACENC_METADATA_MODE, metadata_mode)) != AACENC_OK) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to set metadata mode to %d: %s\n",
+                metadata_mode, aac_get_error(err));
+        goto error;
+    }
+
     if ((err = aacEncEncode(s->handle, NULL, NULL, NULL, NULL)) != AACENC_OK) {
         av_log(avctx, AV_LOG_ERROR, "Unable to initialize the encoder: %s\n",
                aac_get_error(err));
@@ -363,11 +398,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     AACENC_BufDesc in_buf   = { 0 }, out_buf = { 0 };
     AACENC_InArgs  in_args  = { 0 };
     AACENC_OutArgs out_args = { 0 };
-    int in_buffer_identifier = IN_AUDIO_DATA;
-    int in_buffer_size, in_buffer_element_size;
+    void* inBuffer[] = { 0, &s->metaDataSetup };
+    int in_buffer_identifiers[] = { IN_AUDIO_DATA, IN_METADATA_SETUP };
+    int in_buffer_element_sizes[]   = { 2, sizeof(AACENC_MetaData) };
+    int in_buffer_sizes[] = { 0 , sizeof(s->metaDataSetup) };
+    void *out_ptr;
     int out_buffer_identifier = OUT_BITSTREAM_DATA;
     int out_buffer_size, out_buffer_element_size;
-    void *in_ptr, *out_ptr;
     int ret;
     uint8_t dummy_buf[1];
     AACENC_ERROR err;
@@ -376,27 +413,34 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
     if (!frame) {
         /* Must be a non-null pointer, even if it's a dummy. We could use
          * the address of anything else on the stack as well. */
-        in_ptr               = dummy_buf;
-        in_buffer_size       = 0;
+        inBuffer[0]               = dummy_buf;
 
         in_args.numInSamples = -1;
     } else {
-        in_ptr               = frame->data[0];
-        in_buffer_size       = 2 * avctx->ch_layout.nb_channels * frame->nb_samples;
+        inBuffer[0]               = frame->data[0];
+        in_buffer_sizes[0]       = 2 * avctx->channels * frame->nb_samples;
 
-        in_args.numInSamples = avctx->ch_layout.nb_channels * frame->nb_samples;
+        in_args.numInSamples = avctx->channels * frame->nb_samples;
 
         /* add current frame to the queue */
         if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
             return ret;
     }
 
-    in_buffer_element_size   = 2;
-    in_buf.numBufs           = 1;
-    in_buf.bufs              = &in_ptr;
-    in_buf.bufferIdentifiers = &in_buffer_identifier;
-    in_buf.bufSizes          = &in_buffer_size;
-    in_buf.bufElSizes        = &in_buffer_element_size;
+    // Only use audio input data if metadata mode is none.
+    if (aacEncoder_GetParam(s->handle, AACENC_METADATA_MODE) == 0) {
+        in_buf.numBufs           = 1;
+        in_buf.bufs              = &inBuffer[0];
+        in_buf.bufferIdentifiers = &in_buffer_identifiers[0];
+        in_buf.bufSizes          = &in_buffer_sizes[0];
+        in_buf.bufElSizes        = &in_buffer_element_sizes[0];
+    } else {
+        in_buf.numBufs           = 2;
+        in_buf.bufs              = (void**)&inBuffer;
+        in_buf.bufferIdentifiers = &in_buffer_identifiers;
+        in_buf.bufSizes          = &in_buffer_sizes;
+        in_buf.bufElSizes        = &in_buffer_element_sizes;
+    }
 
     /* The maximum packet size is 6144 bits aka 768 bytes per channel. */
     ret = ff_alloc_packet(avctx, avpkt, FFMAX(8192, 768 * avctx->ch_layout.nb_channels));
-- 
2.39.2.637.g21b0678d19-goog

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-28 22:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <63F985BE.06260C.50083@loongson.cn>
2023-02-27  1:22 ` [FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata JonHGee
2023-02-28 14:10   ` Martin Storsjö
2023-02-28 21:25     ` JonHGee
2023-02-28 21:34       ` Martin Storsjö
2023-02-28 22:08         ` Jonathan Gee
2023-02-28 22:16           ` Martin Storsjö
2023-02-25  3:39 JonHGee

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git