// 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 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 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); }