mirror of
https://github.com/nu774/fdkaac.git
synced 2025-06-05 23:29:14 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
2c116b15d5 | |||
e1adc17835 | |||
3c0f152d39 | |||
5732f1f6c5 |
50
ChangeLog
50
ChangeLog
@ -1,7 +1,55 @@
|
|||||||
2013-10-25 nu774 <honeycomb77@gmail.com>
|
2013-10-30 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
* update ChangeLog [HEAD]
|
* update ChangeLog [HEAD]
|
||||||
|
|
||||||
|
* bump version [v0.4.2]
|
||||||
|
|
||||||
|
* use tell() to obtain data chunk offset
|
||||||
|
|
||||||
|
* rename aacenc_result_t -> aacenc_frame_t, simplify write_sample()
|
||||||
|
|
||||||
|
* prepend 1 sample zero padding in case of SBR and enc_delay is odd
|
||||||
|
|
||||||
|
* cleanup interface of aac_encode_frame()
|
||||||
|
|
||||||
|
* add some copyright notice
|
||||||
|
|
||||||
|
2013-10-29 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* smart padding for better gapless playback
|
||||||
|
|
||||||
|
* fix unused variable warning
|
||||||
|
|
||||||
|
* fix warning: cast size_t as sprintf() arg to int
|
||||||
|
|
||||||
|
* fix vcxproj
|
||||||
|
|
||||||
|
* fix pcm_seek() to inline
|
||||||
|
|
||||||
|
2013-10-27 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* bump version [v0.4.1]
|
||||||
|
|
||||||
|
* add --include-sbr-delay
|
||||||
|
|
||||||
|
* fix help message: show -I as shorthand for --ignorelength
|
||||||
|
|
||||||
|
* remove --sbr-signaling
|
||||||
|
|
||||||
|
2013-10-26 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* re-fix #ifdef cond for lrint()
|
||||||
|
|
||||||
|
* tag mapping: add recorded date and tempo, remove performer->artist
|
||||||
|
|
||||||
|
2013-10-25 nu774 <honeycomb77@gmail.com>
|
||||||
|
|
||||||
|
* fix MSVC12 build issue
|
||||||
|
|
||||||
|
* fix build issue on platform where fileno is a naive macro
|
||||||
|
|
||||||
|
* update ChangeLog
|
||||||
|
|
||||||
* bump version [v0.4.0]
|
* bump version [v0.4.0]
|
||||||
|
|
||||||
* update README
|
* update README
|
||||||
|
81
src/aacenc.c
81
src/aacenc.c
@ -13,6 +13,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "aacenc.h"
|
#include "aacenc.h"
|
||||||
|
|
||||||
|
int aacenc_is_sbr_ratio_available()
|
||||||
|
{
|
||||||
|
#if AACENCODER_LIB_VL0 < 3 || (AACENCODER_LIB_VL0==3 && AACENCODER_LIB_VL1<4)
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
LIB_INFO lib_info;
|
||||||
|
aacenc_get_lib_info(&lib_info);
|
||||||
|
return lib_info.version > 0x03040000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int aacenc_is_sbr_active(const aacenc_param_t *params)
|
int aacenc_is_sbr_active(const aacenc_param_t *params)
|
||||||
{
|
{
|
||||||
switch (params->profile) {
|
switch (params->profile) {
|
||||||
@ -26,6 +37,33 @@ int aacenc_is_sbr_active(const aacenc_param_t *params)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int aacenc_is_dual_rate_sbr(const aacenc_param_t *params)
|
||||||
|
{
|
||||||
|
if (params->profile == AOT_PS || params->profile == AOT_MP2_PS)
|
||||||
|
return 1;
|
||||||
|
else if (params->profile == AOT_SBR || params->profile == AOT_MP2_SBR)
|
||||||
|
return params->sbr_ratio == 0 || params->sbr_ratio == 2;
|
||||||
|
else if (params->profile == AOT_ER_AAC_ELD && params->lowdelay_sbr)
|
||||||
|
return params->sbr_ratio == 2;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void aacenc_get_lib_info(LIB_INFO *info)
|
||||||
|
{
|
||||||
|
LIB_INFO *lib_info = 0;
|
||||||
|
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
||||||
|
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < FDK_MODULE_LAST; ++i) {
|
||||||
|
if (lib_info[i].module_id == FDK_AACENC) {
|
||||||
|
memcpy(info, &lib_info[i], sizeof(LIB_INFO));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(lib_info);
|
||||||
|
}
|
||||||
|
|
||||||
static const unsigned aacenc_sampling_freq_tab[] = {
|
static const unsigned aacenc_sampling_freq_tab[] = {
|
||||||
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
|
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
|
||||||
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
16000, 12000, 11025, 8000, 7350, 0, 0, 0
|
||||||
@ -50,10 +88,13 @@ int aacenc_mp4asc(const aacenc_param_t *params,
|
|||||||
uint8_t *outasc, uint32_t *outsize)
|
uint8_t *outasc, uint32_t *outsize)
|
||||||
{
|
{
|
||||||
unsigned asc_sfreq = aacenc_sampling_freq_tab[(asc[0]&0x7)<<1 |asc[1]>>7];
|
unsigned asc_sfreq = aacenc_sampling_freq_tab[(asc[0]&0x7)<<1 |asc[1]>>7];
|
||||||
|
unsigned shift = aacenc_is_dual_rate_sbr(params);
|
||||||
|
|
||||||
switch (params->profile) {
|
switch (params->profile) {
|
||||||
case AOT_SBR:
|
case AOT_SBR:
|
||||||
case AOT_PS:
|
case AOT_PS:
|
||||||
|
if (!shift)
|
||||||
|
break;
|
||||||
if (*outsize < ascsize + 3)
|
if (*outsize < ascsize + 3)
|
||||||
return -1;
|
return -1;
|
||||||
memcpy(outasc, asc, ascsize);
|
memcpy(outasc, asc, ascsize);
|
||||||
@ -65,10 +106,10 @@ int aacenc_mp4asc(const aacenc_param_t *params,
|
|||||||
/* sbrPresentFlag:1 (value:1) */
|
/* sbrPresentFlag:1 (value:1) */
|
||||||
outasc[ascsize+2] = 0x80;
|
outasc[ascsize+2] = 0x80;
|
||||||
/* extensionSamplingFrequencyIndex:4 */
|
/* extensionSamplingFrequencyIndex:4 */
|
||||||
outasc[ascsize+2] |= sampling_freq_index(asc_sfreq << 1) << 3;
|
outasc[ascsize+2] |= sampling_freq_index(asc_sfreq << shift) << 3;
|
||||||
if (params->profile == AOT_SBR) {
|
if (params->profile == AOT_SBR) {
|
||||||
*outsize = ascsize + 3;
|
*outsize = ascsize + 3;
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*outsize < ascsize + 5)
|
if (*outsize < ascsize + 5)
|
||||||
return -1;
|
return -1;
|
||||||
@ -78,13 +119,12 @@ int aacenc_mp4asc(const aacenc_param_t *params,
|
|||||||
/* psPresentFlag:1 (value:1) */
|
/* psPresentFlag:1 (value:1) */
|
||||||
outasc[ascsize+4] = 0x80;
|
outasc[ascsize+4] = 0x80;
|
||||||
*outsize = ascsize + 5;
|
*outsize = ascsize + 5;
|
||||||
break;
|
return 0;
|
||||||
default:
|
|
||||||
if (*outsize < ascsize)
|
|
||||||
return -1;
|
|
||||||
memcpy(outasc, asc, ascsize);
|
|
||||||
*outsize = ascsize;
|
|
||||||
}
|
}
|
||||||
|
if (*outsize < ascsize)
|
||||||
|
return -1;
|
||||||
|
memcpy(outasc, asc, ascsize);
|
||||||
|
*outsize = ascsize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,10 +133,10 @@ int aacenc_channel_mode(const pcm_sample_description_t *format)
|
|||||||
{
|
{
|
||||||
uint32_t chanmask = format->channel_mask;
|
uint32_t chanmask = format->channel_mask;
|
||||||
|
|
||||||
if (format->channels_per_frame > 6)
|
if (format->channels_per_frame > 8)
|
||||||
return 0;
|
return 0;
|
||||||
if (!chanmask) {
|
if (!chanmask) {
|
||||||
static uint32_t defaults[] = { 0x4, 0x3, 0x7, 0, 0x37, 0x3f };
|
static uint32_t defaults[] = { 0x4, 0x3, 0x7, 0, 0x37, 0x3f, 0, 0x63f };
|
||||||
chanmask = defaults[format->channels_per_frame - 1];
|
chanmask = defaults[format->channels_per_frame - 1];
|
||||||
}
|
}
|
||||||
switch (chanmask) {
|
switch (chanmask) {
|
||||||
@ -108,6 +148,10 @@ int aacenc_channel_mode(const pcm_sample_description_t *format)
|
|||||||
case 0x107: return MODE_1_2_1;
|
case 0x107: return MODE_1_2_1;
|
||||||
case 0x607: return MODE_1_2_2;
|
case 0x607: return MODE_1_2_2;
|
||||||
case 0x60f: return MODE_1_2_2_1;
|
case 0x60f: return MODE_1_2_2_1;
|
||||||
|
#if AACENCODER_LIB_VL0 > 3 || (AACENCODER_LIB_VL0==3 && AACENCODER_LIB_VL1>=4)
|
||||||
|
case 0xff: return MODE_1_2_2_2_1;
|
||||||
|
case 0x63f: return MODE_7_1_REAR_SURROUND;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -118,8 +162,11 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
|||||||
{
|
{
|
||||||
int channel_mode;
|
int channel_mode;
|
||||||
int aot;
|
int aot;
|
||||||
|
LIB_INFO lib_info;
|
||||||
|
|
||||||
*encoder = 0;
|
*encoder = 0;
|
||||||
|
aacenc_get_lib_info(&lib_info);
|
||||||
|
|
||||||
if ((channel_mode = aacenc_channel_mode(format)) == 0) {
|
if ((channel_mode = aacenc_channel_mode(format)) == 0) {
|
||||||
fprintf(stderr, "ERROR: unsupported channel layout\n");
|
fprintf(stderr, "ERROR: unsupported channel layout\n");
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
@ -145,13 +192,21 @@ int aacenc_init(HANDLE_AACENCODER *encoder, const aacenc_param_t *params,
|
|||||||
fprintf(stderr, "ERROR: unsupported sample rate\n");
|
fprintf(stderr, "ERROR: unsupported sample rate\n");
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
aacEncoder_SetParam(*encoder, AACENC_CHANNELMODE, channel_mode);
|
if (aacEncoder_SetParam(*encoder, AACENC_CHANNELMODE,
|
||||||
|
channel_mode) != AACENC_OK) {
|
||||||
|
fprintf(stderr, "ERROR: unsupported channel mode\n");
|
||||||
|
goto FAIL;
|
||||||
|
}
|
||||||
aacEncoder_SetParam(*encoder, AACENC_BANDWIDTH, params->bandwidth);
|
aacEncoder_SetParam(*encoder, AACENC_BANDWIDTH, params->bandwidth);
|
||||||
aacEncoder_SetParam(*encoder, AACENC_CHANNELORDER, 1);
|
aacEncoder_SetParam(*encoder, AACENC_CHANNELORDER, 1);
|
||||||
aacEncoder_SetParam(*encoder, AACENC_AFTERBURNER, !!params->afterburner);
|
aacEncoder_SetParam(*encoder, AACENC_AFTERBURNER, !!params->afterburner);
|
||||||
|
|
||||||
if (aot == AOT_ER_AAC_ELD && params->lowdelay_sbr)
|
aacEncoder_SetParam(*encoder, AACENC_SBR_MODE, params->lowdelay_sbr);
|
||||||
aacEncoder_SetParam(*encoder, AACENC_SBR_MODE, 1);
|
|
||||||
|
#if AACENCODER_LIB_VL0 > 3 || (AACENCODER_LIB_VL0==3 && AACENCODER_LIB_VL1>=4)
|
||||||
|
if (lib_info.version > 0x03040000)
|
||||||
|
aacEncoder_SetParam(*encoder, AACENC_SBR_RATIO, params->sbr_ratio);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (aacEncoder_SetParam(*encoder, AACENC_TRANSMUX,
|
if (aacEncoder_SetParam(*encoder, AACENC_TRANSMUX,
|
||||||
params->transport_format) != AACENC_OK) {
|
params->transport_format) != AACENC_OK) {
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
unsigned bandwidth; \
|
unsigned bandwidth; \
|
||||||
unsigned afterburner; \
|
unsigned afterburner; \
|
||||||
unsigned lowdelay_sbr; \
|
unsigned lowdelay_sbr; \
|
||||||
|
unsigned sbr_ratio; \
|
||||||
unsigned sbr_signaling; \
|
unsigned sbr_signaling; \
|
||||||
unsigned transport_format; \
|
unsigned transport_format; \
|
||||||
unsigned adts_crc_check; \
|
unsigned adts_crc_check; \
|
||||||
@ -29,8 +30,14 @@ typedef struct aacenc_frame_t {
|
|||||||
uint32_t size, capacity;
|
uint32_t size, capacity;
|
||||||
} aacenc_frame_t;
|
} aacenc_frame_t;
|
||||||
|
|
||||||
|
int aacenc_is_sbr_ratio_available();
|
||||||
|
|
||||||
int aacenc_is_sbr_active(const aacenc_param_t *params);
|
int aacenc_is_sbr_active(const aacenc_param_t *params);
|
||||||
|
|
||||||
|
int aacenc_is_dual_rate_sbr(const aacenc_param_t *params);
|
||||||
|
|
||||||
|
void aacenc_get_lib_info(LIB_INFO *info);
|
||||||
|
|
||||||
int aacenc_mp4asc(const aacenc_param_t *params,
|
int aacenc_mp4asc(const aacenc_param_t *params,
|
||||||
const uint8_t *asc, uint32_t ascsize,
|
const uint8_t *asc, uint32_t ascsize,
|
||||||
uint8_t *outasc, uint32_t *outsize);
|
uint8_t *outasc, uint32_t *outsize);
|
||||||
|
69
src/main.c
69
src/main.c
@ -132,7 +132,14 @@ PROGNAME " %s\n"
|
|||||||
" -a, --afterburner <n> Afterburner\n"
|
" -a, --afterburner <n> Afterburner\n"
|
||||||
" 0: Off\n"
|
" 0: Off\n"
|
||||||
" 1: On(default)\n"
|
" 1: On(default)\n"
|
||||||
" -L, --lowdelay-sbr Enable ELD-SBR (AAC ELD only)\n"
|
" -L, --lowdelay-sbr <-1|0|1> Configure SBR activity on AAC ELD\n"
|
||||||
|
" -1: Use ELD SBR auto configurator\n"
|
||||||
|
" 0: Disable SBR on ELD (default)\n"
|
||||||
|
" 1: Enable SBR on ELD\n"
|
||||||
|
" -s, --sbr-ratio <0|1|2> Controls activation of downsampled SBR\n"
|
||||||
|
" 0: Use lib default (default)\n"
|
||||||
|
" 1: downsampled SBR (default for ELD+SBR)\n"
|
||||||
|
" 2: dual-rate SBR (default for HE-AAC)\n"
|
||||||
" -f, --transport-format <n> Transport format\n"
|
" -f, --transport-format <n> Transport format\n"
|
||||||
" 0: RAW (default, muxed into M4A)\n"
|
" 0: RAW (default, muxed into M4A)\n"
|
||||||
" 1: ADIF\n"
|
" 1: ADIF\n"
|
||||||
@ -228,7 +235,7 @@ static
|
|||||||
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
unsigned n;
|
int n;
|
||||||
|
|
||||||
#define OPT_INCLUDE_SBR_DELAY M4AF_FOURCC('s','d','l','y')
|
#define OPT_INCLUDE_SBR_DELAY M4AF_FOURCC('s','d','l','y')
|
||||||
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
#define OPT_MOOV_BEFORE_MDAT M4AF_FOURCC('m','o','o','v')
|
||||||
@ -247,7 +254,8 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
{ "bitrate-mode", required_argument, 0, 'm' },
|
{ "bitrate-mode", required_argument, 0, 'm' },
|
||||||
{ "bandwidth", required_argument, 0, 'w' },
|
{ "bandwidth", required_argument, 0, 'w' },
|
||||||
{ "afterburner", required_argument, 0, 'a' },
|
{ "afterburner", required_argument, 0, 'a' },
|
||||||
{ "lowdelay-sbr", no_argument, 0, 'L' },
|
{ "lowdelay-sbr", required_argument, 0, 'L' },
|
||||||
|
{ "sbr-ratio", required_argument, 0, 's' },
|
||||||
{ "transport-format", required_argument, 0, 'f' },
|
{ "transport-format", required_argument, 0, 'f' },
|
||||||
{ "adts-crc-check", no_argument, 0, 'C' },
|
{ "adts-crc-check", no_argument, 0, 'C' },
|
||||||
{ "header-period", required_argument, 0, 'P' },
|
{ "header-period", required_argument, 0, 'P' },
|
||||||
@ -325,7 +333,18 @@ int parse_options(int argc, char **argv, aacenc_param_ex_t *params)
|
|||||||
params->afterburner = n;
|
params->afterburner = n;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
params->lowdelay_sbr = 1;
|
if (sscanf(optarg, "%d", &n) != 1 || n < -1 || n > 1) {
|
||||||
|
fprintf(stderr, "invalid arg for lowdelay-sbr\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->lowdelay_sbr = n;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
if (sscanf(optarg, "%u", &n) != 1 || n > 2) {
|
||||||
|
fprintf(stderr, "invalid arg for sbr-ratio\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
params->sbr_ratio = n;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if (sscanf(optarg, "%u", &n) != 1) {
|
if (sscanf(optarg, "%u", &n) != 1) {
|
||||||
@ -567,19 +586,11 @@ void put_tool_tag(m4af_ctx_t *m4af, const aacenc_param_ex_t *params,
|
|||||||
{
|
{
|
||||||
char tool_info[256];
|
char tool_info[256];
|
||||||
char *p = tool_info;
|
char *p = tool_info;
|
||||||
LIB_INFO *lib_info = 0;
|
LIB_INFO lib_info;
|
||||||
|
|
||||||
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
p += sprintf(p, PROGNAME " %s, ", fdkaac_version);
|
||||||
|
aacenc_get_lib_info(&lib_info);
|
||||||
lib_info = calloc(FDK_MODULE_LAST, sizeof(LIB_INFO));
|
p += sprintf(p, "libfdk-aac %s, ", lib_info.versionStr);
|
||||||
if (aacEncGetLibInfo(lib_info) == AACENC_OK) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < FDK_MODULE_LAST; ++i)
|
|
||||||
if (lib_info[i].module_id == FDK_AACENC)
|
|
||||||
break;
|
|
||||||
p += sprintf(p, "libfdk-aac %s, ", lib_info[i].versionStr);
|
|
||||||
}
|
|
||||||
free(lib_info);
|
|
||||||
if (params->bitrate_mode)
|
if (params->bitrate_mode)
|
||||||
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
sprintf(p, "VBR mode %d", params->bitrate_mode);
|
||||||
else
|
else
|
||||||
@ -756,11 +767,13 @@ int main(int argc, char **argv)
|
|||||||
pcm_reader_t *reader = 0;
|
pcm_reader_t *reader = 0;
|
||||||
HANDLE_AACENCODER encoder = 0;
|
HANDLE_AACENCODER encoder = 0;
|
||||||
AACENC_InfoStruct aacinfo = { 0 };
|
AACENC_InfoStruct aacinfo = { 0 };
|
||||||
|
LIB_INFO lib_info = { 0 };
|
||||||
m4af_ctx_t *m4af = 0;
|
m4af_ctx_t *m4af = 0;
|
||||||
const pcm_sample_description_t *sample_format;
|
const pcm_sample_description_t *sample_format;
|
||||||
int downsampled_timescale = 0;
|
int downsampled_timescale = 0;
|
||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
int sbr_mode = 0;
|
int sbr_mode = 0;
|
||||||
|
unsigned scale_shift = 0;
|
||||||
|
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
setbuf(stderr, 0);
|
setbuf(stderr, 0);
|
||||||
@ -782,7 +795,16 @@ int main(int argc, char **argv)
|
|||||||
* way in MPEG4 part3 spec, and seems the only way supported by iTunes.
|
* way in MPEG4 part3 spec, and seems the only way supported by iTunes.
|
||||||
* Since FDK library does not support it, we have to do it on our side.
|
* Since FDK library does not support it, we have to do it on our side.
|
||||||
*/
|
*/
|
||||||
|
sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
||||||
|
if (sbr_mode && !aacenc_is_sbr_ratio_available()) {
|
||||||
|
fprintf(stderr, "WARNING: Only dual-rate SBR is available "
|
||||||
|
"for this version\n");
|
||||||
|
params.sbr_ratio = 2;
|
||||||
|
}
|
||||||
|
scale_shift = aacenc_is_dual_rate_sbr((aacenc_param_t*)¶ms);
|
||||||
params.sbr_signaling = (params.transport_format == TT_MP4_LOAS) ? 2 : 0;
|
params.sbr_signaling = (params.transport_format == TT_MP4_LOAS) ? 2 : 0;
|
||||||
|
if (sbr_mode && !scale_shift)
|
||||||
|
params.sbr_signaling = 2;
|
||||||
|
|
||||||
if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format,
|
if (aacenc_init(&encoder, (aacenc_param_t*)¶ms, sample_format,
|
||||||
&aacinfo) < 0)
|
&aacinfo) < 0)
|
||||||
@ -800,15 +822,13 @@ int main(int argc, char **argv)
|
|||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
handle_signals();
|
handle_signals();
|
||||||
sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)¶ms);
|
|
||||||
if (!params.transport_format) {
|
if (!params.transport_format) {
|
||||||
uint32_t scale;
|
uint32_t scale;
|
||||||
uint8_t mp4asc[32];
|
uint8_t mp4asc[32];
|
||||||
uint32_t ascsize = sizeof(mp4asc);
|
uint32_t ascsize = sizeof(mp4asc);
|
||||||
unsigned framelen = aacinfo.frameLength;
|
unsigned framelen = aacinfo.frameLength;
|
||||||
if (sbr_mode)
|
scale = sample_format->sample_rate >> scale_shift;
|
||||||
downsampled_timescale = 1;
|
|
||||||
scale = sample_format->sample_rate >> downsampled_timescale;
|
|
||||||
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
|
if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
|
||||||
params.output_fp)) < 0)
|
params.output_fp)) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
@ -816,12 +836,12 @@ int main(int argc, char **argv)
|
|||||||
aacinfo.confSize, mp4asc, &ascsize);
|
aacinfo.confSize, mp4asc, &ascsize);
|
||||||
m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize);
|
m4af_set_decoder_specific_info(m4af, 0, mp4asc, ascsize);
|
||||||
m4af_set_fixed_frame_duration(m4af, 0,
|
m4af_set_fixed_frame_duration(m4af, 0,
|
||||||
framelen >> downsampled_timescale);
|
framelen >> scale_shift);
|
||||||
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
|
m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
|
||||||
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
|
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
|
||||||
m4af_begin_write(m4af);
|
m4af_begin_write(m4af);
|
||||||
}
|
}
|
||||||
if (sbr_mode && (aacinfo.encoderDelay & 1)) {
|
if (scale_shift && (aacinfo.encoderDelay & 1)) {
|
||||||
/*
|
/*
|
||||||
* Since odd delay cannot be exactly expressed in downsampled scale,
|
* Since odd delay cannot be exactly expressed in downsampled scale,
|
||||||
* we push one zero frame to the encoder here, to make delay even
|
* we push one zero frame to the encoder here, to make delay even
|
||||||
@ -841,12 +861,11 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (sbr_mode && params.profile != AOT_ER_AAC_ELD &&
|
if (sbr_mode && params.profile != AOT_ER_AAC_ELD &&
|
||||||
!params.include_sbr_delay)
|
!params.include_sbr_delay)
|
||||||
delay -= 481 << 1;
|
delay -= 481 << scale_shift;
|
||||||
if (sbr_mode && (delay & 1))
|
if (scale_shift && (delay & 1))
|
||||||
++delay;
|
++delay;
|
||||||
padding = frame_count * aacinfo.frameLength - frames_read - delay;
|
padding = frame_count * aacinfo.frameLength - frames_read - delay;
|
||||||
m4af_set_priming(m4af, 0, delay >> downsampled_timescale,
|
m4af_set_priming(m4af, 0, delay >> scale_shift, padding >> scale_shift);
|
||||||
padding >> downsampled_timescale);
|
|
||||||
if (finalize_m4a(m4af, ¶ms, encoder) < 0)
|
if (finalize_m4a(m4af, ¶ms, encoder) < 0)
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user