private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var title = (SourceTitle)e.NewValue; var chapterBar = d as RangeBar; if (title == null) { return; } List <SourceChapter> chapters = title.ChapterList; chapterBar.markersUpdated = false; chapterBar.totalDuration = title.Duration.ToSpan(); chapterBar.totalSeconds = HandBrakeUnitConversionHelpers.PtsToSeconds((ulong)title.Duration.Ticks); ulong pts = 0; chapterBar.chapterFractions = new List <double>(); foreach (SourceChapter chapter in chapters) { pts += (ulong)chapter.Duration.Ticks; chapterBar.chapterFractions.Add(Math.Min(HandBrakeUnitConversionHelpers.PtsToSeconds(pts) / chapterBar.totalSeconds, 1)); } chapterBar.UpdateSeekBarUI(); chapterBar.UpdateMarkers(); }
private void UpdateMarkers() { if (this.markersUpdated) { return; } if (this.ChaptersEnabled) { if (this.StartChapter <= 0 || this.EndChapter <= 0 || this.Chapters == null) { return; } } double barWidth = this.barHolder.ActualWidth; if (barWidth == 0) { return; } this.markersGrid.Children.Clear(); if (this.ChaptersEnabled) { ulong pts = 0; for (int i = 1; i < this.Chapters.Count - 1; i++) { pts += (ulong)this.Chapters[i - 1].Duration.Ticks; var marker = new Polygon { Style = this.FindResource("SeekBarTick") as Style, Margin = new Thickness(barWidth * (HandBrakeUnitConversionHelpers.PtsToSeconds(pts) / this.totalSeconds) - 1, 0, 0, 0), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; this.markersGrid.Children.Add(marker); } } for (int minutes = 10; minutes * 60 < this.totalSeconds; minutes += 10) { string style = minutes % 60 == 0 ? "SeekBarBigTick" : "SeekBarTick"; var marker = new Polygon { Style = this.FindResource(style) as Style, Margin = new Thickness(barWidth * ((minutes * 60) / this.totalSeconds) - 1, 0, 0, 0), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Bottom }; this.markersGrid.Children.Add(marker); } this.markersUpdated = true; }
private double GetBarFractionFromChapter(int chapter) { ulong pts = 0; for (int i = 1; i <= chapter; i++) { pts += (ulong)this.Chapters[i - 1].Duration.Ticks; } return GetBarFractionFromSeconds(HandBrakeUnitConversionHelpers.PtsToSeconds(pts)); }
private Filters CreateFilters(EncodeTask job) { Filters filter = new Filters { FilterList = new List <Filter>(), }; // Note, order is important. // Detelecine if (job.Detelecine != Detelecine.Off) { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DETELECINE, null, null, job.CustomDetelecine); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DETELECINE, Settings = settings }; filter.FilterList.Add(filterItem); } } // Deinterlace if (job.DeinterlaceFilter == DeinterlaceFilter.Yadif) { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DEINTERLACE, job.DeinterlacePreset?.ShortName, null, job.CustomDeinterlaceSettings); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument root = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEINTERLACE, Settings = root }; filter.FilterList.Add(filterItem); } } // Decomb if (job.DeinterlaceFilter == DeinterlaceFilter.Decomb) { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DECOMB, job.DeinterlacePreset?.ShortName, null, job.CustomDeinterlaceSettings); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DECOMB, Settings = settings }; filter.FilterList.Add(filterItem); } } if (job.DeinterlaceFilter == DeinterlaceFilter.Decomb || job.DeinterlaceFilter == DeinterlaceFilter.Yadif) { if (job.CombDetect != CombDetect.Off) { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_COMB_DETECT, EnumHelper <CombDetect> .GetShortName(job.CombDetect), null, job.CustomCombDetect); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_COMB_DETECT, Settings = settings }; filter.FilterList.Add(filterItem); } } } // Denoise if (job.Denoise != Denoise.Off) { hb_filter_ids id = job.Denoise == Denoise.hqdn3d ? hb_filter_ids.HB_FILTER_HQDN3D : hb_filter_ids.HB_FILTER_NLMEANS; string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)id, job.DenoisePreset.ToString().ToLower().Replace(" ", string.Empty), job.DenoiseTune.ToString().ToLower().Replace(" ", string.Empty), job.CustomDenoise); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)id, Settings = settings }; filter.FilterList.Add(filterItem); } } // Sharpen if (job.Sharpen != Sharpen.Off) { hb_filter_ids id = job.Sharpen == Sharpen.LapSharp ? hb_filter_ids.HB_FILTER_LAPSHARP : hb_filter_ids.HB_FILTER_UNSHARP; string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)id, job.SharpenPreset.Key, job.SharpenTune.Key, job.SharpenCustom); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)id, Settings = settings }; filter.FilterList.Add(filterItem); } } // Deblock if (job.DeblockPreset != null && job.DeblockPreset.Key != "off") { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_DEBLOCK, job.DeblockPreset.Key, job.DeblockTune.Key, job.CustomDeblock); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_DEBLOCK, Settings = settings }; filter.FilterList.Add(filterItem); } } // CropScale Filter string cropSettings = string.Format("width={0}:height={1}:crop-top={2}:crop-bottom={3}:crop-left={4}:crop-right={5}", job.Width, job.Height, job.Cropping.Top, job.Cropping.Bottom, job.Cropping.Left, job.Cropping.Right); string unparsedCropSettingsJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_CROP_SCALE, null, null, cropSettings); if (!string.IsNullOrEmpty(unparsedCropSettingsJson)) { JsonDocument cropSettingsJson = JsonDocument.Parse(unparsedCropSettingsJson); Filter cropScale = new Filter { ID = (int)hb_filter_ids.HB_FILTER_CROP_SCALE, Settings = cropSettingsJson }; filter.FilterList.Add(cropScale); } // Padding Filter if (job.Padding.Enabled) { // Calculate the new Width / Height int?width = job.Width; int?height = job.Height; if (job.Padding.Enabled) { width = width + job.Padding.W; height = height + job.Padding.H; } // Setup the filter. string padSettings = string.Format("width={0}:height={1}:color={2}:x={3}:y={4}", width, height, job.Padding.Color, job.Padding.X, job.Padding.Y); string unparsedPadSettingsJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_PAD, null, null, padSettings); if (!string.IsNullOrEmpty(unparsedPadSettingsJson)) { JsonDocument PadSettingsJson = JsonDocument.Parse(unparsedPadSettingsJson); Filter padding = new Filter { ID = (int)hb_filter_ids.HB_FILTER_PAD, Settings = PadSettingsJson }; filter.FilterList.Add(padding); } } // Colourspace if (job.Colourspace != null && job.Colourspace.Key != "off") { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_COLORSPACE, job.Colourspace.Key, null, job.CustomColourspace); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_COLORSPACE, Settings = settings }; filter.FilterList.Add(filterItem); } } if (job.ChromaSmooth != null && job.ChromaSmooth.Key != "off") { string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH, job.ChromaSmooth.Key, job.ChromaSmoothTune?.Key, job.CustomChromaSmooth); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_CHROMA_SMOOTH, Settings = settings }; filter.FilterList.Add(filterItem); } } // Grayscale if (job.Grayscale) { Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_GRAYSCALE, Settings = null }; filter.FilterList.Add(filterItem); } // Rotate if (job.Rotation != 0 || job.FlipVideo) { string rotateSettings = string.Format("angle={0}:hflip={1}", job.Rotation, job.FlipVideo ? "1" : "0"); string unparsedJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_ROTATE, null, null, rotateSettings); if (!string.IsNullOrEmpty(unparsedJson)) { JsonDocument settings = JsonDocument.Parse(unparsedJson); Filter filterItem = new Filter { ID = (int)hb_filter_ids.HB_FILTER_ROTATE, Settings = settings }; 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) { int vrate = HandBrakeUnitConversionHelpers.GetFramerateFromName(job.Framerate.Value.ToString(CultureInfo.InvariantCulture)); if (vrate > 0) { num = 27000000; den = vrate; } } string framerateString = num.HasValue ? string.Format("mode={0}:rate={1}/{2}", fm, num, den) : string.Format("mode={0}", fm); // filter_cfr, filter_vrate.num, filter_vrate.den string unparsedFramerateJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_VFR, null, null, framerateString); if (!string.IsNullOrEmpty(unparsedFramerateJson)) { JsonDocument framerateSettings = JsonDocument.Parse(unparsedFramerateJson); Filter framerateShaper = new Filter { ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateSettings }; filter.FilterList.Add(framerateShaper); } return(filter); }