From da4318f07c23f6755b1b21845b7336990ebabcd4 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 7 Sep 2012 21:40:41 +0000 Subject: [PATCH] WinGui: Updated the Bitrate Converted to be a bit more intelligent about it's bitrate selection. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4937 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Model/Encoding/AudioTrack.cs | 1 + .../Converters/Audio/AudioBitrateConverter.cs | 73 ++++++++++++++++++- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs index 6e5803c09..ac4b95e32 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs @@ -254,6 +254,7 @@ namespace HandBrake.ApplicationServices.Model.Encoding { this.sampleRate = value; this.NotifyOfPropertyChange("SampleRate"); + this.NotifyOfPropertyChange("TrackReference"); } } diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs index 28e31b07d..89016071e 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs @@ -46,23 +46,56 @@ namespace HandBrakeWPF.Converters.Audio List bitrates = new List { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 640, 768 }; int max = 160; + AudioTrack track = value as AudioTrack; if (track != null) { + int channels = this.GetChannelCount(track.MixDown); + + double samplerate = 48; // Default + + if (!track.SampleRate.Equals(0.0d)) + { + samplerate = track.SampleRate; + } + else if (track.ScannedTrack != null && track.ScannedTrack.SampleRate != 0) + { + samplerate = track.ScannedTrack.SampleRate / 1000d; + } + switch (track.Encoder) { case AudioEncoder.Faac: case AudioEncoder.ffaac: - max = track.MixDown >= Mixdown.FivePoint1Channels ? 768 : 320; + if (samplerate > 24) + { + max = 160 * channels; + if (max > 768) + { + max = 768; + } + } + else + { + max = 96 * channels; + if (max > 480) + { + max = 480; + } + } break; case AudioEncoder.Lame: - max = 320; + max = samplerate > 24 ? 320 : 160; break; case AudioEncoder.Vorbis: - max = 384; + max = samplerate > 24 + ? (channels > 2 + ? 128 * channels + : (track.SampleRate > 32 ? 224 * channels : 160 * channels)) + : 80 * this.GetChannelCount(track.MixDown); break; case AudioEncoder.Ac3: - max = 640; + max = samplerate > 24 ? 640 : 320; break; case AudioEncoder.Ac3Passthrough: case AudioEncoder.DtsPassthrough: @@ -88,6 +121,38 @@ namespace HandBrakeWPF.Converters.Audio return bitrates.Where(bitrate => bitrate <= max); } + /// + /// The get channel count. + /// + /// + /// The mixdown. + /// + /// + /// The System.Int32. + /// + private int GetChannelCount(Mixdown mixdown) + { + switch (mixdown) + { + case Mixdown.Five_2_LFE: + case Mixdown.SevenPoint1Channels: + return 8; + case Mixdown.SixPoint1Channels: + return 7; + case Mixdown.FivePoint1Channels: + return 6; + case Mixdown.Mono: + case Mixdown.LeftOnly: + case Mixdown.RightOnly: + return 1; + case Mixdown.None: + return 0; + default: + return 2; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); -- 2.40.0