diff options
author | [email protected] <sr55> | 2016-01-29 20:55:10 +0000 |
---|---|---|
committer | [email protected] <sr55> | 2016-01-29 20:55:10 +0000 |
commit | db29f87dc3bf3909d263491390d0f56418616e26 (patch) | |
tree | e0adda8c59fb4344fa8cff5ea6465afa130cc260 /win/CS/HandBrakeWPF/Services | |
parent | da7b1d29c60f740037883f44e07415580fc5d9a9 (diff) |
WinGui: Add support for the rotate and flip filter.
Diffstat (limited to 'win/CS/HandBrakeWPF/Services')
3 files changed, 155 insertions, 121 deletions
diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs index 3415f1ee7..62a3faf81 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs @@ -65,17 +65,17 @@ namespace HandBrakeWPF.Services.Encode.Factories internal static JsonEncodeObject Create(EncodeTask job, HBConfiguration configuration) { JsonEncodeObject encode = new JsonEncodeObject - { - SequenceID = 0, - Audio = CreateAudio(job), - Destination = CreateDestination(job), - Filters = CreateFilters(job), - PAR = CreatePAR(job), - Metadata = CreateMetadata(job), - Source = CreateSource(job, configuration), - Subtitle = CreateSubtitle(job), - Video = CreateVideo(job, configuration) - }; + { + SequenceID = 0, + Audio = CreateAudio(job), + Destination = CreateDestination(job), + Filters = CreateFilters(job), + PAR = CreatePAR(job), + Metadata = CreateMetadata(job), + Source = CreateSource(job, configuration), + Subtitle = CreateSubtitle(job), + Video = CreateVideo(job, configuration) + }; return encode; } @@ -145,10 +145,10 @@ namespace HandBrakeWPF.Services.Encode.Factories { File = job.Destination, Mp4Options = new Mp4Options - { - IpodAtom = job.IPod5GSupport, - Mp4Optimize = job.OptimizeMP4 - }, + { + IpodAtom = job.IPod5GSupport, + Mp4Optimize = job.OptimizeMP4 + }, ChapterMarkers = job.IncludeChapterMarkers, Mux = HBFunctions.hb_container_get_from_name(job.OutputFormat == OutputFormat.Mp4 ? "av_mp4" : "av_mkv"), // TODO tidy up. ChapterList = new List<Chapter>() @@ -192,17 +192,17 @@ namespace HandBrakeWPF.Services.Encode.Factories private static Subtitle CreateSubtitle(EncodeTask job) { Subtitles subtitle = new Subtitles - { - Search = + { + Search = new SubtitleSearch - { - Enable = false, - Default = false, - Burn = false, - Forced = false - }, - SubtitleList = new List<HandBrake.ApplicationServices.Interop.Json.Encode.SubtitleTrack>() - }; + { + Enable = false, + Default = false, + Burn = false, + Forced = false + }, + SubtitleList = new List<HandBrake.ApplicationServices.Interop.Json.Encode.SubtitleTrack>() + }; foreach (SubtitleTrack item in job.SubtitleTracks) { @@ -352,28 +352,28 @@ namespace HandBrakeWPF.Services.Encode.Factories 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, - DRC = item.DRC, - Encoder = encoder.Id, - Gain = item.Gain, - Mixdown = mixdown.Id, - NormalizeMixLevel = false, - Samplerate = sampleRate != null ? sampleRate.Rate : 0, - Name = item.TrackName, - }; + { + Track = (item.Track.HasValue ? item.Track.Value : 0) - 1, + DRC = item.DRC, + Encoder = encoder.Id, + Gain = item.Gain, + Mixdown = mixdown.Id, + NormalizeMixLevel = false, + Samplerate = sampleRate != null ? sampleRate.Rate : 0, + Name = item.TrackName, + }; if (!item.IsPassthru) { - if (item.EncoderRateType == AudioEncoderRateType.Quality) - { + if (item.EncoderRateType == AudioEncoderRateType.Quality) + { audioTrack.Quality = item.Quality; - } + } - if (item.EncoderRateType == AudioEncoderRateType.Bitrate) - { + if (item.EncoderRateType == AudioEncoderRateType.Bitrate) + { audioTrack.Bitrate = item.Bitrate; - } + } } audio.AudioList.Add(audioTrack); @@ -394,9 +394,11 @@ namespace HandBrakeWPF.Services.Encode.Factories private static Filters CreateFilters(EncodeTask job) { Filters filter = new Filters - { - FilterList = new List<Filter>(), - }; + { + FilterList = new List<Filter>(), + }; + + // Note, order is important. // Detelecine if (job.Detelecine != Detelecine.Off) @@ -405,27 +407,6 @@ namespace HandBrakeWPF.Services.Encode.Factories filter.FilterList.Add(filterItem); } - // Decomb - if (job.DeinterlaceFilter == DeinterlaceFilter.Decomb) - { - string options; - if (job.Decomb == Decomb.Fast) - { - options = "7:2:6:9:1:80"; - } - else if (job.Decomb == Decomb.Bob) - { - options = "455"; - } - else - { - options = job.CustomDecomb; - } - - Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DECOMB, Settings = options }; - filter.FilterList.Add(filterItem); - } - // Deinterlace if (job.DeinterlaceFilter == DeinterlaceFilter.Deinterlace) { @@ -455,29 +436,24 @@ namespace HandBrakeWPF.Services.Encode.Factories filter.FilterList.Add(filterItem); } - // VFR / CFR - int fm = job.FramerateMode == FramerateMode.CFR ? 1 : job.FramerateMode == FramerateMode.PFR ? 2 : 0; - int? num = null, den = null; - if (job.Framerate != null) + // Decomb + if (job.DeinterlaceFilter == DeinterlaceFilter.Decomb) { - IntPtr frameratePrt = Marshal.StringToHGlobalAnsi(job.Framerate.Value.ToString(CultureInfo.InvariantCulture)); - int vrate = HBFunctions.hb_video_framerate_get_from_name(frameratePrt); - - if (vrate > 0) + string options; + if (job.Decomb == Decomb.Fast) { - num = 27000000; - den = vrate; + options = "7:2:6:9:1:80"; + } + else if (job.Decomb == Decomb.Bob) + { + options = "455"; + } + else + { + options = job.CustomDecomb; } - } - - string framerateString = num.HasValue ? string.Format("{0}:{1}:{2}", fm, num, den) : string.Format("{0}", fm); // filter_cfr, filter_vrate.num, filter_vrate.den - Filter framerateShaper = new Filter { ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateString }; - filter.FilterList.Add(framerateShaper); - // Deblock - if (job.Deblock >= 5) - { - Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEBLOCK, Settings = job.Deblock.ToString() }; + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DECOMB, Settings = options }; filter.FilterList.Add(filterItem); } @@ -503,9 +479,10 @@ namespace HandBrakeWPF.Services.Encode.Factories filter.FilterList.Add(filterItem); } - if (job.Grayscale) + // Deblock + if (job.Deblock >= 5) { - Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_GRAYSCALE, Settings = null }; + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEBLOCK, Settings = job.Deblock.ToString() }; filter.FilterList.Add(filterItem); } @@ -525,8 +502,38 @@ namespace HandBrakeWPF.Services.Encode.Factories }; filter.FilterList.Add(cropScale); + // Grayscale + if (job.Grayscale) + { + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_GRAYSCALE, Settings = null }; + filter.FilterList.Add(filterItem); + } + // Rotate - /* TODO NOT SUPPORTED YET. */ + if (job.Rotation != 0 || job.FlipVideo) + { + Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_ROTATE, Settings = string.Format("{0}:{1}", job.Rotation, job.FlipVideo ? "1" : "0") }; + filter.FilterList.Add(filterItem); + } + + // Framerate shaping filter + int fm = job.FramerateMode == FramerateMode.CFR ? 1 : job.FramerateMode == FramerateMode.PFR ? 2 : 0; + int? num = null, den = null; + if (job.Framerate != null) + { + IntPtr frameratePrt = Marshal.StringToHGlobalAnsi(job.Framerate.Value.ToString(CultureInfo.InvariantCulture)); + int vrate = HBFunctions.hb_video_framerate_get_from_name(frameratePrt); + + if (vrate > 0) + { + num = 27000000; + den = vrate; + } + } + + string framerateString = num.HasValue ? string.Format("{0}:{1}:{2}", fm, num, den) : string.Format("{0}", fm); // filter_cfr, filter_vrate.num, filter_vrate.den + Filter framerateShaper = new Filter { ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateString }; + filter.FilterList.Add(framerateShaper); return filter; } diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs index 03cea74f5..0ae588bc7 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/EncodeTask.cs @@ -101,6 +101,9 @@ namespace HandBrakeWPF.Services.Encode.Model this.DenoiseTune = task.DenoiseTune; this.Destination = task.Destination; this.Detelecine = task.Detelecine; + this.FlipVideo = task.FlipVideo; + this.Rotation = task.Rotation; + this.DisplayWidth = task.DisplayWidth; this.EndPoint = task.EndPoint; this.Framerate = task.Framerate; @@ -339,6 +342,15 @@ namespace HandBrakeWPF.Services.Encode.Model /// </summary> public bool Grayscale { get; set; } + /// <summary> + /// Rotate the Video by x Degrees + /// </summary> + public int Rotation { get; set; } + + /// <summary> + /// Flip the video. + /// </summary> + public bool FlipVideo { get; set; } #endregion #region Video diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index 9cdb554d1..dbb702a77 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -13,6 +13,7 @@ namespace HandBrakeWPF.Services.Presets.Factories using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
+ using System.Windows.Forms.VisualStyles;
using HandBrake.ApplicationServices.Interop.Json.Presets;
using HandBrake.ApplicationServices.Interop.Model;
@@ -61,7 +62,7 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.Task = new EncodeTask();
preset.IsDefault = importedPreset.Default;
preset.IsBuildIn = importedPreset.Type == 0;
-
+
// Step 1, Create the EncodeTask Object that can be loaded into the UI.
/* Output Settings */
@@ -77,7 +78,7 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.Task.HasCropping = !importedPreset.PictureAutoCrop;
preset.Task.Modulus = importedPreset.PictureModulus;
preset.Task.KeepDisplayAspect = importedPreset.PictureKeepRatio;
-
+
switch (importedPreset.PicturePAR)
{
case "custom":
@@ -247,6 +248,21 @@ namespace HandBrakeWPF.Services.Presets.Factories break;
}
+ // Rotation and Flip
+ if (!string.IsNullOrEmpty(importedPreset.PictureRotate))
+ {
+ string[] rotation = importedPreset.PictureRotate.Split(':');
+ if (rotation.Length == 2)
+ {
+ int rotate;
+ if (int.TryParse(rotation[0], out rotate))
+ {
+ preset.Task.Rotation = int.Parse(rotation[0]);
+ preset.Task.FlipVideo = rotation[1] == "1";
+ }
+ }
+ }
+
/* Video Settings */
preset.Task.VideoEncoder = EnumHelper<VideoEncoder>.GetValue(importedPreset.VideoEncoder);
preset.Task.VideoBitrate = importedPreset.VideoAvgBitrate;
@@ -284,7 +300,7 @@ namespace HandBrakeWPF.Services.Presets.Factories break;
}
- /* Audio Settings */
+ /* Audio Settings */
preset.AudioTrackBehaviours = new AudioBehaviours();
preset.Task.AllowedPassthruOptions.AudioEncoderFallback = EnumHelper<AudioEncoder>.GetValue(importedPreset.AudioEncoderFallback);
preset.AudioTrackBehaviours.SelectedBehaviour = importedPreset.AudioTrackSelectionBehavior == "all"
@@ -353,8 +369,8 @@ namespace HandBrakeWPF.Services.Presets.Factories // track.CompressionLevel = audioTrack.AudioCompressionLevel;
// track.AudioDitherMethod = audioTrack.AudioDitherMethod;
- track.Encoder = EnumHelper<AudioEncoder>.GetValue(audioTrack.AudioEncoder);
- track.MixDown = EnumHelper<Mixdown>.GetValue(audioTrack.AudioMixdown);
+ track.Encoder = EnumHelper<AudioEncoder>.GetValue(audioTrack.AudioEncoder);
+ track.MixDown = EnumHelper<Mixdown>.GetValue(audioTrack.AudioMixdown);
// track.AudioNormalizeMixLevel = audioTrack.AudioNormalizeMixLevel;
track.SampleRate = audioTrack.AudioSamplerate == "auto" ? 0 : double.Parse(audioTrack.AudioSamplerate);
@@ -368,7 +384,7 @@ namespace HandBrakeWPF.Services.Presets.Factories }
}
- /* Subtitle Settings */
+ /* Subtitle Settings */
preset.SubtitleTrackBehaviours = new SubtitleBehaviours();
preset.SubtitleTrackBehaviours.SelectedBehaviour = EnumHelper<SubtitleBehaviourModes>.GetValue(importedPreset.SubtitleTrackSelectionBehavior);
preset.SubtitleTrackBehaviours.SelectedBurnInBehaviour = EnumHelper<SubtitleBurnInBehaviourModes>.GetValue(importedPreset.SubtitleBurnBehavior);
@@ -387,11 +403,11 @@ namespace HandBrakeWPF.Services.Presets.Factories /* Chapter Marker Settings */
preset.Task.IncludeChapterMarkers = importedPreset.ChapterMarkers;
- /* Advanced Settings */
+ /* Advanced Settings */
preset.Task.ShowAdvancedTab = importedPreset.x264UseAdvancedOptions;
preset.Task.AdvancedEncoderOptions = importedPreset.x264Option;
- /* Not Supported Yet */
+ /* Not Supported Yet */
// public int VideoColorMatrixCode { get; set; }
// public bool VideoHWDecode { get; set; }
// public string VideoScaler { get; set; }
@@ -404,7 +420,6 @@ namespace HandBrakeWPF.Services.Presets.Factories // public bool PictureLooseCrop { get; set; }
// public int PicturePARWidth { get; set; }
// public int PicturePARHeight { get; set; }
- // public int PictureRotate { get; set; }
// public int PictureForceHeight { get; set; }
// public int PictureForceWidth { get; set; }
// public List<object> ChildrenArray { get; set; }
@@ -491,23 +506,23 @@ namespace HandBrakeWPF.Services.Presets.Factories foreach (var item in export.Task.AudioTracks)
{
AudioList track = new AudioList
- {
- AudioBitrate = item.Bitrate,
- AudioCompressionLevel = 0, // TODO
- AudioDitherMethod = null, // TODO
- AudioEncoder = EnumHelper<AudioEncoder>.GetShortName(item.Encoder),
- AudioMixdown = EnumHelper<Mixdown>.GetShortName(item.MixDown),
- AudioNormalizeMixLevel = false, // TODO
- AudioSamplerate = item.SampleRate == 0 ? "auto" : item.SampleRate.ToString(), // TODO check formatting.
- AudioTrackDRCSlider = item.DRC,
- AudioTrackGainSlider = item.Gain,
- AudioTrackQuality = item.Quality ?? 0,
- AudioTrackQualityEnable = item.Quality.HasValue && item.IsQualityVisible
- };
-
+ {
+ AudioBitrate = item.Bitrate,
+ AudioCompressionLevel = 0, // TODO
+ AudioDitherMethod = null, // TODO
+ AudioEncoder = EnumHelper<AudioEncoder>.GetShortName(item.Encoder),
+ AudioMixdown = EnumHelper<Mixdown>.GetShortName(item.MixDown),
+ AudioNormalizeMixLevel = false, // TODO
+ AudioSamplerate = item.SampleRate == 0 ? "auto" : item.SampleRate.ToString(), // TODO check formatting.
+ AudioTrackDRCSlider = item.DRC,
+ AudioTrackGainSlider = item.Gain,
+ AudioTrackQuality = item.Quality ?? 0,
+ AudioTrackQualityEnable = item.Quality.HasValue && item.IsQualityVisible
+ };
+
preset.AudioList.Add(track);
}
-
+
// Subtitles
preset.SubtitleAddCC = export.SubtitleTrackBehaviours.AddClosedCaptions;
preset.SubtitleAddForeignAudioSearch = export.SubtitleTrackBehaviours.AddForeignAudioScanTrack;
@@ -536,9 +551,9 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.PictureModulus = export.Task.Modulus ?? 16;
preset.PicturePAR = EnumHelper<Anamorphic>.GetShortName(export.Task.Anamorphic);
preset.PicturePARHeight = export.Task.PixelAspectY;
- preset.PicturePARWidth = export.Task.PixelAspectX;
+ preset.PicturePARWidth = export.Task.PixelAspectX;
preset.PictureRightCrop = export.Task.Cropping.Right;
- preset.PictureRotate = 0; // TODO Not supported yet.
+ preset.PictureRotate = string.Format("{0}:{1}", export.Task.Rotation, export.Task.FlipVideo ? "1" : "0");
preset.PictureTopCrop = export.Task.Cropping.Top;
preset.PictureWidth = preset.UsesPictureSettings >= 1 ? export.Task.MaxWidth : 0; // TODO
preset.PictureDARWidth = export.Task.DisplayWidth.HasValue ? (int)export.Task.DisplayWidth.Value : 0;
@@ -547,20 +562,20 @@ namespace HandBrakeWPF.Services.Presets.Factories // Filters
preset.PictureDeblock = export.Task.Deblock;
- preset.PictureDeinterlaceFilter = export.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb
- ? "decomb"
- : export.Task.DeinterlaceFilter == DeinterlaceFilter.Deinterlace ? "deinterlace" : "off";
- preset.PictureDeinterlacePreset = export.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb
- ? EnumHelper<Decomb>.GetShortName(export.Task.Decomb)
+ preset.PictureDeinterlaceFilter = export.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb
+ ? "decomb"
+ : export.Task.DeinterlaceFilter == DeinterlaceFilter.Deinterlace ? "deinterlace" : "off";
+ preset.PictureDeinterlacePreset = export.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb
+ ? EnumHelper<Decomb>.GetShortName(export.Task.Decomb)
: export.Task.DeinterlaceFilter == DeinterlaceFilter.Deinterlace ? EnumHelper<Deinterlace>.GetShortName(export.Task.Deinterlace) : string.Empty;
- preset.PictureDeinterlaceCustom = export.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb
- ? export.Task.CustomDecomb
+ preset.PictureDeinterlaceCustom = export.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb
+ ? export.Task.CustomDecomb
: export.Task.DeinterlaceFilter == DeinterlaceFilter.Deinterlace ? export.Task.CustomDeinterlace : string.Empty;
preset.PictureDeinterlaceCustom = export.Task.CustomDeinterlace;
preset.PictureDenoiseCustom = export.Task.CustomDenoise;
preset.PictureDenoiseFilter = EnumHelper<Denoise>.GetShortName(export.Task.Denoise);
preset.PictureDenoisePreset = EnumHelper<DenoisePreset>.GetShortName(export.Task.DenoisePreset);
- preset.PictureDenoiseTune = EnumHelper<DenoiseTune>.GetShortName(export.Task.DenoiseTune);
+ preset.PictureDenoiseTune = EnumHelper<DenoiseTune>.GetShortName(export.Task.DenoiseTune);
preset.PictureDetelecine = EnumHelper<Detelecine>.GetShortName(export.Task.Detelecine);
preset.PictureDetelecineCustom = export.Task.CustomDetelecine;
|