diff options
author | randomengy <[email protected]> | 2014-08-03 04:33:09 +0000 |
---|---|---|
committer | randomengy <[email protected]> | 2014-08-03 04:33:09 +0000 |
commit | 9474387d2ae72794970b8ca2a9e8f8facdc0fdab (patch) | |
tree | 11ac1b628d8c43af0301bd45be0089ad2d7b50ce /win/CS/HandBrake.Interop | |
parent | e4b94f18017bcbf9d7f26fb2486ff3a745d55eef (diff) |
Interop: Added support for NL-Means denoise.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6260 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrake.Interop')
8 files changed, 70 insertions, 103 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index 0e484794c..b08facbd2 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -1212,28 +1212,9 @@ namespace HandBrake.Interop // Denoise
if (profile.Denoise != Denoise.Off)
{
- string settings = null;
- switch (profile.DenoisePreset)
- {
- case DenoisePreset.Weak:
- settings = "2:1:1:2:3:3";
- break;
- case DenoisePreset.Medium:
- settings = "3:2:2:2:3:3";
- break;
- case DenoisePreset.Strong:
- settings = "7:7:7:5:5:5";
- break;
- case DenoisePreset.Custom:
- settings = profile.CustomDenoise;
- break;
- // TODO Add new Presets.
- default:
- break;
- }
+ int filterType = profile.Denoise == Denoise.hqdn3d ? (int)hb_filter_ids.HB_FILTER_HQDN3D : (int)hb_filter_ids.HB_FILTER_NLMEANS;
- // TODO Add Tunes
- this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DENOISE, settings, allocatedMemory);
+ this.AddFilterFromPreset(filterList, filterType, profile.DenoisePreset, profile.DenoiseTune);
}
// Crop/scale
@@ -1279,7 +1260,9 @@ namespace HandBrake.Interop width = outputSize.Width;
height = outputSize.Height;
- nativeJob.anamorphic.keep_display_aspect = profile.KeepDisplayAspect ? 1 : 0;
+ nativeJob.anamorphic.keep_display_aspect = 0;
+ nativeJob.anamorphic.par_width = 1;
+ nativeJob.anamorphic.par_height = 1;
nativeJob.width = width;
nativeJob.height = height;
@@ -1677,6 +1660,23 @@ namespace HandBrake.Interop filterList.Add(filter);
}
+ /// <summary>
+ /// Adds a filter to the given filter list with the provided preset and tune.
+ /// </summary>
+ /// <param name="filterList">The list to add the filter to.</param>
+ /// <param name="filterType">The type of filter.</param>
+ /// <param name="preset">The preset name.</param>
+ /// <param name="tune">The tune name.</param>
+ private void AddFilterFromPreset(List<hb_filter_object_s> filterList, int filterType, string preset, string tune)
+ {
+ IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings(filterType, preset, tune);
+
+ hb_filter_object_s filter = InteropUtilities.ToStructureFromPtr<hb_filter_object_s>(HBFunctions.hb_filter_init(filterType));
+ filter.settings = settingsPtr;
+
+ filterList.Add(filter);
+ }
+
/// <summary>
/// Converts the given filter list to a native list.
/// </summary>
@@ -1777,12 +1777,16 @@ namespace HandBrake.Interop bool isPassthrough = encoder.IsPassthrough;
+ HBAudioEncoder inputCodec = Encoders.GetAudioEncoder((int)baseStruct.config.input.codec);
+
uint outputCodec = (uint)encoder.Id;
if (encoding.PassthroughIfPossible &&
- encoder.Id == baseStruct.config.input.codec &&
- (encoder.Id & NativeConstants.HB_ACODEC_PASS_MASK) > 0)
+ (encoder.Id == baseStruct.config.input.codec ||
+ inputCodec != null && (inputCodec.ShortName.ToLowerInvariant().Contains("aac") && encoder.ShortName.ToLowerInvariant().Contains("aac") ||
+ inputCodec.ShortName.ToLowerInvariant().Contains("mp3") && encoder.ShortName.ToLowerInvariant().Contains("mp3"))) &&
+ (inputCodec.Id & NativeConstants.HB_ACODEC_PASS_MASK) > 0)
{
- outputCodec |= NativeConstants.HB_ACODEC_PASS_FLAG;
+ outputCodec = baseStruct.config.input.codec | NativeConstants.HB_ACODEC_PASS_FLAG;
isPassthrough = true;
}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj index a1f1b076b..59d7835f3 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInterop.csproj @@ -174,8 +174,6 @@ <Compile Include="HbLib\NativeConstants.cs" />
<Compile Include="Interfaces\IHandBrakeInstance.cs" />
<Compile Include="Helpers\InteropUtilities.cs" />
- <Compile Include="Model\Encoding\DenoisePreset.cs" />
- <Compile Include="Model\Encoding\DenoiseTune.cs" />
<Compile Include="Model\Encoding\PictureRotation.cs" />
<Compile Include="Model\Encoding\x265\x265Preset.cs" />
<Compile Include="Model\Encoding\x265\x265Profile.cs" />
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs index 9402d0940..cf8193f52 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/HbFunctions.cs @@ -444,6 +444,12 @@ namespace HandBrake.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_filter_init", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hb_filter_init(int filter_id);
+ [DllImport("hb.dll", EntryPoint = "hb_generate_filter_settings", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr hb_generate_filter_settings(
+ int filter_id,
+ [In] [MarshalAs(UnmanagedType.LPStr)] string preset,
+ [In] [MarshalAs(UnmanagedType.LPStr)] string tune);
+
[DllImport("hb.dll", EntryPoint = "hb_x264_encopt_name", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr hb_x264_encopt_name(IntPtr name);
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_ids.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_ids.cs index 3c56b7f75..90b60d846 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_ids.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/hb_filter_ids.cs @@ -17,7 +17,8 @@ namespace HandBrake.Interop.HbLib HB_FILTER_VFR,
// Filters that must operate on the original source image are next
HB_FILTER_DEBLOCK,
- HB_FILTER_DENOISE,
+ HB_FILTER_HQDN3D,
+ HB_FILTER_NLMEANS,
HB_FILTER_RENDER_SUB,
HB_FILTER_CROP_SCALE,
// Finally filters that don't care what order they are in,
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs index f27fad285..295586c8f 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoders.cs @@ -201,6 +201,16 @@ namespace HandBrake.Interop.Model }
/// <summary>
+ /// Gets the audio encoder with the specified codec ID.
+ /// </summary>
+ /// <param name="codecId">The ID of the audio encoder.</param>
+ /// <returns>The requested audio encoder.</returns>
+ public static HBAudioEncoder GetAudioEncoder(int codecId)
+ {
+ return AudioEncoders.SingleOrDefault(e => e.Id == codecId);
+ }
+
+ /// <summary>
/// Gets the video encoder with the specified short name.
/// </summary>
/// <param name="shortName">The name of the video encoder.</param>
@@ -276,6 +286,16 @@ namespace HandBrake.Interop.Model }
/// <summary>
+ /// Determines if the given input audio codec can be passed through.
+ /// </summary>
+ /// <param name="codecId">The input codec to consider.</param>
+ /// <returns>True if the codec can be passed through.</returns>
+ public static bool CanPassthroughAudio(int codecId)
+ {
+ return (codecId & NativeConstants.HB_ACODEC_PASS_MASK) > 0;
+ }
+
+ /// <summary>
/// Sanitizes a mixdown given the output codec and input channel layout.
/// </summary>
/// <param name="mixdown">The desired mixdown.</param>
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoisePreset.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoisePreset.cs deleted file mode 100644 index b26635052..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoisePreset.cs +++ /dev/null @@ -1,37 +0,0 @@ -// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="DenoisePreset.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>
-// Defines the DenoisePreset type.
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrake.Interop.Model.Encoding
-{
- using System.ComponentModel.DataAnnotations;
-
- /// <summary>
- /// The denoise preset.
- /// </summary>
- public enum DenoisePreset
- {
- [Display(Name = "Weak")]
- Weak = 0,
-
- [Display(Name = "Medium")]
- Medium,
-
- [Display(Name = "Strong")]
- Strong,
-
- [Display(Name = "Custom")]
- Custom,
-
- [Display(Name = "Ultralight")] // NLMeans only
- Ultralight,
-
- [Display(Name = "Light")] // NLMeans only
- Light,
- }
-}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoiseTune.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoiseTune.cs deleted file mode 100644 index 35b5843a8..000000000 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/DenoiseTune.cs +++ /dev/null @@ -1,34 +0,0 @@ -// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="DenoiseTune.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>
-// Defines the DenoiseTune type.
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrake.Interop.Model.Encoding
-{
- using System.ComponentModel.DataAnnotations;
-
- /// <summary>
- /// The denoise tune.
- /// </summary>
- public enum DenoiseTune
- {
- [Display(Name = "None")]
- None = 0,
-
- [Display(Name = "Film")]
- Film,
-
- [Display(Name = "Grain")]
- Grain,
-
- [Display(Name = "High Motion")]
- HighMotion,
-
- [Display(Name = "Animation")]
- Animation,
- }
-}
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs index 834ef5576..bcabcf282 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/Model/Encoding/EncodingProfile.cs @@ -185,14 +185,20 @@ namespace HandBrake.Interop.Model.Encoding public Denoise Denoise { get; set; }
/// <summary>
- /// Gets or sets the denoise preset.
+ /// Gets or sets the denoise preset name.
/// </summary>
- public DenoisePreset DenoisePreset { get; set; }
+ public string DenoisePreset { get; set; }
/// <summary>
- /// Gets or sets the denoise tune.
+ /// Gets or sets the denoise tune name.
/// </summary>
- public DenoiseTune DenoiseTune { get; set; }
+ public string DenoiseTune { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether we should use the provided
+ /// custom denoise string or we should use the preset and tune.
+ /// </summary>
+ public bool UseCustomDenoise { get; set; }
/// <summary>
/// Gets or sets the custom denoise.
@@ -343,6 +349,9 @@ namespace HandBrake.Interop.Model.Encoding Detelecine = this.Detelecine,
CustomDetelecine = this.CustomDetelecine,
Denoise = this.Denoise,
+ DenoisePreset = this.DenoisePreset,
+ DenoiseTune = this.DenoiseTune,
+ UseCustomDenoise = this.UseCustomDenoise,
CustomDenoise = this.CustomDenoise,
Deblock = this.Deblock,
Grayscale = this.Grayscale,
|