diff options
author | sr55 <[email protected]> | 2015-06-20 19:45:31 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2015-06-20 19:45:31 +0000 |
commit | ae9dbce961c2d87e5f52288c35fbf882de8430c7 (patch) | |
tree | c8da7e616457a9fa67505de26ad3dfffcdb8dc8f /win/CS/HandBrake.ApplicationServices/Services | |
parent | 9192276e8bfde8ac2ce798edf677be141ad5e9b5 (diff) |
WinGui: Initial implementation of quality based encoding option. Please note, the preset version has been bumped so user presets will need to be re-created.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7306 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Services')
4 files changed, 373 insertions, 67 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs index 12c06f011..e133492ff 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs @@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories {
using System;
using System.Collections.Generic;
+ using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
@@ -341,6 +342,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper<Mixdown>.GetShortName(item.MixDown));
Validate.NotNull(mixdown, "Unrecognized audio mixdown:" + item.MixDown);
+ HBRate sampleRate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(s => s.Name == item.SampleRate.ToString(CultureInfo.InvariantCulture));
+
HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack audioTrack = new HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack
{
Track = (item.Track.HasValue ? item.Track.Value : 0) - 1,
@@ -349,27 +352,21 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories Gain = item.Gain,
Mixdown = mixdown.Id,
NormalizeMixLevel = false,
- Samplerate = GetSampleRateRaw(item.SampleRate),
+ Samplerate = sampleRate != null ? sampleRate.Rate : 0,
Name = item.TrackName,
};
if (!item.IsPassthru)
{
- // TODO Impiment Quality and Compression. We only support bitrate right now.
- // if (item.EncodeRateType == AudioEncodeRateType.Quality)
- // {
- // audioTrack.Quality = item.Quality;
- // }
-
- // if (item.EncodeRateType == AudioEncodeRateType.Compression)
- // {
- // audioTrack.CompressionLevel = item.Compression;
- // }
-
- // if (item.EncodeRateType == AudioEncodeRateType.Bitrate)
- // {
- audioTrack.Bitrate = item.Bitrate;
- // }
+ if (item.EncoderRateType == AudioEncoderRateType.Quality)
+ {
+ audioTrack.Quality = item.Quality;
+ }
+
+ if (item.EncoderRateType == AudioEncoderRateType.Bitrate)
+ {
+ audioTrack.Bitrate = item.Bitrate;
+ }
}
audio.AudioList.Add(audioTrack);
@@ -379,28 +376,6 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories }
/// <summary>
- /// The get sample rate raw.
- /// </summary>
- /// <param name="rate">
- /// The rate.
- /// </param>
- /// <returns>
- /// The <see cref="int"/>.
- /// </returns>
- private static int GetSampleRateRaw(double rate)
- {
- if (rate == 22.05)
- return 22050;
- else if (rate == 24)
- return 24000;
- else if (rate == 44.1)
- return 32000;
- else if (rate == 48)
- return 48000;
- else return 48000;
- }
-
- /// <summary>
/// The create filter.
/// </summary>
/// <param name="job">
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs new file mode 100644 index 000000000..0b152b656 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs @@ -0,0 +1,89 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AudioEncoder.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The audio encoder enumeration
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
+{
+ using System.ComponentModel.DataAnnotations;
+
+ using HandBrake.ApplicationServices.Attributes;
+
+ /// <summary>
+ /// The audio encoder.
+ /// </summary>
+ public enum AudioEncoder
+ {
+ [Display(Name = "AAC (avcodec)")]
+ [ShortName("av_aac")]
+ ffaac,
+
+ [Display(Name = "AAC (FDK)")]
+ [ShortName("fdk_aac")]
+ fdkaac,
+
+ [Display(Name = "HE-AAC (FDK)")]
+ [ShortName("fdk_haac")]
+ fdkheaac,
+
+ [Display(Name = "MP3")]
+ [ShortName("mp3")]
+ Lame,
+
+ [Display(Name = "AC3")]
+ [ShortName("ac3")]
+ Ac3,
+
+ [Display(Name = "Auto Passthru")]
+ [ShortName("copy")]
+ Passthrough,
+
+ [Display(Name = "AC3 Passthru")]
+ [ShortName("copy:ac3")]
+ Ac3Passthrough,
+
+ [Display(Name = "E-AC3 Passthru")]
+ [ShortName("copy:eac3")]
+ EAc3Passthrough,
+
+ [Display(Name = "DTS Passthru")]
+ [ShortName("copy:dts")]
+ DtsPassthrough,
+
+ [Display(Name = "DTS-HD Passthru")]
+ [ShortName("copy:dtshd")]
+ DtsHDPassthrough,
+
+ [Display(Name = "TrueHD Passthru")]
+ [ShortName("copy:truehd")]
+ TrueHDPassthrough,
+
+ [Display(Name = "AAC Passthru")]
+ [ShortName("copy:aac")]
+ AacPassthru,
+
+ [Display(Name = "MP3 Passthru")]
+ [ShortName("copy:mp3")]
+ Mp3Passthru,
+
+ [Display(Name = "Vorbis")]
+ [ShortName("vorbis")]
+ Vorbis,
+
+ [Display(Name = "FLAC 16-bit")]
+ [ShortName("flac16")]
+ ffflac,
+
+ [Display(Name = "FLAC 24-bit")]
+ [ShortName("flac24")]
+ ffflac24,
+
+ [Display(Name = "FLAC Passthru")]
+ [ShortName("copy:flac")]
+ FlacPassthru,
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs new file mode 100644 index 000000000..fb245a9b5 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs @@ -0,0 +1,31 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AudioEncoderRateType.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The audio encoder rate type.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
+{
+ using System.ComponentModel.DataAnnotations;
+
+ /// <summary>
+ /// The audio encoder rate type.
+ /// </summary>
+ public enum AudioEncoderRateType
+ {
+ /// <summary>
+ /// The bitrate.
+ /// </summary>
+ [Display(Name = "Bitrate: ")]
+ Bitrate,
+
+ /// <summary>
+ /// The quality.
+ /// </summary>
+ [Display(Name = "Quality: ")]
+ Quality,
+ }
+}
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs index d1c980e54..d59bf8701 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs @@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models using System.ComponentModel;
using System.Globalization;
using System.Linq;
+ using System.Runtime.CompilerServices;
using HandBrake.ApplicationServices.Interop;
using HandBrake.ApplicationServices.Interop.Model;
@@ -39,6 +40,9 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models private Audio scannedTrack;
private bool isDefault;
private IEnumerable<int> bitrates;
+ private IEnumerable<double> encoderQualityValues;
+ private AudioEncoderRateType encoderRateType;
+ private double? quality;
/// <summary>
/// Initializes a new instance of the <see cref = "AudioTrack" /> class.
@@ -55,7 +59,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.TrackName = string.Empty;
// Setup Backing Properties
- this.SetupBitrateLimits();
+ this.EncoderRateType = AudioEncoderRateType.Bitrate;
+ this.SetupLimits();
}
/// <summary>
@@ -81,32 +86,16 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.scannedTrack = track.ScannedTrack ?? new Audio();
}
this.TrackName = track.TrackName;
+ this.Quality = track.Quality;
// Setup Backing Properties
- this.SetupBitrateLimits();
+ this.encoderRateType = track.EncoderRateType;
+ this.SetupLimits();
}
#region Track Properties
/// <summary>
- /// Gets or sets Audio Bitrate
- /// </summary>
- public int Bitrate
- {
- get
- {
- return this.bitrate;
- }
-
- set
- {
- this.bitrate = value;
- this.NotifyOfPropertyChange(() => this.Bitrate);
- }
- }
-
-
- /// <summary>
/// Gets or sets Dynamic Range Compression
/// </summary>
public double DRC
@@ -160,7 +149,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models {
this.mixDown = value;
this.NotifyOfPropertyChange(() => this.MixDown);
- this.SetupBitrateLimits();
+ this.SetupLimits();
this.NotifyOfPropertyChange(() => this.TrackReference);
}
}
@@ -180,9 +169,18 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.encoder = value;
this.NotifyOfPropertyChange(() => this.Encoder);
this.NotifyOfPropertyChange(() => this.IsPassthru);
- this.NotifyOfPropertyChange(() => this.CannotSetBitrate);
- this.SetupBitrateLimits();
+ this.NotifyOfPropertyChange(() => this.IsBitrateVisible);
+ this.NotifyOfPropertyChange(() => this.IsQualityVisible);
+ this.NotifyOfPropertyChange(() => this.IsRateTypeVisible);
+ this.SetupLimits();
this.NotifyOfPropertyChange(() => this.TrackReference);
+
+ // Refresh the available encoder rate types.
+ this.NotifyOfPropertyChange(() => this.AudioEncoderRateTypes);
+ if (!this.AudioEncoderRateTypes.Contains(this.EncoderRateType))
+ {
+ this.EncoderRateType = AudioEncoderRateType.Bitrate; // Default to bitrate.
+ }
}
}
@@ -200,16 +198,81 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models {
this.sampleRate = value;
this.NotifyOfPropertyChange(() => this.SampleRate);
- this.SetupBitrateLimits();
+ this.SetupLimits();
this.NotifyOfPropertyChange(() => this.TrackReference);
}
}
+ /// <summary>
+ /// Gets or sets the encoder rate type.
+ /// </summary>
+ public AudioEncoderRateType EncoderRateType
+ {
+ get
+ {
+ return this.encoderRateType;
+ }
+
+ set
+ {
+ this.encoderRateType = value;
+ this.SetupLimits();
+ this.NotifyOfPropertyChange(() => this.EncoderRateType);
+ this.NotifyOfPropertyChange(() => this.IsBitrateVisible);
+ this.NotifyOfPropertyChange(() => this.IsQualityVisible);
+
+ if (!this.Quality.HasValue)
+ {
+ HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));
+ this.Quality = HandBrakeEncoderHelpers.GetDefaultQuality(hbAudioEncoder);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets Audio Bitrate
+ /// </summary>
+ public int Bitrate
+ {
+ get
+ {
+ return this.bitrate;
+ }
+
+ set
+ {
+ this.bitrate = value;
+ this.NotifyOfPropertyChange(() => this.Bitrate);
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets Audio quality
+ /// </summary>
+ public double? Quality
+ {
+ get
+ {
+ return this.quality;
+ }
+
+ set
+ {
+ this.quality = value;
+ this.NotifyOfPropertyChange(() => this.quality);
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the track name.
+ /// </summary>
+ public string TrackName { get; set; }
#endregion
/// <summary>
/// Gets AudioEncoderDisplayValue.
/// </summary>
+ [JsonIgnore]
public string AudioEncoderDisplayValue
{
get
@@ -221,6 +284,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// <summary>
/// Gets AudioMixdownDisplayValue.
/// </summary>
+ [JsonIgnore]
public string AudioMixdownDisplayValue
{
get
@@ -232,6 +296,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// <summary>
/// Gets the The UI display value for bit rate
/// </summary>
+ [JsonIgnore]
public string BitRateDisplayValue
{
get
@@ -244,12 +309,13 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models return this.Bitrate.ToString();
}
- }
+ }
/// <summary>
/// Gets or sets a value indicating whether is default.
/// TODO - Can this be removed? May have been added as a quick fix for a styling quirk.
/// </summary>
+ [JsonIgnore]
public bool IsDefault
{
get
@@ -265,6 +331,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// <summary>
/// Gets or sets the The UI display value for sample rate
/// </summary>
+ [JsonIgnore]
public string SampleRateDisplayValue
{
get
@@ -307,6 +374,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// <summary>
/// Gets the Audio Track Name
/// </summary>
+ [JsonIgnore]
public int? Track
{
get
@@ -323,6 +391,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// <summary>
/// Gets a value indicating whether IsPassthru.
/// </summary>
+ [JsonIgnore]
public bool IsPassthru
{
get
@@ -342,6 +411,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// <summary>
/// Gets the bitrates.
/// </summary>
+ [JsonIgnore]
public IEnumerable<int> Bitrates
{
get
@@ -351,19 +421,91 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models }
/// <summary>
+ /// Gets the quality compression values.
+ /// </summary>
+ [JsonIgnore]
+ public IEnumerable<double> EncoderQualityValues
+ {
+ get
+ {
+ return this.encoderQualityValues;
+ }
+ }
+
+ /// <summary>
+ /// Gets the audio encoder rate types.
+ /// </summary>
+ [JsonIgnore]
+ public IEnumerable<AudioEncoderRateType> AudioEncoderRateTypes
+ {
+ get
+ {
+ IList<AudioEncoderRateType> types = EnumHelper<AudioEncoderRateType>.GetEnumList().ToList();
+ HBAudioEncoder hbaenc = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));
+ if (hbaenc == null || !hbaenc.SupportsQuality)
+ {
+ types.Remove(AudioEncoderRateType.Quality);
+ }
+
+ return types;
+ }
+ }
+
+ /// <summary>
/// Gets a value indicating whether can set bitrate.
/// </summary>
- public bool CannotSetBitrate
+ [JsonIgnore]
+ public bool IsBitrateVisible
+ {
+ get
+ {
+ if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24)
+ {
+ return false;
+ }
+
+ return Equals(this.EncoderRateType, AudioEncoderRateType.Bitrate);
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether is quality visible.
+ /// </summary>
+ [JsonIgnore]
+ public bool IsQualityVisible
{
get
{
- return this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24;
+ if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24)
+ {
+ return false;
+ }
+
+ return Equals(this.EncoderRateType, AudioEncoderRateType.Quality);
+ }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether is rate type visible.
+ /// </summary>
+ [JsonIgnore]
+ public bool IsRateTypeVisible
+ {
+ get
+ {
+ if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24)
+ {
+ return false;
+ }
+
+ return true;
}
}
/// <summary>
/// Gets a value indicating whether IsLossless.
/// </summary>
+ [JsonIgnore]
public bool IsLossless
{
get
@@ -381,10 +523,16 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models get { return this; }
}
+ #region Handler Methods
+
/// <summary>
- /// Gets or sets the track name.
+ /// The setup limits.
/// </summary>
- public string TrackName { get; set; }
+ private void SetupLimits()
+ {
+ this.SetupBitrateLimits();
+ this.SetupQualityCompressionLimits();
+ }
/// <summary>
/// The calculate bitrate limits.
@@ -421,5 +569,68 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.Bitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(hbaenc, rate != null ? rate.Rate : 48000, mixdown);
}
}
+
+ /// <summary>
+ /// The setup quality compression limits.
+ /// </summary>
+ private void SetupQualityCompressionLimits()
+ {
+ HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));
+ if (hbAudioEncoder.SupportsQuality)
+ {
+ RangeLimits limits = null;
+
+ if (hbAudioEncoder.SupportsQuality)
+ {
+ limits = hbAudioEncoder.QualityLimits;
+ }
+
+ if (limits != null)
+ {
+ double value = limits.Ascending ? limits.Low : limits.High;
+ List<double> values = new List<double> { value };
+
+ if (limits.Ascending)
+ {
+ while (value < limits.High)
+ {
+ value += limits.Granularity;
+ values.Add(value);
+ }
+ }
+ else
+ {
+ while (value > limits.Low)
+ {
+ value -= limits.Granularity;
+ values.Add(value);
+ }
+ }
+
+ this.encoderQualityValues = values;
+ }
+ else
+ {
+ this.encoderQualityValues = new List<double>();
+ }
+ }
+ else
+ {
+ this.encoderQualityValues = new List<double>();
+ }
+
+ // Default the audio quality value if it's out of range.
+ if (Equals(this.EncoderRateType, AudioEncoderRateType.Quality))
+ {
+ if (this.Quality.HasValue && !this.encoderQualityValues.Contains(this.Quality.Value))
+ {
+ this.Quality = HandBrakeEncoderHelpers.GetDefaultQuality(hbAudioEncoder);
+ }
+ }
+
+ this.NotifyOfPropertyChange(() => this.EncoderQualityValues);
+ }
+
+ #endregion
}
}
\ No newline at end of file |