/// <summary> /// Initializes a new instance of the <see cref="AudioTrack"/> class. /// Copy Constructor /// </summary> /// <param name="track"> /// The track. /// </param> public AudioBehaviourTrack(AudioBehaviourTrack track) { this.bitrate = track.Bitrate; this.drc = track.DRC; this.encoder = track.Encoder; this.gain = track.Gain; this.mixDown = track.MixDown; this.sampleRate = track.SampleRate; this.Quality = track.Quality; this.encoderRateType = track.EncoderRateType; this.SetupLimits(); }
/// <summary> /// Remove the Selected Track /// </summary> /// <param name="track"> /// The track. /// </param> public void RemoveTrack(AudioBehaviourTrack track) { this.BehaviourTracks.Remove(track); }
/// <summary> /// The create preset. /// </summary> /// <param name="importedPreset"> /// The preset. /// </param> /// <returns> /// The <see cref="Preset"/>. /// </returns> public static Preset ImportPreset(HBPreset importedPreset) { Preset preset = new Preset(); preset.Name = importedPreset.PresetName; preset.Description = importedPreset.PresetDescription; 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 */ preset.Task.OptimizeMP4 = importedPreset.Mp4HttpOptimize; preset.Task.IPod5GSupport = importedPreset.Mp4iPodCompatible; preset.Task.OutputFormat = GetFileFormat(importedPreset.FileFormat.Replace("file", string.Empty).Trim()); // TOOD null check. /* Picture Settings */ preset.PictureSettingsMode = (PresetPictureSettingsMode)importedPreset.UsesPictureSettings; preset.Task.MaxWidth = importedPreset.PictureWidth.HasValue && importedPreset.PictureWidth.Value > 0 ? importedPreset.PictureWidth.Value : (int?)null; preset.Task.MaxHeight = importedPreset.PictureHeight.HasValue && importedPreset.PictureHeight.Value > 0 ? importedPreset.PictureHeight.Value : (int?)null; preset.Task.Cropping = new Cropping(importedPreset.PictureTopCrop, importedPreset.PictureBottomCrop, importedPreset.PictureLeftCrop, importedPreset.PictureRightCrop); preset.Task.HasCropping = !importedPreset.PictureAutoCrop; preset.Task.Modulus = importedPreset.PictureModulus; preset.Task.KeepDisplayAspect = importedPreset.PictureKeepRatio; switch (importedPreset.PicturePAR) { case "custom": preset.Task.Anamorphic = Anamorphic.Custom; preset.Task.DisplayWidth = importedPreset.PictureDARWidth; break; case "loose": preset.Task.Anamorphic = Anamorphic.Loose; break; case "auto": preset.Task.Anamorphic = Anamorphic.Automatic; break; default: preset.Task.Anamorphic = Anamorphic.None; break; } /* Filter Settings */ preset.Task.Grayscale = importedPreset.VideoGrayScale; preset.Task.Deblock = importedPreset.PictureDeblock; switch (importedPreset.PictureDeinterlaceFilter) { case "decomb": preset.Task.Decomb = Decomb.Default; preset.Task.Deinterlace = Deinterlace.Default; preset.Task.DeinterlaceFilter = DeinterlaceFilter.Decomb; break; case "deinterlace": preset.Task.Decomb = Decomb.Default; preset.Task.Deinterlace = Deinterlace.Default; preset.Task.DeinterlaceFilter = DeinterlaceFilter.Yadif; break; default: preset.Task.Decomb = Decomb.Default; preset.Task.Deinterlace = Deinterlace.Default; preset.Task.DeinterlaceFilter = DeinterlaceFilter.Off; break; } if (preset.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb) { switch (importedPreset.PictureDeinterlaceFilter) { case "custom": preset.Task.Decomb = Decomb.Custom; break; case "default": preset.Task.Decomb = Decomb.Default; break; case "bob": preset.Task.Decomb = Decomb.Bob; break; case "eedi2": preset.Task.Decomb = Decomb.EEDI2; break; case "eedi2bob": preset.Task.Decomb = Decomb.EEDI2Bob; break; default: preset.Task.Decomb = Decomb.Default; break; } if (preset.Task.Decomb == Decomb.Custom) { preset.Task.CustomDecomb = importedPreset.PictureDeinterlaceCustom; } } if (preset.Task.DeinterlaceFilter == DeinterlaceFilter.Yadif) { switch (importedPreset.PictureDeinterlaceFilter) { case "custom": preset.Task.Deinterlace = Deinterlace.Custom; break; case "bob": preset.Task.Deinterlace = Deinterlace.Bob; break; case "skip-spatial": preset.Task.Deinterlace = Deinterlace.SkipSpatialCheck; break; case "default": preset.Task.Deinterlace = Deinterlace.Default; break; default: preset.Task.Deinterlace = Deinterlace.Default; break; } if (preset.Task.Deinterlace == Deinterlace.Custom) { preset.Task.CustomDecomb = importedPreset.PictureDeinterlaceCustom; } } if (preset.Task.DeinterlaceFilter == DeinterlaceFilter.Yadif || preset.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb) { switch (importedPreset.PictureCombDetectPreset) { case "off": preset.Task.CombDetect = CombDetect.Off; break; case "custom": preset.Task.CombDetect = CombDetect.Custom; break; case "default": preset.Task.CombDetect = CombDetect.Default; break; case "permissive": preset.Task.CombDetect = CombDetect.LessSensitive; break; case "fast": preset.Task.CombDetect = CombDetect.Fast; break; default: preset.Task.CombDetect = CombDetect.Off; break; } } preset.Task.CustomDeinterlace = importedPreset.PictureDetelecineCustom; preset.Task.CustomDenoise = importedPreset.PictureDenoiseCustom; preset.Task.CustomDetelecine = importedPreset.PictureDetelecineCustom; preset.Task.CustomCombDetect = importedPreset.PictureCombDetectCustom; switch (importedPreset.PictureDetelecine) { case "custom": preset.Task.Detelecine = Detelecine.Custom; break; case "default": preset.Task.Detelecine = Detelecine.Default; break; default: preset.Task.Detelecine = Detelecine.Off; break; } switch (importedPreset.PictureDenoiseFilter) { case "nlmeans": preset.Task.Denoise = Denoise.NLMeans; break; case "hqdn3d": preset.Task.Denoise = Denoise.hqdn3d; break; default: preset.Task.Denoise = Denoise.Off; break; } switch (importedPreset.PictureDenoisePreset) { case "custom": preset.Task.DenoisePreset = DenoisePreset.Custom; break; case "light": preset.Task.DenoisePreset = DenoisePreset.Light; break; case "medium": preset.Task.DenoisePreset = DenoisePreset.Medium; break; case "strong": preset.Task.DenoisePreset = DenoisePreset.Strong; break; case "ultralight": preset.Task.DenoisePreset = DenoisePreset.Ultralight; break; case "weak": preset.Task.DenoisePreset = DenoisePreset.Weak; break; } switch (importedPreset.PictureDenoiseTune) { case "animation": preset.Task.DenoiseTune = DenoiseTune.Animation; break; case "film": preset.Task.DenoiseTune = DenoiseTune.Film; break; case "grain": preset.Task.DenoiseTune = DenoiseTune.Grain; break; case "highnotion": preset.Task.DenoiseTune = DenoiseTune.HighMotion; break; default: preset.Task.DenoiseTune = DenoiseTune.None; 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; preset.Task.TwoPass = importedPreset.VideoTwoPass; preset.Task.TurboFirstPass = importedPreset.VideoTurboTwoPass; preset.Task.ExtraAdvancedArguments = importedPreset.VideoOptionExtra; preset.Task.Quality = double.Parse(importedPreset.VideoQualitySlider.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture); preset.Task.VideoEncodeRateType = (VideoEncodeRateType)importedPreset.VideoQualityType; preset.Task.VideoLevel = new VideoLevel(importedPreset.VideoLevel, importedPreset.VideoLevel); preset.Task.VideoPreset = new VideoPreset(importedPreset.VideoPreset, importedPreset.VideoPreset); preset.Task.VideoProfile = new VideoProfile(importedPreset.VideoProfile, importedPreset.VideoProfile); if (!string.IsNullOrEmpty(importedPreset.VideoTune)) { string[] split = importedPreset.VideoTune.Split(','); foreach (var item in split) { preset.Task.VideoTunes.Add(new VideoTune(item, item)); } } preset.Task.Framerate = importedPreset.VideoFramerate == "auto" || string.IsNullOrEmpty(importedPreset.VideoFramerate) ? (double?)null : double.Parse(importedPreset.VideoFramerate, CultureInfo.InvariantCulture); string parsedValue = importedPreset.VideoFramerateMode; switch (parsedValue) { case "vfr": preset.Task.FramerateMode = FramerateMode.VFR; break; case "cfr": preset.Task.FramerateMode = FramerateMode.CFR; break; default: preset.Task.FramerateMode = FramerateMode.PFR; break; } /* Audio Settings */ preset.AudioTrackBehaviours = new AudioBehaviours(); preset.Task.AllowedPassthruOptions.AudioEncoderFallback = EnumHelper<AudioEncoder>.GetValue(importedPreset.AudioEncoderFallback); preset.AudioTrackBehaviours.SelectedBehaviour = importedPreset.AudioTrackSelectionBehavior == "all" ? AudioBehaviourModes.AllMatching : AudioBehaviourModes.FirstMatch; // TODO - The other GUI's don't support All Tracks yet. So for now we can only load / Save first track. if (importedPreset.AudioSecondaryEncoderMode) { preset.AudioTrackBehaviours.SelectedTrackDefaultBehaviour = AudioTrackDefaultsMode.FirstTrack; } else { preset.AudioTrackBehaviours.SelectedTrackDefaultBehaviour = AudioTrackDefaultsMode.None; } if (importedPreset.AudioCopyMask != null) { preset.Task.AllowedPassthruOptions.SetFalse(); foreach (var item in importedPreset.AudioCopyMask) { AudioEncoder encoder = EnumHelper<AudioEncoder>.GetValue(item); switch (encoder) { case AudioEncoder.AacPassthru: preset.Task.AllowedPassthruOptions.AudioAllowAACPass = true; break; case AudioEncoder.Ac3Passthrough: preset.Task.AllowedPassthruOptions.AudioAllowAC3Pass = true; break; case AudioEncoder.EAc3Passthrough: preset.Task.AllowedPassthruOptions.AudioAllowEAC3Pass = true; break; case AudioEncoder.DtsHDPassthrough: preset.Task.AllowedPassthruOptions.AudioAllowDTSHDPass = true; break; case AudioEncoder.DtsPassthrough: preset.Task.AllowedPassthruOptions.AudioAllowDTSPass = true; break; case AudioEncoder.FlacPassthru: preset.Task.AllowedPassthruOptions.AudioAllowFlacPass = true; break; case AudioEncoder.Mp3Passthru: preset.Task.AllowedPassthruOptions.AudioAllowMP3Pass = true; break; case AudioEncoder.TrueHDPassthrough: preset.Task.AllowedPassthruOptions.AudioAllowTrueHDPass = true; break; } } } if (importedPreset.AudioLanguageList != null) { IList<string> names = LanguageUtilities.GetLanguageNames(importedPreset.AudioLanguageList); foreach (var name in names) { preset.AudioTrackBehaviours.SelectedLangauges.Add(name); } } preset.Task.AudioTracks = new ObservableCollection<AudioTrack>(); if (importedPreset.AudioList != null) { foreach (var audioTrack in importedPreset.AudioList) { AudioBehaviourTrack track = new AudioBehaviourTrack(); track.Bitrate = audioTrack.AudioBitrate; // track.CompressionLevel = audioTrack.AudioCompressionLevel; // track.AudioDitherMethod = audioTrack.AudioDitherMethod; track.Encoder = EnumHelper<AudioEncoder>.GetValue(audioTrack.AudioEncoder); track.MixDown = HandBrakeEncoderHelpers.GetMixdown(audioTrack.AudioMixdown); // track.AudioNormalizeMixLevel = audioTrack.AudioNormalizeMixLevel; track.SampleRate = audioTrack.AudioSamplerate == "auto" ? 0 : double.Parse(audioTrack.AudioSamplerate); track.EncoderRateType = audioTrack.AudioTrackQualityEnable ? AudioEncoderRateType.Quality : AudioEncoderRateType.Bitrate; track.Quality = audioTrack.AudioTrackQuality; track.Gain = (int)audioTrack.AudioTrackGainSlider; track.DRC = audioTrack.AudioTrackDRCSlider; preset.AudioTrackBehaviours.BehaviourTracks.Add(track); } } /* Subtitle Settings */ preset.SubtitleTrackBehaviours = new SubtitleBehaviours(); preset.SubtitleTrackBehaviours.SelectedBehaviour = EnumHelper<SubtitleBehaviourModes>.GetValue(importedPreset.SubtitleTrackSelectionBehavior); preset.SubtitleTrackBehaviours.SelectedBurnInBehaviour = EnumHelper<SubtitleBurnInBehaviourModes>.GetValue(importedPreset.SubtitleBurnBehavior); preset.SubtitleTrackBehaviours.AddClosedCaptions = importedPreset.SubtitleAddCC; preset.SubtitleTrackBehaviours.AddForeignAudioScanTrack = importedPreset.SubtitleAddForeignAudioSearch; if (importedPreset.SubtitleLanguageList != null) { IList<string> names = LanguageUtilities.GetLanguageNames(importedPreset.SubtitleLanguageList); foreach (var name in names) { preset.SubtitleTrackBehaviours.SelectedLangauges.Add(name); } } /* Chapter Marker Settings */ preset.Task.IncludeChapterMarkers = importedPreset.ChapterMarkers; /* Advanced Settings */ preset.Task.ShowAdvancedTab = importedPreset.x264UseAdvancedOptions; preset.Task.AdvancedEncoderOptions = importedPreset.x264Option; /* Not Supported Yet */ // public int VideoColorMatrixCode { get; set; } // public bool VideoHWDecode { get; set; } // public string VideoScaler { get; set; } // public bool VideoQSVDecode { get; set; } // public int VideoQSVAsyncDepth { get; set; } // public bool SubtitleAddForeignAudioSubtitle { get; set; } // public bool SubtitleBurnBDSub { get; set; } // public bool SubtitleBurnDVDSub { get; set; } // public bool PictureItuPAR { get; set; } // public bool PictureLooseCrop { get; set; } // public int PicturePARWidth { get; set; } // public int PicturePARHeight { get; set; } // public int PictureForceHeight { get; set; } // public int PictureForceWidth { get; set; } // public List<object> ChildrenArray { get; set; } // public bool Folder { get; set; } // public bool FolderOpen { get; set; } // public int Type { get; set; } return preset; }
/// <summary> /// Initializes a new instance of the <see cref="AudioTrack"/> class. /// Create a track from a behaviour track. /// </summary> /// <param name="track"> /// The Behavior track /// </param> public AudioTrack(AudioBehaviourTrack track) { this.drc = track.DRC; this.encoder = track.Encoder; this.gain = track.Gain; this.mixDown = track.MixDown != null ? track.MixDown.ShortName : "dpl2"; this.sampleRate = track.SampleRate; this.scannedTrack = new Audio(); this.encoderRateType = track.EncoderRateType; this.quality = track.Quality; this.bitrate = track.Bitrate; this.SetupLimits(); }