// Applies values from an AudioTrack output to the preview object private static void UpdateAudioPreviewTrack(AudioOutputPreview outputPreviewTrack, OutputAudioTrackInfo outputTrack) { // Change from AudioTrack to custom object and remove dependency on JSON model? outputPreviewTrack.Encoder = outputTrack.Encoder.DisplayName; outputPreviewTrack.Mixdown = outputTrack.Mixdown.DisplayName; outputPreviewTrack.SampleRate = DisplayConversions.DisplaySampleRate(outputTrack.SampleRate); if (outputTrack.EncodeRateType == AudioEncodeRateType.Bitrate) { if (outputTrack.Bitrate >= 0) { outputPreviewTrack.Quality = outputTrack.Bitrate + " kbps"; } else { outputPreviewTrack.Quality = string.Empty; } } else { outputPreviewTrack.Quality = "CQ " + outputTrack.Quality; } var modifiers = new List <string>(); if (outputTrack.Gain != 0) { modifiers.Add(string.Format("{0}{1} dB", outputTrack.Gain > 0 ? "+" : string.Empty, outputTrack.Gain)); } if (outputTrack.Drc != 0) { modifiers.Add("DRC " + outputTrack.Drc.ToString(CultureInfo.CurrentCulture)); } outputPreviewTrack.Modifiers = string.Join(", ", modifiers); }
public VideoPanelViewModel(EncodingWindowViewModel encodingWindowViewModel) : base(encodingWindowViewModel) { this.AutomaticChange = true; this.RegisterProfileProperties(); this.encoderChoices = new List <VideoEncoderViewModel>(); this.framerateChoices = new List <double> { 0 }; foreach (var framerate in HandBrakeEncoderHelpers.VideoFramerates) { this.framerateChoices.Add(double.Parse(framerate.Name, CultureInfo.InvariantCulture)); } // InputType this.WhenAnyValue(x => x.HasSourceData, x => x.MainViewModel.SelectedTitle.Type, (hasSourceData, titleType) => { if (hasSourceData) { return(DisplayConversions.DisplayTitleType((TitleType)titleType)); } return(string.Empty); }).ToProperty(this, x => x.InputType, out this.inputType); // InputVideoCodec this.WhenAnyValue(x => x.HasSourceData, x => x.MainViewModel.SelectedTitle.VideoCodec, (hasSourceData, videoCodec) => { if (hasSourceData) { return(DisplayConversions.DisplayVideoCodecName(videoCodec)); } return(string.Empty); }).ToProperty(this, x => x.InputVideoCodec, out this.inputVideoCodec); // InputFramerate this.WhenAnyValue(x => x.HasSourceData, x => x.MainViewModel.SelectedTitle.FrameRate, (hasSourceData, framerate) => { if (hasSourceData) { return(string.Format(EncodingRes.FpsFormat, framerate.ToDouble())); } return(string.Empty); }).ToProperty(this, x => x.InputFramerate, out this.inputFramerate); // X264SettingsVisible this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(false); } string videoEncoder = selectedEncoder.Encoder.ShortName; return(videoEncoder == "x264"); }).ToProperty(this, x => x.X264SettingsVisible, out this.x264SettingsVisible); // QsvSettingsVisible this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(false); } string videoEncoder = selectedEncoder.Encoder.ShortName; return(videoEncoder.StartsWith("qsv_", StringComparison.OrdinalIgnoreCase)); }).ToProperty(this, x => x.QsvSettingsVisible, out this.qsvSettingsVisible); // EncoderSettingsVisible this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(false); } string videoEncoder = selectedEncoder.Encoder.ShortName; return (videoEncoder.StartsWith("x264", StringComparison.OrdinalIgnoreCase) || videoEncoder.StartsWith("x265", StringComparison.OrdinalIgnoreCase) || videoEncoder == "qsv_h264" || videoEncoder == "qsv_h265"); }).ToProperty(this, x => x.EncoderSettingsVisible, out this.encoderSettingsVisible); // BasicEncoderSettingsVisible this.WhenAnyValue(x => x.SelectedEncoder, x => x.UseAdvancedTab, (selectedEncoder, useAdvancedTab) => { if (this.selectedEncoder == null) { return(false); } string videoEncoder = selectedEncoder.Encoder.ShortName; if (videoEncoder == "qsv_h264") { return(true); } if (videoEncoder != "x264") { return(true); } return(!useAdvancedTab); }).ToProperty(this, x => x.BasicEncoderSettingsVisible, out this.basicEncoderSettingsVisible); // ConstantFramerateToolTip this.WhenAnyValue(x => x.Framerate, framerate => { if (framerate == 0) { return(EncodingRes.CfrSameAsSourceToolTip); } else { return(EncodingRes.CfrToolTip); } }).ToProperty(this, x => x.ConstantFramerateToolTip, out this.constantFramerateToolTip); // VariableFramerateToolTip this.WhenAnyValue(x => x.Framerate, framerate => { if (framerate == 0) { return(EncodingRes.VfrSameAsSourceToolTip); } else { return(EncodingRes.VfrPeakFramerateToolTip); } }).ToProperty(this, x => x.VariableFramerateToolTip, out this.variableFramerateToolTip); // VfrChoiceText this.WhenAnyValue(x => x.Framerate, framerate => { if (framerate == 0) { return(EncodingRes.VfrChoice); } else { return(EncodingRes.VfrPeakChoice); } }).ToProperty(this, x => x.VfrChoiceText, out this.vfrChoiceText); // TwoPassEnabled this.WhenAnyValue(x => x.VideoEncodeRateType, videoEncodeRateType => { return(videoEncodeRateType != VCVideoEncodeRateType.ConstantQuality); }).ToProperty(this, x => x.TwoPassEnabled, out this.twoPassEnabled); // TurboFirstPassEnabled this.WhenAnyValue(x => x.VideoEncodeRateType, x => x.TwoPass, (videoEncodeRateType, twoPass) => { return(videoEncodeRateType != VCVideoEncodeRateType.ConstantQuality && twoPass); }).ToProperty(this, x => x.TurboFirstPassEnabled, out this.turboFirstPassEnabled); // TurboFirstPassVisible this.WhenAnyValue(x => x.VideoEncodeRateType, x => x.SelectedEncoder, (videoEncodeRateType, selectedEncoder) => { if (selectedEncoder == null) { return(false); } string videoEncoderShortName = selectedEncoder.Encoder.ShortName; return(videoEncodeRateType != VCVideoEncodeRateType.ConstantQuality && (videoEncoderShortName == "x265" || videoEncoderShortName == "x264")); }).ToProperty(this, x => x.TurboFirstPassVisible, out this.turboFirstPassVisible); // QualityModulus this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(0); } return(Math.Round( HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Granularity, 2)); }).ToProperty(this, x => x.QualityModulus, out this.qualityModulus); // QualitySliderMin this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(0); } return(HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Low); }).ToProperty(this, x => x.QualitySliderMin, out this.qualitySliderMin); // QualitySliderMax this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(0); } return(HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).High); }).ToProperty(this, x => x.QualitySliderMax, out this.qualitySliderMax); // QualitySliderLeftText this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(string.Empty); } if (HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Ascending) { return(EncodingRes.LowQuality); } else { return(EncodingRes.HighQuality); } }).ToProperty(this, x => x.QualitySliderLeftText, out this.qualitySliderLeftText); // QualitySliderRightText this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(string.Empty); } if (HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Ascending) { return(EncodingRes.HighQuality); } else { return(EncodingRes.LowQuality); } }).ToProperty(this, x => x.QualitySliderRightText, out this.qualitySliderRightText); // PresetName this.WhenAnyValue(x => x.SelectedEncoder, x => x.PresetIndex, (selectedEncoder, presetIndex) => { if (selectedEncoder == null) { return(string.Empty); } string currentPresetName = null; if (this.presets != null && presetIndex >= 0 && presetIndex < this.presets.Count) { currentPresetName = this.presets[presetIndex]; } if (string.IsNullOrEmpty(currentPresetName)) { currentPresetName = GetDefaultPreset(selectedEncoder.Encoder.ShortName); } switch (currentPresetName) { case "ultrafast": return(EncodingRes.Preset_UltraFast); case "superfast": return(EncodingRes.Preset_SuperFast); case "veryfast": return(EncodingRes.Preset_VeryFast); case "faster": return(EncodingRes.Preset_Faster); case "fast": return(EncodingRes.Preset_Fast); case "medium": return(EncodingRes.Preset_Medium); case "slow": return(EncodingRes.Preset_Slow); case "slower": return(EncodingRes.Preset_Slower); case "veryslow": return(EncodingRes.Preset_VerySlow); case "placebo": return(EncodingRes.Preset_Placebo); case "speed": return(EncodingRes.QsvPreset_Speed); case "balanced": return(EncodingRes.QsvPreset_Balanced); case "quality": return(EncodingRes.QsvPreset_Quality); default: return(string.Empty); } }).ToProperty(this, x => x.PresetName, out this.presetName); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile) .Subscribe(_ => { this.ReadTuneListFromProfile(); this.RaisePropertyChanged(nameof(this.Tune)); this.RaisePropertyChanged(nameof(this.FastDecode)); this.RaisePropertyChanged(nameof(this.PresetIndex)); }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.VideoEncoder) .Subscribe(_ => { if (!this.userVideoEncoderChange) { this.RefreshEncoderChoices(this.PresetsService.SelectedPreset.Preset.EncodingProfile.ContainerName, EncoderChoicesRefreshSource.ProfileChange); } }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.VideoOptions) .Subscribe(_ => { if (!this.updatingLocalVideoOptions) { this.RaisePropertyChanged(nameof(this.VideoOptions)); } }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.ContainerName) .Skip(1) .Subscribe(containerName => { this.RefreshEncoderChoices(containerName, EncoderChoicesRefreshSource.ContainerChange); }); this.WhenAnyValue(x => x.SelectedEncoder.Encoder.ShortName) .Subscribe(videoEncoder => { this.RefreshEncoderSettings(applyDefaults: false); }); this.main.AudioChoiceChanged += (o, e) => { this.NotifyAudioInputChanged(); }; this.main.WhenAnyValue(x => x.SelectedTitle) .Skip(1) .Subscribe(_ => { this.NotifyAudioInputChanged(); }); this.AutomaticChange = false; }
public AudioOutputPreview GetAudioPreview(AudioTrack inputTrack, AudioEncodingViewModel audioVM) { HBAudioEncoder encoder = audioVM.HBAudioEncoder; var outputPreviewTrack = new AudioOutputPreview { Name = inputTrack.NoTrackDisplay, Encoder = encoder.DisplayName }; if (encoder.IsPassthrough) { // For passthrough encodes, we need to make sure the input track is of the right type if (!Encoders.AudioEncoderIsCompatible(inputTrack, encoder) && encoder.ShortName != "copy") { return(null); } HBContainer container = Encoders.GetContainer(this.Profile.ContainerName); if (encoder.ShortName == "copy" && (inputTrack.Codec == AudioCodec.Dts || inputTrack.Codec == AudioCodec.DtsHD) && container.DefaultExtension == "mp4") { this.PassthroughWarningText = EncodingRes.DtsMp4Warning; this.PassthroughWarningVisible = true; return(outputPreviewTrack); } } // Find out what the real mixdown, sample rate and bitrate will be. HBMixdown mixdown; int sampleRate, bitrate; if (encoder.ShortName == "copy") { if (Encoders.AudioEncoderIsCompatible(inputTrack, encoder)) { return(outputPreviewTrack); } if (this.Profile.AudioEncoderFallback == null) { encoder = Encoders.AudioEncoders.First(a => !a.IsPassthrough); } else { encoder = Encoders.GetAudioEncoder(this.Profile.AudioEncoderFallback); } mixdown = Encoders.GetDefaultMixdown(encoder, inputTrack.ChannelLayout); sampleRate = 0; bitrate = 0; outputPreviewTrack.Encoder = encoder.DisplayName; } else { mixdown = audioVM.SelectedMixdown.Mixdown; sampleRate = audioVM.SampleRate; bitrate = audioVM.SelectedBitrate.Bitrate; } HBMixdown previewMixdown; previewMixdown = Encoders.SanitizeMixdown(mixdown, encoder, inputTrack.ChannelLayout); int previewSampleRate = sampleRate; if (previewSampleRate == 0) { previewSampleRate = inputTrack.SampleRate; } int previewBitrate = bitrate; if (previewBitrate == 0) { previewBitrate = Encoders.GetDefaultBitrate(encoder, previewSampleRate, previewMixdown); } else { previewBitrate = Encoders.SanitizeAudioBitrate(previewBitrate, encoder, previewSampleRate, previewMixdown); } outputPreviewTrack.Mixdown = previewMixdown.DisplayName; outputPreviewTrack.SampleRate = DisplayConversions.DisplaySampleRate(previewSampleRate); if (audioVM.EncodeRateType == AudioEncodeRateType.Bitrate) { if (previewBitrate >= 0) { outputPreviewTrack.Quality = previewBitrate + " kbps"; } else { outputPreviewTrack.Quality = string.Empty; } } else { outputPreviewTrack.Quality = "CQ " + audioVM.AudioQuality; } var modifiers = new List <string>(); if (audioVM.Gain != 0) { modifiers.Add(string.Format("{0}{1} dB", audioVM.Gain > 0 ? "+" : string.Empty, audioVM.Gain)); } if (audioVM.Drc != 0) { modifiers.Add("DRC " + audioVM.Drc.ToString()); } outputPreviewTrack.Modifiers = string.Join(", ", modifiers); return(outputPreviewTrack); }
public VideoPanelViewModel(EncodingWindowViewModel encodingWindowViewModel) : base(encodingWindowViewModel) { this.AutomaticChange = true; this.RegisterProfileProperties(); this.encoderChoices = new List <VideoEncoderViewModel>(); this.framerateChoices = new List <double> { 0 }; foreach (var framerate in HandBrakeEncoderHelpers.VideoFramerates) { this.framerateChoices.Add(double.Parse(framerate.Name, CultureInfo.InvariantCulture)); } // InputType this.WhenAnyValue(x => x.HasSourceData, x => x.MainViewModel.SelectedTitle.Title.Type, (hasSourceData, titleType) => { if (hasSourceData) { return(DisplayConversions.DisplayTitleType((TitleType)titleType)); } return(string.Empty); }).ToProperty(this, x => x.InputType, out this.inputType); // InputVideoCodec this.WhenAnyValue(x => x.HasSourceData, x => x.MainViewModel.SelectedTitle.VideoCodec, (hasSourceData, videoCodec) => { if (hasSourceData) { return(DisplayConversions.DisplayVideoCodecName(videoCodec)); } return(string.Empty); }).ToProperty(this, x => x.InputVideoCodec, out this.inputVideoCodec); // InputFramerate this.WhenAnyValue(x => x.HasSourceData, x => x.MainViewModel.SelectedTitle.FrameRate, (hasSourceData, framerate) => { if (hasSourceData) { return(string.Format(EncodingRes.FpsFormat, framerate.ToDouble())); } return(string.Empty); }).ToProperty(this, x => x.InputFramerate, out this.inputFramerate); // X264SettingsVisible this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(false); } string videoEncoder = selectedEncoder.Encoder.ShortName; return(videoEncoder == "x264"); }).ToProperty(this, x => x.X264SettingsVisible, out this.x264SettingsVisible); // ConstantFramerateToolTip this.WhenAnyValue(x => x.Framerate, framerate => { if (framerate == 0) { return(EncodingRes.CfrSameAsSourceToolTip); } else { return(EncodingRes.CfrToolTip); } }).ToProperty(this, x => x.ConstantFramerateToolTip, out this.constantFramerateToolTip); // VariableFramerateToolTip this.WhenAnyValue(x => x.Framerate, framerate => { if (framerate == 0) { return(EncodingRes.VfrSameAsSourceToolTip); } else { return(EncodingRes.VfrPeakFramerateToolTip); } }).ToProperty(this, x => x.VariableFramerateToolTip, out this.variableFramerateToolTip); // VfrChoiceText this.WhenAnyValue(x => x.Framerate, framerate => { if (framerate == 0) { return(EncodingRes.VfrChoice); } else { return(EncodingRes.VfrPeakChoice); } }).ToProperty(this, x => x.VfrChoiceText, out this.vfrChoiceText); // TwoPassVisible this.WhenAnyValue(x => x.VideoEncodeRateType, x => x.SelectedEncoder, (videoEncodeRateType, selectedEncoder) => { if (selectedEncoder != null) { var encoderShortName = selectedEncoder.Encoder.ShortName; if (!EncoderSupportsTwoPass(encoderShortName)) { return(false); } } return(videoEncodeRateType != VCVideoEncodeRateType.ConstantQuality); }).ToProperty(this, x => x.TwoPassVisible, out this.twoPassVisible); // TurboFirstPassEnabled this.WhenAnyValue(x => x.VideoEncodeRateType, x => x.TwoPass, (videoEncodeRateType, twoPass) => { return(videoEncodeRateType != VCVideoEncodeRateType.ConstantQuality && twoPass); }).ToProperty(this, x => x.TurboFirstPassEnabled, out this.turboFirstPassEnabled); // TurboFirstPassVisible this.WhenAnyValue(x => x.VideoEncodeRateType, x => x.SelectedEncoder, (videoEncodeRateType, selectedEncoder) => { if (selectedEncoder == null) { return(false); } string videoEncoderShortName = selectedEncoder.Encoder.ShortName; return(videoEncodeRateType != VCVideoEncodeRateType.ConstantQuality && videoEncoderShortName.StartsWith("x26", StringComparison.Ordinal)); }).ToProperty(this, x => x.TurboFirstPassVisible, out this.turboFirstPassVisible); // QualityModulus this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(0); } return(Math.Round( HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Granularity, 2)); }).ToProperty(this, x => x.QualityModulus, out this.qualityModulus); // QualitySliderMin this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(0); } return(HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Low); }).ToProperty(this, x => x.QualitySliderMin, out this.qualitySliderMin); // QualitySliderMax this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(0); } return(HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).High); }).ToProperty(this, x => x.QualitySliderMax, out this.qualitySliderMax); // QualitySliderLeftText this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(string.Empty); } if (HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Ascending) { return(EncodingRes.LowQuality); } else { return(EncodingRes.HighQuality); } }).ToProperty(this, x => x.QualitySliderLeftText, out this.qualitySliderLeftText); // QualitySliderRightText this.WhenAnyValue(x => x.SelectedEncoder, selectedEncoder => { if (selectedEncoder == null) { return(string.Empty); } if (HandBrakeEncoderHelpers.GetVideoQualityLimits(selectedEncoder.Encoder).Ascending) { return(EncodingRes.HighQuality); } else { return(EncodingRes.LowQuality); } }).ToProperty(this, x => x.QualitySliderRightText, out this.qualitySliderRightText); // PresetName this.WhenAnyValue(x => x.SelectedEncoder, x => x.Presets, x => x.PresetIndex, (selectedEncoder, localPresets, presetIndex) => { if (selectedEncoder == null) { return(string.Empty); } string currentPresetName = null; if (localPresets != null && presetIndex >= 0 && presetIndex < localPresets.Count) { currentPresetName = localPresets[presetIndex]; } if (string.IsNullOrEmpty(currentPresetName)) { currentPresetName = GetDefaultPreset(selectedEncoder.Encoder.ShortName); } switch (currentPresetName) { case "ultrafast": return(EncodingRes.Preset_UltraFast); case "superfast": return(EncodingRes.Preset_SuperFast); case "veryfast": return(EncodingRes.Preset_VeryFast); case "faster": return(EncodingRes.Preset_Faster); case "fast": return(EncodingRes.Preset_Fast); case "medium": return(EncodingRes.Preset_Medium); case "slow": return(EncodingRes.Preset_Slow); case "slower": return(EncodingRes.Preset_Slower); case "veryslow": return(EncodingRes.Preset_VerySlow); case "placebo": return(EncodingRes.Preset_Placebo); case "speed": return(EncodingRes.QsvPreset_Speed); case "balanced": return(EncodingRes.QsvPreset_Balanced); case "quality": return(EncodingRes.QsvPreset_Quality); case "ll": return(EncodingRes.NVEncPreset_ll); case "hq": return(EncodingRes.NVEncPreset_hq); case "hp": return(EncodingRes.NVEncPreset_hp); default: return(currentPresetName); } }).ToProperty(this, x => x.PresetName, out this.presetName); // FullParameterList this.WhenAnyValue( x => x.SelectedEncoder, x => x.PresetsService.SelectedPreset.Preset.EncodingProfile.VideoPreset, x => x.PresetsService.SelectedPreset.Preset.EncodingProfile.VideoTunes, x => x.VideoOptions, x => x.VideoProfile, x => x.VideoLevel, x => x.OutputSizeService.Size, (selectedEncoder, videoPreset, videoTunes, videoOptions, videoProfile, videoLevel, outputSize) => { if (selectedEncoder == null) { return(string.Empty); } int width, height; if (outputSize != null) { width = outputSize.OutputWidth; height = outputSize.OutputHeight; } else { width = 640; height = 480; } if (width <= 0) { width = 640; } if (height <= 0) { height = 480; } string parameterList = HandBrakeUtils.CreateX264OptionsString( videoPreset, videoTunes, videoOptions?.Trim(), videoProfile, videoLevel, width, height); return(parameterList); }).ToProperty(this, x => x.FullParameterList, out this.fullParameterList); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile) .Subscribe(_ => { this.ReadTuneListFromProfile(); this.RaisePropertyChanged(nameof(this.Tune)); this.RaisePropertyChanged(nameof(this.FastDecode)); this.RaisePropertyChanged(nameof(this.PresetIndex)); }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.VideoEncoder) .Subscribe(_ => { if (!this.userVideoEncoderChange) { this.RefreshEncoderChoices(this.PresetsService.SelectedPreset.Preset.EncodingProfile.ContainerName, EncoderChoicesRefreshSource.ProfileChange); } }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.VideoOptions) .Subscribe(_ => { if (!this.updatingLocalVideoOptions) { this.RaisePropertyChanged(nameof(this.VideoOptions)); } }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.ContainerName) .Skip(1) .Subscribe(containerName => { this.RefreshEncoderChoices(containerName, EncoderChoicesRefreshSource.ContainerChange); // Refresh preset/profile/tune/level choices and values this.RefreshEncoderSettings(applyDefaults: false); }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioCopyMask) .Skip(1) .Subscribe(copyMask => { this.NotifyAudioChanged(); }); this.PresetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioEncodings) .Skip(1) .Subscribe(copyMask => { this.NotifyAudioChanged(); }); this.WhenAnyValue(x => x.SelectedEncoder.Encoder.ShortName) .Subscribe(videoEncoder => { this.RefreshEncoderSettings(applyDefaults: false); }); this.main.AudioTracks .Connect() .WhenAnyPropertyChanged() .Subscribe(_ => { this.NotifyAudioChanged(); }); this.main.WhenAnyValue(x => x.SelectedTitle) .Skip(1) .Subscribe(_ => { this.NotifyAudioChanged(); }); this.AutomaticChange = false; }
public AudioOutputPreview GetAudioPreview(SourceAudioTrack inputTrack, AudioEncodingViewModel audioVM) { HBAudioEncoder encoder = audioVM.HBAudioEncoder; var outputPreviewTrack = new AudioOutputPreview { Name = inputTrack.Description, Encoder = encoder.DisplayName }; if (encoder.IsPassthrough) { // For passthrough encodes, we need to make sure the input track is of the right type if (!HandBrakeEncoderHelpers.AudioEncoderIsCompatible(inputTrack.Codec, encoder) && encoder.ShortName != "copy") { return(null); } } // Find out what the real mixdown, sample rate and bitrate will be. HBMixdown mixdown; int sampleRate, bitrate; if (encoder.ShortName == "copy") { if (this.CopyMaskChoices.Any( choice => { if (!choice.Enabled) { return(false); } return((HandBrakeEncoderHelpers.GetAudioEncoder("copy:" + choice.Codec).Id & inputTrack.Codec) > 0); })) { return(outputPreviewTrack); } if (this.Profile.AudioEncoderFallback == null) { encoder = HandBrakeEncoderHelpers.AudioEncoders.First(a => !a.IsPassthrough); } else { encoder = HandBrakeEncoderHelpers.GetAudioEncoder(this.Profile.AudioEncoderFallback); } mixdown = HandBrakeEncoderHelpers.GetDefaultMixdown(encoder, (ulong)inputTrack.ChannelLayout); sampleRate = 0; bitrate = 0; outputPreviewTrack.Encoder = encoder.DisplayName; } else { mixdown = audioVM.SelectedMixdown.Mixdown; sampleRate = audioVM.SampleRate; bitrate = audioVM.SelectedBitrate.Bitrate; } HBMixdown previewMixdown; previewMixdown = HandBrakeEncoderHelpers.SanitizeMixdown(mixdown, encoder, (ulong)inputTrack.ChannelLayout); int previewSampleRate = sampleRate; if (previewSampleRate == 0) { previewSampleRate = inputTrack.SampleRate; } int previewBitrate = bitrate; if (previewBitrate == 0) { previewBitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(encoder, previewSampleRate, previewMixdown); } else { previewBitrate = HandBrakeEncoderHelpers.SanitizeAudioBitrate(previewBitrate, encoder, previewSampleRate, previewMixdown); } outputPreviewTrack.Mixdown = previewMixdown.DisplayName; outputPreviewTrack.SampleRate = DisplayConversions.DisplaySampleRate(previewSampleRate); if (audioVM.EncodeRateType == AudioEncodeRateType.Bitrate) { if (previewBitrate >= 0) { outputPreviewTrack.Quality = previewBitrate + " kbps"; } else { outputPreviewTrack.Quality = string.Empty; } } else { outputPreviewTrack.Quality = "CQ " + audioVM.AudioQuality; } var modifiers = new List <string>(); if (audioVM.Gain != 0) { modifiers.Add(string.Format("{0}{1} dB", audioVM.Gain > 0 ? "+" : string.Empty, audioVM.Gain)); } if (audioVM.Drc != 0) { modifiers.Add("DRC " + audioVM.Drc.ToString()); } outputPreviewTrack.Modifiers = string.Join(", ", modifiers); return(outputPreviewTrack); }