diff options
author | van <[email protected]> | 2008-11-09 01:45:52 +0000 |
---|---|---|
committer | van <[email protected]> | 2008-11-09 01:45:52 +0000 |
commit | 19de50b9c802cbbdd8df6f20ff770b308f5347b2 (patch) | |
tree | 6f570365d5655d2d52cdf76c43760659b9e627d1 /libhb/encfaac.c | |
parent | df4163cccd4aa35fcc4271d7f2c155116531b4c7 (diff) |
If 'auto' audio output rate is selected and that results in an invalid rate for AAC, select the next higher valid rate. This should make wmv's & avi's with weird audio rates more likely to work with the default HB settings.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1907 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/encfaac.c')
-rw-r--r-- | libhb/encfaac.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/libhb/encfaac.c b/libhb/encfaac.c index cd333d3f3..c955199d0 100644 --- a/libhb/encfaac.c +++ b/libhb/encfaac.c @@ -36,6 +36,21 @@ hb_work_object_t hb_encfaac = encfaacClose }; +static const int valid_rates[] = +{ + 22050, 24000, 32000, 44100, 48000, 0 +}; + +static int find_samplerate( int rate ) +{ + int i; + + for ( i = 0; valid_rates[i] && rate > valid_rates[i]; ++i ) + { + } + return i; +} + /*********************************************************************** * hb_work_encfaac_init *********************************************************************** @@ -56,6 +71,28 @@ int encfaacInit( hb_work_object_t * w, hb_job_t * job ) /* pass the number of channels used into the private work data */ pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(audio->config.out.mixdown); + /* if the sample rate is 'auto' and that has given us an invalid output */ + /* rate, map it to the next highest output rate or 48K if above the highest. */ + int rate_index = find_samplerate(audio->config.out.samplerate); + if ( audio->config.out.samplerate != valid_rates[rate_index] ) + { + int rate = valid_rates[valid_rates[rate_index]? rate_index : rate_index - 1]; + hb_log( "encfaac changing output samplerate from %d to %d", + audio->config.out.samplerate, rate ); + audio->config.out.samplerate = rate; + + /* if the new rate is over the max bandwidth per channel limit */ + /* lower the bandwidth. */ + double bw = audio->config.out.bitrate * 1000 / pv->out_discrete_channels; + if ( bw > (double)rate * (6144./1024.) ) + { + int newbr = (double)rate * (6.144/1024.) * pv->out_discrete_channels; + hb_log( "encfaac changing output bitrate from %d to %d", + audio->config.out.bitrate, newbr ); + audio->config.out.bitrate = newbr; + } + } + pv->faac = faacEncOpen( audio->config.out.samplerate, pv->out_discrete_channels, &pv->input_samples, &pv->output_bytes ); pv->buf = malloc( pv->input_samples * sizeof( float ) ); |