[FFmpeg-devel] [PATCH] Scale libFDK encoder VBR mode with FF_QP2LAMBDA
VBR mode currently does not account for scaling when using -aq options with libfdk, resulting in clamping to vbr mode 5 whenever a value >0 is provided. Adjusting for the scaling factor for proper VBR support. --- libavcodec/libfdk-aacenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 54549de473..da211baf51 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -230,7 +230,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } if (avctx->flags & AV_CODEC_FLAG_QSCALE || s->vbr) { -int mode = s->vbr ? s->vbr : avctx->global_quality; +int mode = s->vbr ? s->vbr : avctx->global_quality / FF_QP2LAMBDA; if (mode < 1 || mode > 5) { av_log(avctx, AV_LOG_WARNING, "VBR quality %d out of range, should be 1-5\n", mode); -- 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Scale VBR mode with FF_QP2LAMBDA
libavcodec/libfdk-aacenc: VBR mode currently does not account for scaling when using -aq options with libfdk, resulting in clamping to vbr mode 5 whenever a value >0 is provided. Adjusting for the scaling factor for proper VBR support. --- libavcodec/libfdk-aacenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 54549de473..da211baf51 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -230,7 +230,7 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } if (avctx->flags & AV_CODEC_FLAG_QSCALE || s->vbr) { -int mode = s->vbr ? s->vbr : avctx->global_quality; +int mode = s->vbr ? s->vbr : avctx->global_quality / FF_QP2LAMBDA; if (mode < 1 || mode > 5) { av_log(avctx, AV_LOG_WARNING, "VBR quality %d out of range, should be 1-5\n", mode); -- 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavcodec/libfdk-aacnc: send encoder delay/padding in packet side data
--- libavcodec/libfdk-aacenc.c | 27 ++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 54549de473..55d10990e4 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -21,6 +21,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/common.h" +#include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "avcodec.h" #include "audio_frame_queue.h" @@ -46,6 +47,7 @@ typedef struct AACContext { int latm; int header_period; int vbr; +int delay_sent; AudioFrameQueue afq; } AACContext; @@ -368,7 +370,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int out_buffer_identifier = OUT_BITSTREAM_DATA; int out_buffer_size, out_buffer_element_size; void *in_ptr, *out_ptr; -int ret; +int ret, discard_padding; uint8_t dummy_buf[1]; AACENC_ERROR err; @@ -428,6 +430,29 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); +discard_padding = avctx->frame_size - avpkt->duration; +// Check if subtraction resulted in an overflow +if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { +av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n"); +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(EINVAL); +} +if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) { +uint8_t *side_data = +av_packet_new_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, 10); +if (!side_data) { +av_packet_unref(avpkt); +av_free(avpkt); +return AVERROR(ENOMEM); +} +if (!s->delay_sent) { +AV_WL32(side_data, avctx->initial_padding); +s->delay_sent = 1; +} +AV_WL32(side_data + 4, discard_padding); +} + avpkt->size = out_args.numOutBytes; *got_packet_ptr = 1; return 0; -- 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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
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, 0x, 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(AVCodecContex
[FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
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, 0x, 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(AVCodecContex
[FFmpeg-devel] [PATCH] libavcodec/libfdk-aacenc: Enable writing DRC metadata
Signed-off-by: JonHGee --- 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, 0x, 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
[FFmpeg-devel] [PATCH] libavcodec/libfdk-aacnc: send encoder delay/padding in packet side data
Signed-off-by: JonHGee --- libavcodec/libfdk-aacenc.c | 25 - 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c index 54549de473..954ddab07f 100644 --- a/libavcodec/libfdk-aacenc.c +++ b/libavcodec/libfdk-aacenc.c @@ -21,6 +21,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/common.h" +#include "libavutil/intreadwrite.h" #include "libavutil/opt.h" #include "avcodec.h" #include "audio_frame_queue.h" @@ -46,6 +47,7 @@ typedef struct AACContext { int latm; int header_period; int vbr; +int delay_sent; AudioFrameQueue afq; } AACContext; @@ -368,7 +370,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, int out_buffer_identifier = OUT_BITSTREAM_DATA; int out_buffer_size, out_buffer_element_size; void *in_ptr, *out_ptr; -int ret; +int ret, discard_padding; uint8_t dummy_buf[1]; AACENC_ERROR err; @@ -428,6 +430,27 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts, &avpkt->duration); +discard_padding = avctx->frame_size - avpkt->duration; +// Check if subtraction resulted in an overflow +if ((discard_padding < avctx->frame_size) != (avpkt->duration > 0)) { +av_log(avctx, AV_LOG_ERROR, "discard padding overflow\n"); +av_packet_unref(avpkt); +return AVERROR(EINVAL); +} +if ((!s->delay_sent && avctx->initial_padding > 0) || discard_padding > 0) { +uint8_t *side_data = +av_packet_new_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, 10); +if (!side_data) { +av_packet_unref(avpkt); +return AVERROR(ENOMEM); +} +if (!s->delay_sent) { +AV_WL32(side_data, avctx->initial_padding); +s->delay_sent = 1; +} +AV_WL32(side_data + 4, discard_padding); +} + avpkt->size = out_args.numOutBytes; *got_packet_ptr = 1; return 0; -- 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-requ...@ffmpeg.org with subject "unsubscribe".