20 #include <fdk-aac/aacenc_lib.h>
32 #ifdef AACENCODER_LIB_VL0
33 #define FDKENC_VER_AT_LEAST(vl0, vl1) \
34 ((AACENCODER_LIB_VL0 > vl0) || \
35 (AACENCODER_LIB_VL0 == vl0 && AACENCODER_LIB_VL1 >= vl1))
37 #define FDKENC_VER_AT_LEAST(vl0, vl1) 0
64 {
"eld_sbr",
"Enable SBR for ELD (for SBR in other configurations, use the -profile parameter)", offsetof(
AACContext, eld_sbr),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1,
AV_OPT_FLAG_AUDIO_PARAM |
AV_OPT_FLAG_ENCODING_PARAM },
65 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
68 {
"signaling",
"SBR/PS signaling style", offsetof(
AACContext, signaling),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 2,
AV_OPT_FLAG_AUDIO_PARAM |
AV_OPT_FLAG_ENCODING_PARAM,
"signaling" },
69 {
"default",
"Choose signaling implicitly (explicit hierarchical by default, implicit if global header is disabled)", 0,
AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0,
AV_OPT_FLAG_AUDIO_PARAM |
AV_OPT_FLAG_ENCODING_PARAM,
"signaling" },
71 {
"explicit_sbr",
"Explicit SBR, implicit PS signaling", 0,
AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0,
AV_OPT_FLAG_AUDIO_PARAM |
AV_OPT_FLAG_ENCODING_PARAM,
"signaling" },
97 case AACENC_INVALID_HANDLE:
98 return "Invalid handle";
99 case AACENC_MEMORY_ERROR:
100 return "Memory allocation error";
101 case AACENC_UNSUPPORTED_PARAMETER:
102 return "Unsupported parameter";
103 case AACENC_INVALID_CONFIG:
104 return "Invalid config";
105 case AACENC_INIT_ERROR:
106 return "Initialization error";
107 case AACENC_INIT_AAC_ERROR:
108 return "AAC library initialization error";
109 case AACENC_INIT_SBR_ERROR:
110 return "SBR library initialization error";
111 case AACENC_INIT_TP_ERROR:
112 return "Transport library initialization error";
113 case AACENC_INIT_META_ERROR:
114 return "Metadata library initialization error";
115 case AACENC_ENCODE_ERROR:
116 return "Encoding error";
117 case AACENC_ENCODE_EOF:
118 return "End of file";
120 return "Unknown error";
129 aacEncClose(&
s->handle);
139 AACENC_InfoStruct
info = { 0 };
143 int sce = 0, cpe = 0;
154 if ((err = aacEncoder_SetParam(
s->handle, AACENC_AOT, aot)) != AACENC_OK) {
161 if ((err = aacEncoder_SetParam(
s->handle, AACENC_SBR_MODE,
169 if ((err = aacEncoder_SetParam(
s->handle, AACENC_SAMPLERATE,
177 case 1:
mode = MODE_1; sce = 1; cpe = 0;
break;
179 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
182 if ((err = aacEncoder_SetParam(
s->handle, AACENC_CHANNELMODE,
183 128)) != AACENC_OK) {
200 case 3:
mode = MODE_1_2; sce = 1; cpe = 1;
break;
201 case 4:
mode = MODE_1_2_1; sce = 2; cpe = 1;
break;
202 case 5:
mode = MODE_1_2_2; sce = 1; cpe = 2;
break;
203 case 6:
mode = MODE_1_2_2_1; sce = 2; cpe = 2;
break;
204 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
205 case 7:
mode = MODE_6_1; sce = 3; cpe = 2;
break;
209 #if FDKENC_VER_AT_LEAST(3, 4) // 3.4.12
214 mode = MODE_7_1_REAR_SURROUND;
215 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
217 mode = MODE_7_1_TOP_FRONT;
221 mode = MODE_7_1_FRONT_CENTER;
231 if ((err = aacEncoder_SetParam(
s->handle, AACENC_CHANNELMODE,
232 mode)) != AACENC_OK) {
238 if ((err = aacEncoder_SetParam(
s->handle, AACENC_CHANNELORDER,
241 "Unable to set wav channel order %d: %s\n",
250 "VBR quality %d out of range, should be 1-5\n",
mode);
254 "Note, the VBR setting is unsupported and only works with "
255 "some parameter combinations\n");
256 if ((err = aacEncoder_SetParam(
s->handle, AACENC_BITRATEMODE,
257 mode)) != AACENC_OK) {
275 if ((err = aacEncoder_SetParam(
s->handle, AACENC_BITRATE,
285 if ((err = aacEncoder_SetParam(
s->handle, AACENC_TRANSMUX,
287 s->latm ? TT_MP4_LOAS : TT_MP4_ADTS)) != AACENC_OK) {
293 if (
s->latm &&
s->header_period) {
294 if ((err = aacEncoder_SetParam(
s->handle, AACENC_HEADER_PERIOD,
295 s->header_period)) != AACENC_OK) {
305 if (
s->signaling < 0)
308 if ((err = aacEncoder_SetParam(
s->handle, AACENC_SIGNALING_MODE,
309 s->signaling)) != AACENC_OK) {
315 if ((err = aacEncoder_SetParam(
s->handle, AACENC_AFTERBURNER,
316 s->afterburner)) != AACENC_OK) {
328 if ((err = aacEncoder_SetParam(
s->handle, AACENC_BANDWIDTH,
329 avctx->
cutoff)) != AACENC_OK) {
336 s->metadata_mode = 0;
338 s->metadata_mode = 1;
339 s->metaDataSetup.prog_ref_level_present = 1;
340 s->metaDataSetup.prog_ref_level =
s->prog_ref << 16;
342 if (
s->drc_profile) {
343 s->metadata_mode = 1;
344 s->metaDataSetup.drc_profile =
s->drc_profile;
345 s->metaDataSetup.drc_TargetRefLevel =
s->drc_target_ref << 16;
346 if (
s->comp_profile) {
348 s->metadata_mode = 2;
349 s->metaDataSetup.comp_profile =
s->comp_profile;
350 s->metaDataSetup.comp_TargetRefLevel =
s->comp_target_ref << 16;
354 if ((err = aacEncoder_SetParam(
s->handle, AACENC_METADATA_MODE,
s->metadata_mode)) != AACENC_OK) {
366 if ((err = aacEncInfo(
s->handle, &
info)) != AACENC_OK) {
373 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
401 AACENC_BufDesc in_buf = { 0 }, out_buf = { 0 };
402 AACENC_InArgs in_args = { 0 };
403 AACENC_OutArgs out_args = { 0 };
404 void* inBuffer[] = { 0, &
s->metaDataSetup };
405 int in_buffer_identifiers[] = { IN_AUDIO_DATA, IN_METADATA_SETUP };
406 int in_buffer_element_sizes[] = { 2,
sizeof(AACENC_MetaData) };
407 int in_buffer_sizes[] = { 0,
sizeof(
s->metaDataSetup) };
408 int out_buffer_identifier = OUT_BITSTREAM_DATA;
409 int out_buffer_size, out_buffer_element_size;
411 int ret, discard_padding;
412 uint8_t dummy_buf[1];
419 inBuffer[0] = dummy_buf;
421 in_args.numInSamples = -1;
423 inBuffer[0] =
frame->data[0];
433 if (
s->metadata_mode == 0) {
439 in_buf.bufs = (
void**)inBuffer;
440 in_buf.bufferIdentifiers = in_buffer_identifiers;
441 in_buf.bufSizes = in_buffer_sizes;
442 in_buf.bufElSizes = in_buffer_element_sizes;
449 out_ptr = avpkt->
data;
450 out_buffer_size = avpkt->
size;
451 out_buffer_element_size = 1;
453 out_buf.bufs = &out_ptr;
454 out_buf.bufferIdentifiers = &out_buffer_identifier;
455 out_buf.bufSizes = &out_buffer_size;
456 out_buf.bufElSizes = &out_buffer_element_size;
458 if ((err = aacEncEncode(
s->handle, &in_buf, &out_buf, &in_args,
459 &out_args)) != AACENC_OK) {
460 if (!
frame && err == AACENC_ENCODE_EOF)
467 if (!out_args.numOutBytes)
480 if ((!
s->delay_sent && avctx->
initial_padding > 0) || discard_padding > 0) {
485 if (!
s->delay_sent) {
489 AV_WL32(side_data + 4, discard_padding);
492 avpkt->
size = out_args.numOutBytes;
511 #if FF_API_OLD_CHANNEL_LAYOUT
512 static const uint64_t aac_channel_layout[] = {
519 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
522 #if FDKENC_VER_AT_LEAST(3, 4) // 3.4.12
526 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
540 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
543 #if FDKENC_VER_AT_LEAST(3, 4) // 3.4.12
547 #if FDKENC_VER_AT_LEAST(4, 0) // 4.0.0
554 96000, 88200, 64000, 48000, 44100, 32000,
555 24000, 22050, 16000, 12000, 11025, 8000, 0
559 .
p.
name =
"libfdk_aac",
576 .p.wrapper_name =
"libfdk",