aacenc: make a better estimate for the audio bitrate if not provided

aacenc: temporarily disable Mid/Side coding with multichannel files

from Brad (maintainer)
This commit is contained in:
ajacoutot 2016-02-25 03:53:53 +00:00
parent 386887e461
commit beb4446f37
2 changed files with 59 additions and 25 deletions

View File

@ -1,11 +1,11 @@
# $OpenBSD: Makefile,v 1.143 2016/01/23 14:12:28 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.144 2016/02/25 03:53:53 ajacoutot Exp $
COMMENT= audio/video converter and streamer
V= 20160113
DISTNAME= ffmpeg-git-${V}
PKGNAME= ffmpeg-${V}
REVISION= 3
REVISION= 4
CATEGORIES= graphics multimedia
MASTER_SITES= http://comstyle.com/source/
EXTRACT_SUFX= .tar.xz

View File

@ -1,4 +1,4 @@
$OpenBSD: patch-libavcodec_aacenc_c,v 1.12 2016/01/22 07:05:01 ajacoutot Exp $
$OpenBSD: patch-libavcodec_aacenc_c,v 1.13 2016/02/25 03:53:53 ajacoutot Exp $
aacenc: copy PRNG from the decoder
@ -70,8 +70,12 @@ aacenc: remove FAAC-like coder
avcodec/aacenc: Check all coefficients for finiteness
aacenc: make a better estimate for the audio bitrate if not provided
aacenc: temporarily disable Mid/Side coding with multichannel files
--- libavcodec/aacenc.c.orig Wed Jan 13 15:27:48 2016
+++ libavcodec/aacenc.c Wed Jan 20 21:30:40 2016
+++ libavcodec/aacenc.c Mon Feb 15 17:12:33 2016
@@ -29,6 +29,7 @@
* add sane pulse detection
***********************************/
@ -436,50 +440,62 @@ avcodec/aacenc: Check all coefficients for finiteness
ff_mdct_end(&s->mdct1024);
ff_mdct_end(&s->mdct128);
ff_psy_end(&s->psy);
@@ -796,76 +900,109 @@ static av_cold int aac_encode_init(AVCodecContext *avc
@@ -796,76 +900,123 @@ static av_cold int aac_encode_init(AVCodecContext *avc
uint8_t grouping[AAC_MAX_CHANNELS];
int lengths[2];
+ s->channels = avctx->channels;
+ s->chan_map = aac_chan_configs[s->channels-1];
+ s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120;
+ /* Constants */
+ s->last_frame_pb_count = 0;
+ avctx->extradata_size = 5;
avctx->frame_size = 1024;
+ avctx->initial_padding = 1024;
+ avctx->bit_rate = (int)FFMIN(
+ 6144 * s->channels / 1024.0 * avctx->sample_rate,
+ avctx->bit_rate);
+ avctx->profile = avctx->profile == FF_PROFILE_UNKNOWN ? FF_PROFILE_AAC_LOW :
+ avctx->profile;
+ s->lambda = avctx->global_quality > 0 ? avctx->global_quality : 120;
+ /* Channel map and unspecified bitrate guessing */
+ s->channels = avctx->channels;
+ ERROR_IF(s->channels > AAC_MAX_CHANNELS || s->channels == 7,
+ "Unsupported number of channels: %d\n", s->channels);
+ s->chan_map = aac_chan_configs[s->channels-1];
+ if (!avctx->bit_rate) {
+ for (i = 1; i <= s->chan_map[0]; i++) {
+ avctx->bit_rate += s->chan_map[i] == TYPE_CPE ? 128000 : /* Pair */
+ s->chan_map[i] == TYPE_LFE ? 16000 : /* LFE */
+ 69000 ; /* SCE */
+ }
+ }
+
+ /* Samplerate */
for (i = 0; i < 16; i++)
if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i])
break;
+ s->samplerate_index = i;
-
- s->channels = avctx->channels;
-
- ERROR_IF(i == 16 || i >= ff_aac_swb_size_1024_len || i >= ff_aac_swb_size_128_len,
+ s->samplerate_index = i;
+ ERROR_IF(s->samplerate_index == 16 ||
+ s->samplerate_index >= ff_aac_swb_size_1024_len ||
+ s->samplerate_index >= ff_aac_swb_size_128_len,
"Unsupported sample rate %d\n", avctx->sample_rate);
- ERROR_IF(s->channels > AAC_MAX_CHANNELS,
+ ERROR_IF(s->channels > AAC_MAX_CHANNELS || s->channels == 7,
"Unsupported number of channels: %d\n", s->channels);
- "Unsupported number of channels: %d\n", s->channels);
+
+ /* Bitrate limiting */
WARN_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels,
- "Too many bits per frame requested, clamping to max\n");
- if (avctx->profile == FF_PROFILE_AAC_MAIN) {
+ "Too many bits %f > %d per frame requested, clamping to max\n",
+ 1024.0 * avctx->bit_rate / avctx->sample_rate,
+ 6144 * s->channels);
+
+ avctx->bit_rate = (int64_t)FFMIN(6144 * s->channels / 1024.0 * avctx->sample_rate,
+ avctx->bit_rate);
+
+ /* Profile and option setting */
+ avctx->profile = avctx->profile == FF_PROFILE_UNKNOWN ? FF_PROFILE_AAC_LOW :
+ avctx->profile;
+ for (i = 0; i < FF_ARRAY_ELEMS(aacenc_profiles); i++)
+ if (avctx->profile == aacenc_profiles[i])
+ break;
+ ERROR_IF(i == FF_ARRAY_ELEMS(aacenc_profiles),
+ "Unsupported encoding profile: %d\n", avctx->profile);
+ if (avctx->profile == FF_PROFILE_MPEG2_AAC_LOW) {
+ avctx->profile = FF_PROFILE_AAC_LOW;
+ ERROR_IF(s->options.pred,
@ -520,21 +536,25 @@ avcodec/aacenc: Check all coefficients for finiteness
+ "LTP prediction unavailable in the \"aac_main\" profile\n");
}
+ s->profile = avctx->profile;
+ s->coder = &ff_aac_coders[s->options.coder];
- if (s->options.aac_coder != AAC_CODER_TWOLOOP) {
+ /* Coder limitations */
+ s->coder = &ff_aac_coders[s->options.coder];
+ if (s->options.coder != AAC_CODER_TWOLOOP) {
+ ERROR_IF(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL,
+ "Coders other than twoloop require -strict -2 and some may be removed in the future\n");
s->options.intensity_stereo = 0;
s->options.pns = 0;
}
+ ERROR_IF(s->options.ltp && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL,
+ "The LPT profile requires experimental compliance, add -strict -2 to enable!\n");
- avctx->bit_rate = (int)FFMIN(
- 6144 * s->channels / 1024.0 * avctx->sample_rate,
- avctx->bit_rate);
+ ERROR_IF(s->options.ltp && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL,
+ "The LPT profile requires experimental compliance, add -strict -2 to enable!\n");
+ /* M/S introduces horrible artifacts with multichannel files, this is temporary */
+ if (s->channels > 3)
+ s->options.mid_side = 0;
- s->samplerate_index = i;
-
@ -578,7 +598,7 @@ avcodec/aacenc: Check all coefficients for finiteness
ff_af_queue_init(avctx, &s->afq);
return 0;
@@ -876,27 +1013,16 @@ fail:
@@ -876,27 +1027,16 @@ fail:
#define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
static const AVOption aacenc_options[] = {
@ -616,9 +636,23 @@ avcodec/aacenc: Check all coefficients for finiteness
{NULL}
};
@@ -917,8 +1043,7 @@ AVCodec ff_aac_encoder = {
@@ -907,6 +1047,11 @@ static const AVClass aacenc_class = {
LIBAVUTIL_VERSION_INT,
};
+static const AVCodecDefault aac_encode_defaults[] = {
+ { "b", "0" },
+ { NULL }
+};
+
AVCodec ff_aac_encoder = {
.name = "aac",
.long_name = NULL_IF_CONFIG_SMALL("AAC (Advanced Audio Coding)"),
@@ -916,9 +1061,9 @@ AVCodec ff_aac_encoder = {
.init = aac_encode_init,
.encode2 = aac_encode_frame,
.close = aac_encode_end,
+ .defaults = aac_encode_defaults,
.supported_samplerates = mpeg4audio_sample_rates,
- .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY |
- AV_CODEC_CAP_EXPERIMENTAL,