From: Raphael Schlarb <info@raphael.schlarb.one>
To: ffmpeg-devel@ffmpeg.org
Cc: Raphael Schlarb <info@raphael.schlarb.one>
Subject: [FFmpeg-devel] [PATCH v2] Add option to set frame length when encoding with libfdk_aac
Date: Mon, 27 Mar 2023 16:37:05 +0200
Message-ID: <20230327143705.2371-1-info@raphael.schlarb.one> (raw)
In-Reply-To: <dacdb965-e2e4-abbf-3da5-31f2498f5579@gmail.com>
Some specifications require the size of ld/eld frames to be 480 samples
instead of the default 512. libfdk_aac provides an option to set an alternative
frame size, but it's not exposed via the ffmpeg interface.
This patch adds a frame_length option to solve this problem.
---
Thank you, this really makes more sense. Here an updated version.
libavcodec/libfdk-aacenc.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/libavcodec/libfdk-aacenc.c b/libavcodec/libfdk-aacenc.c
index eb97e0fb41..93c26ee082 100644
--- a/libavcodec/libfdk-aacenc.c
+++ b/libavcodec/libfdk-aacenc.c
@@ -55,6 +55,7 @@ typedef struct AACContext {
int metadata_mode;
AACENC_MetaData metaDataSetup;
int delay_sent;
+ int frame_length;
AudioFrameQueue afq;
} AACContext;
@@ -78,6 +79,7 @@ static const AVOption aac_enc_options[] = {
{ "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 },
+ { "frame_length", "The desired frame length", offsetof(AACContext, frame_length), AV_OPT_TYPE_INT, { .i64 = 1024 }, 120, 1024, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM },
FF_AAC_PROFILE_OPTS
{ NULL }
};
@@ -166,6 +168,18 @@ static av_cold int aac_encode_init(AVCodecContext *avctx)
}
}
+ if (s->frame_length == 1024 &&
+ (aot == FF_PROFILE_AAC_LD + 1 || aot == FF_PROFILE_AAC_ELD + 1)) {
+ s->frame_length = 512;
+ }
+
+ if ((err = aacEncoder_SetParam(s->handle, AACENC_GRANULE_LENGTH,
+ s->frame_length)) != AACENC_OK) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to set granule length: %s\n",
+ aac_get_error(err));
+ goto error;
+ }
+
if ((err = aacEncoder_SetParam(s->handle, AACENC_SAMPLERATE,
avctx->sample_rate)) != AACENC_OK) {
av_log(avctx, AV_LOG_ERROR, "Unable to set the sample rate %d: %s\n",
--
2.40.0
_______________________________________________
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".
next prev parent reply other threads:[~2023-03-27 14:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 12:28 [FFmpeg-devel] [PATCH] Add option to encode short aac ld/eld frames " Raphael Schlarb
2023-03-27 12:39 ` James Almer
2023-03-27 14:37 ` Raphael Schlarb [this message]
2023-03-29 15:59 ` [FFmpeg-devel] [PATCH v3] avcodec/libfdk-accenc: Add option to set frame length when encoding " Raphael Schlarb
2023-03-30 20:30 ` Martin Storsjö
2023-03-30 12:27 ` [FFmpeg-devel] [PATCH v4] " Raphael Schlarb
2023-03-31 6:51 ` Martin Storsjö
2023-03-31 11:54 ` James Almer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230327143705.2371-1-info@raphael.schlarb.one \
--to=info@raphael.schlarb.one \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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