{ "512", 512 }, { "576", 576 }, { "640", 640 }, { "768", 768 } };
int hb_audio_bitrates_count = sizeof( hb_audio_bitrates ) /
sizeof( hb_rate_t );
-int hb_audio_bitrates_default = 8; /* 128 kbps */
static hb_error_handler_t *error_handler = NULL;
return "";
}
+// Given an input bitrate, find closest match in the set of allowed bitrates
+int hb_find_closest_audio_bitrate(int bitrate)
+{
+ int ii;
+ int result;
+
+ // result is highest rate if none found during search.
+ // rate returned will always be <= rate asked for.
+ result = hb_audio_bitrates[0].rate;
+ for (ii = hb_audio_bitrates_count-1; ii >= 0; ii--)
+ {
+ if (bitrate >= hb_audio_bitrates[ii].rate)
+ {
+ result = hb_audio_bitrates[ii].rate;
+ break;
+ }
+ }
+ return result;
+}
+
+// Get the bitrate low and high limits for a codec/samplerate/mixdown triplet
+// The limits have been empirically determined through testing. Max bitrates
+// in table below. Numbers in parenthesis are the target bitrate chosen.
+/*
+Encoder 1 channel 2 channels 6 channels
+
+faac
+24kHz 86 (128) 173 (256) 460 (768)
+48kHz 152 (160) 304 (320) 759 (768)
+
+Vorbis
+24kHz 97 (80) 177 (160) 527 (512)
+48kHz 241 (224) 465 (448) 783 (768)
+
+Lame
+24kHz 146 (768) 138 (768)
+48kHz 318 (768) 318 (768)
+
+ffac3
+24kHz 318 (320) 318 (320) 318 (320)
+48kHz 636 (640) 636 (640) 636 (640)
+
+Core Audio (core audio api provides range of allowed bitrates)
+24kHz 16-64 32-128 80-320
+44.1kHz 64-320 160-768
+48kHz 32-256 64-320 160-768
+
+Core Audio (minimum limits found in testing)
+24kHz 16 32 96
+44.1kHz 32 64 160
+48kHz 40 80 240
+*/
+
+void hb_get_audio_bitrate_limits(uint32_t codec, int samplerate, int mixdown, int *low, int *high)
+{
+ int channels;
+
+ channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mixdown);
+ switch (codec)
+ {
+ case HB_ACODEC_AC3:
+ *low = 32 * channels;
+ if (samplerate > 24000)
+ {
+ *high = 640;
+ }
+ else
+ {
+ *high = 320;
+ }
+ break;
+
+ case HB_ACODEC_CA_AAC:
+ if (samplerate > 44100)
+ {
+ *low = channels * 40;
+ *high = 256;
+ if (channels == 2)
+ *high = 320;
+ if (channels == 6)
+ {
+ *high = 768;
+ }
+ }
+ else if (samplerate > 24000)
+ {
+ *low = channels * 32;
+ *high = 256;
+ if (channels == 2)
+ *high = 320;
+ if (channels == 6)
+ {
+ *low = 160;
+ *high = 768;
+ }
+ }
+ else
+ {
+ *low = channels * 16;
+ *high = channels * 64;
+ if (channels == 6)
+ {
+ *high = 320;
+ }
+ }
+ break;
+
+ case HB_ACODEC_FAAC:
+ *low = 32 * channels;
+ if (samplerate > 24000)
+ {
+ *high = 160 * channels;
+ if (*high > 768)
+ *high = 768;
+ }
+ else
+ {
+ *high = 96 * channels;
+ if (*high > 480)
+ *high = 480;
+ }
+ break;
+
+ case HB_ACODEC_VORBIS:
+ *high = channels * 80;
+ if (samplerate > 24000)
+ {
+ if (channels > 2)
+ {
+ // Vorbis minimum is around 30kbps/ch for 6ch
+ // at rates > 24k (32k/44.1k/48k)
+ *low = 32 * channels;
+ *high = 128 * channels;
+ }
+ else
+ {
+ // Allow 24kbps mono and 48kbps stereo at rates > 24k
+ // (32k/44.1k/48k)
+ *low = 24 * channels;
+ if (samplerate > 32000)
+ *high = channels * 224;
+ else
+ *high = channels * 160;
+ }
+ }
+ else
+ {
+ *low = channels * 16;
+ *high = 80 * channels;
+ }
+ break;
+
+ case HB_ACODEC_LAME:
+ *low = hb_audio_bitrates[0].rate;
+ if (samplerate > 24000)
+ *high = 320;
+ else
+ *high = 160;
+ break;
+
+ default:
+ *low = hb_audio_bitrates[0].rate;
+ *high = hb_audio_bitrates[hb_audio_bitrates_count-1].rate;
+ break;
+ }
+}
+
+// Given an input bitrate, sanitize it. Check low and high limits and
+// make sure it is in the set of allowed bitrates.
+int hb_get_best_audio_bitrate( uint32_t codec, int bitrate, int samplerate, int mixdown)
+{
+ int low, high;
+
+ hb_get_audio_bitrate_limits(codec, samplerate, mixdown, &low, &high);
+ if (bitrate > high)
+ bitrate = high;
+ if (bitrate < low)
+ bitrate = low;
+ bitrate = hb_find_closest_audio_bitrate(bitrate);
+ return bitrate;
+}
+
+// Get the default bitrate for a given codec/samplerate/mixdown triplet.
+int hb_get_default_audio_bitrate( uint32_t codec, int samplerate, int mixdown )
+{
+ int bitrate, channels;
+ int sr_shift;
+
+ channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mixdown);
+
+ // Min bitrate is established such that we get good quality
+ // audio as a minimum.
+ sr_shift = (samplerate <= 24000) ? 1 : 0;
+
+ switch ( codec )
+ {
+ case HB_ACODEC_AC3:
+ if (channels == 1)
+ bitrate = 96;
+ else if (channels <= 2)
+ bitrate = 224;
+ else
+ bitrate = 640;
+ break;
+ default:
+ bitrate = channels * 80;
+ }
+ bitrate >>= sr_shift;
+ bitrate = hb_get_best_audio_bitrate( codec, bitrate, samplerate, mixdown );
+ return bitrate;
+}
+
+int hb_get_best_mixdown( uint32_t codec, int layout, int mixdown )
+{
+
+ int best_mixdown;
+
+ if (codec & HB_ACODEC_PASS_FLAG)
+ {
+ // Audio pass-thru. No mixdown.
+ return 0;
+ }
+ switch (layout & HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK)
+ {
+ // stereo input or something not handled below
+ default:
+ case HB_INPUT_CH_LAYOUT_STEREO:
+ // mono gets mixed up to stereo & more than stereo gets mixed down
+ best_mixdown = HB_AMIXDOWN_STEREO;
+ break;
+
+ // mono input
+ case HB_INPUT_CH_LAYOUT_MONO:
+ // everything else passes through
+ best_mixdown = HB_AMIXDOWN_MONO;
+ break;
+
+ // dolby (DPL1 aka Dolby Surround = 4.0 matrix-encoded) input
+ // the A52 flags don't allow for a way to distinguish between DPL1 and
+ // DPL2 on a DVD so we always assume a DPL1 source for A52_DOLBY.
+ case HB_INPUT_CH_LAYOUT_DOLBY:
+ best_mixdown = HB_AMIXDOWN_DOLBY;
+ break;
+
+ // 4 channel discrete
+ case HB_INPUT_CH_LAYOUT_2F2R:
+ case HB_INPUT_CH_LAYOUT_3F1R:
+ // a52dec and libdca can't upmix to 6ch,
+ // so we must downmix these.
+ best_mixdown = HB_AMIXDOWN_DOLBYPLII;
+ break;
+
+ // 5, 6, 7, or 8 channel discrete
+ case HB_INPUT_CH_LAYOUT_4F2R:
+ case HB_INPUT_CH_LAYOUT_3F4R:
+ case HB_INPUT_CH_LAYOUT_3F2R:
+ if ( ! ( layout & HB_INPUT_CH_LAYOUT_HAS_LFE ) )
+ {
+ // we don't do 5 channel discrete so mixdown to DPLII
+ // a52dec and libdca can't upmix to 6ch,
+ // so we must downmix this.
+ best_mixdown = HB_AMIXDOWN_DOLBYPLII;
+ }
+ else
+ {
+ switch (codec)
+ {
+ case HB_ACODEC_LAME:
+ best_mixdown = HB_AMIXDOWN_DOLBYPLII;
+ break;
+
+ default:
+ best_mixdown = HB_AMIXDOWN_6CH;
+ break;
+ }
+ }
+ break;
+ }
+ // return the best that is not greater than the requested mixdown
+ // 0 means the caller requested the best available mixdown
+ if( best_mixdown > mixdown && mixdown != 0 )
+ best_mixdown = mixdown;
+
+ return best_mixdown;
+}
+
+int hb_get_default_mixdown( uint32_t codec, int layout )
+{
+ int mixdown;
+ switch (codec)
+ {
+ // the AC3 encoder defaults to the best mixdown up to 6-channel
+ case HB_ACODEC_AC3:
+ mixdown = HB_AMIXDOWN_6CH;
+ break;
+ // other encoders default to the best mixdown up to DPLII
+ default:
+ mixdown = HB_AMIXDOWN_DOLBYPLII;
+ break;
+ }
+ // return the best available mixdown up to the selected default
+ return hb_get_best_mixdown( codec, layout, mixdown );
+}
+
/**********************************************************************
* hb_reduce
**********************************************************************
(quite guessed) */
switch( job->mux )
{
- case HB_MUX_MP4:
- case HB_MUX_PSP:
- case HB_MUX_IPOD:
- case HB_MUX_MKV:
- overhead = 6;
- break;
- case HB_MUX_AVI:
- overhead = 24;
- break;
- case HB_MUX_OGM:
+ case HB_MUX_MP4:
+ case HB_MUX_MKV:
overhead = 6;
break;
default:
// default to decoding mpeg2
t->video_id = 0xE0;
t->video_codec = WORK_DECMPEG2;
+ t->angle_count = 1;
return t;
}
while( ( audio = hb_list_item( t->list_audio, 0 ) ) )
{
+ if ( audio->priv.ff_audio_list != NULL )
+ {
+ hb_list_close( &audio->priv.ff_audio_list );
+ }
hb_list_rem( t->list_audio, audio );
free( audio );
}