diff options
Diffstat (limited to 'win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs')
-rw-r--r-- | win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs | 170 |
1 files changed, 116 insertions, 54 deletions
diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index e019e9610..c62f96fb6 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -11,6 +11,7 @@ namespace HandBrake.Interop {
using System;
using System.Collections.Generic;
+ using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
@@ -251,7 +252,7 @@ namespace HandBrake.Interop IntPtr nativeBuffer = Marshal.AllocHGlobal(imageBufferSize);
allocatedMemory.Add(nativeBuffer);
HBFunctions.hb_set_job(this.hbHandle, job.Title, ref nativeJob);
- HBFunctions.hb_get_preview(this.hbHandle, ref title, previewNumber, nativeBuffer);
+ HBFunctions.hb_get_preview(this.hbHandle, ref title, previewNumber, nativeBuffer);
// Copy the filled image buffer to a managed array.
byte[] managedBuffer = new byte[imageBufferSize];
@@ -593,7 +594,7 @@ namespace HandBrake.Interop int refParHeight = 0;
HBFunctions.hb_set_job(this.hbHandle, job.Title, ref nativeJob);
//HBFunctions.hb_set_anamorphic_size_by_index(this.hbHandle, job.Title, ref refWidth, ref refHeight, ref refParWidth, ref refParHeight);
- HBFunctions.hb_set_anamorphic_size(ref nativeJob, ref refWidth, ref refHeight, ref refParWidth, ref refParHeight);
+ HBFunctions.hb_set_anamorphic_size(ref nativeJob, ref refWidth, ref refHeight, ref refParWidth, ref refParHeight);
InteropUtilities.FreeMemory(allocatedMemory);
width = refWidth;
@@ -988,6 +989,48 @@ namespace HandBrake.Interop nativeJob.crop[2] = crop.Left;
nativeJob.crop[3] = crop.Right;
+ var filterList = new List<IntPtr>();
+
+ // FILTERS: These must be added in the correct order since we cannot depend on the automatic ordering in hb_add_filter . Ordering is determined
+ // by the order they show up in the filters enum.
+
+ // Detelecine
+ if (profile.Detelecine != Detelecine.Off)
+ {
+ string settings = null;
+ if (profile.Detelecine == Detelecine.Custom)
+ {
+ settings = profile.CustomDetelecine;
+ }
+
+ this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DETELECINE, settings, allocatedMemory);
+ }
+
+ // Decomb
+ if (profile.Decomb != Decomb.Off)
+ {
+ string settings = null;
+ switch (profile.Decomb)
+ {
+ case Decomb.Default:
+ break;
+ case Decomb.Fast:
+ settings = "7:2:6:9:1:80";
+ break;
+ case Decomb.Bob:
+ settings = "455";
+ break;
+ case Decomb.Custom:
+ settings = profile.CustomDecomb;
+ break;
+ default:
+ break;
+ }
+
+ this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DECOMB, settings, allocatedMemory);
+ }
+
+ // Deinterlace
if (profile.Deinterlace != Deinterlace.Off)
{
nativeJob.deinterlace = 1;
@@ -996,13 +1039,16 @@ namespace HandBrake.Interop switch (profile.Deinterlace)
{
case Deinterlace.Fast:
- settings = "-1";
+ settings = "0";
break;
case Deinterlace.Slow:
- settings = "2";
+ settings = "1";
break;
case Deinterlace.Slower:
- settings = "0";
+ settings = "3";
+ break;
+ case Deinterlace.Bob:
+ settings = "15";
break;
case Deinterlace.Custom:
settings = profile.CustomDeinterlace;
@@ -1011,40 +1057,57 @@ namespace HandBrake.Interop break;
}
- this.AddFilter(nativeJob, NativeConstants.HB_FILTER_DEINTERLACE, settings, allocatedMemory);
+ this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DEINTERLACE, settings, allocatedMemory);
}
else
{
nativeJob.deinterlace = 0;
}
- if (profile.Detelecine != Detelecine.Off)
+ // VFR
+ if (profile.Framerate == 0)
{
- string settings = null;
- if (profile.Detelecine == Detelecine.Custom)
+ if (profile.ConstantFramerate)
{
- settings = profile.CustomDetelecine;
+ // CFR with "Same as Source". Use the title rate
+ nativeJob.cfr = 1;
+ nativeJob.vrate = originalTitle.rate;
+ nativeJob.vrate_base = originalTitle.rate_base;
+ }
+ else
+ {
+ // Pure VFR "Same as Source"
+ nativeJob.cfr = 0;
}
-
- this.AddFilter(nativeJob, NativeConstants.HB_FILTER_DETELECINE, settings, allocatedMemory);
}
-
- if (profile.Decomb != Decomb.Off)
+ else
{
- string settings = null;
- if (profile.Decomb == Decomb.Custom)
+ // Specified framerate
+ if (profile.ConstantFramerate)
+ {
+ // Mark as pure CFR
+ nativeJob.cfr = 1;
+ }
+ else
{
- settings = profile.CustomDecomb;
+ // Mark as peak framerate
+ nativeJob.cfr = 2;
}
- this.AddFilter(nativeJob, NativeConstants.HB_FILTER_DECOMB, settings, allocatedMemory);
+ nativeJob.vrate = 27000000;
+ nativeJob.vrate_base = Converters.FramerateToVrate(profile.Framerate);
}
+ string vfrSettings = string.Format(CultureInfo.InvariantCulture, "{0}:{1}:{2}", nativeJob.cfr, nativeJob.vrate, nativeJob.vrate_base);
+ this.AddFilter(filterList, (int) hb_filter_ids.HB_FILTER_VFR, vfrSettings, allocatedMemory);
+
+ // Deblock
if (profile.Deblock > 0)
{
- this.AddFilter(nativeJob, NativeConstants.HB_FILTER_DEBLOCK, profile.Deblock.ToString(), allocatedMemory);
+ this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DEBLOCK, profile.Deblock.ToString(CultureInfo.InvariantCulture), allocatedMemory);
}
+ // Denoise
if (profile.Denoise != Denoise.Off)
{
string settings = null;
@@ -1066,9 +1129,10 @@ namespace HandBrake.Interop break;
}
- this.AddFilter(nativeJob, NativeConstants.HB_FILTER_DENOISE, settings, allocatedMemory);
+ this.AddFilter(filterList, (int)hb_filter_ids.HB_FILTER_DENOISE, settings, allocatedMemory);
}
+ // Crop/scale
int width = profile.Width;
int height = profile.Height;
@@ -1169,6 +1233,24 @@ namespace HandBrake.Interop nativeJob.maxWidth = profile.MaxWidth;
nativeJob.maxHeight = profile.MaxHeight;
+ string cropScaleSettings = string.Format(
+ CultureInfo.InvariantCulture,
+ "{0}:{1}:{2}:{3}:{4}:{5}",
+ nativeJob.width,
+ nativeJob.height,
+ nativeJob.crop[0],
+ nativeJob.crop[1],
+ nativeJob.crop[2],
+ nativeJob.crop[3]);
+ this.AddFilter(filterList, (int) hb_filter_ids.HB_FILTER_CROP_SCALE, cropScaleSettings, allocatedMemory);
+
+ // Construct final filter list
+ NativeList filterListNative = InteropUtilities.CreateIntPtrList(filterList);
+ nativeJob.list_filter = filterListNative.ListPtr;
+ allocatedMemory.AddRange(filterListNative.AllocatedMemory);
+
+
+
HBVideoEncoder videoEncoder = Encoders.VideoEncoders.FirstOrDefault(e => e.ShortName == profile.VideoEncoder);
if (videoEncoder == null)
{
@@ -1177,26 +1259,8 @@ namespace HandBrake.Interop nativeJob.vcodec = videoEncoder.Id;
- if (profile.Framerate == 0)
- {
- nativeJob.cfr = 0;
- }
- else
- {
- if (profile.PeakFramerate)
- {
- nativeJob.cfr = 2;
- }
- else
- {
- nativeJob.cfr = 1;
- }
- nativeJob.vrate = 27000000;
- nativeJob.vrate_base = Converters.FramerateToVrate(profile.Framerate);
- }
- // vfr
// areBframes
// color_matrix
List<hb_audio_s> titleAudio = InteropUtilities.ConvertList<hb_audio_s>(originalTitle.list_audio);
@@ -1277,7 +1341,7 @@ namespace HandBrake.Interop subtitleConfig.force = sourceSubtitle.Forced ? 1 : 0;
subtitleConfig.default_track = sourceSubtitle.Default ? 1 : 0;
- bool supportsBurn = nativeSubtitle.source == hb_subtitle_s_subsource.VOBSUB || nativeSubtitle.source == hb_subtitle_s_subsource.SSASUB;
+ bool supportsBurn = nativeSubtitle.source == hb_subtitle_s_subsource.VOBSUB || nativeSubtitle.source == hb_subtitle_s_subsource.SSASUB || nativeSubtitle.source == hb_subtitle_s_subsource.PGSSUB;
if (supportsBurn && sourceSubtitle.BurnedIn)
{
subtitleConfig.dest = hb_subtitle_config_s_subdest.RENDERSUB;
@@ -1404,24 +1468,22 @@ namespace HandBrake.Interop /// <summary>
/// Adds a filter to the given filter list.
/// </summary>
- /// <param name="job">
- /// The job.
- /// </param>
- /// <param name="filterType">
- /// The type of filter.
- /// </param>
- /// <param name="settings">
- /// Settings for the filter.
- /// </param>
- /// <param name="allocatedMemory">
- /// The list of allocated memory.
- /// </param>
- private void AddFilter(hb_job_s job, int filterType, string settings, List<IntPtr> allocatedMemory)
+ /// <param name="filterList">The list to add the filter to.</param>
+ /// <param name="filterType">The type of filter.</param>
+ /// <param name="settings">Settings for the filter.</param>
+ /// <param name="allocatedMemory">The list of allocated memory.</param>
+ private void AddFilter(List<IntPtr> filterList, int filterType, string settings, List<IntPtr> allocatedMemory)
{
IntPtr settingsNativeString = Marshal.StringToHGlobalAnsi(settings);
- hb_filter_object_s filter = HBFunctions.hb_filter_init(filterType);
- HBFunctions.hb_add_filter(ref job, filter, settingsNativeString);
+ hb_filter_object_s filter = InteropUtilities.ReadStructure<hb_filter_object_s>(HBFunctions.hb_filter_init(filterType));
+ filter.settings = settingsNativeString;
+
+ IntPtr filterPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(hb_filter_object_s)));
+ Marshal.StructureToPtr(filter, filterPtr, false);
+
+ filterList.Add(filterPtr);
allocatedMemory.Add(settingsNativeString);
+ allocatedMemory.Add(filterPtr);
}
/// <summary>
|