Esempio n. 1
0
        public void RemoveAudioEncoding(AudioEncodingViewModel audioEncodingVM)
        {
            this.audioEncodings.Remove(audioEncodingVM);
            audioEncodingVM.Dispose();

            this.RefreshAudioPreview();
            this.UpdateAudioEncodings();
        }
Esempio n. 2
0
 public void RemoveAudioEncoding(AudioEncodingViewModel audioEncodingVM)
 {
     this.AudioEncodings.Remove(audioEncodingVM);
     this.RaisePropertyChanged(() => this.HasAudioTracks);
     this.RefreshAudioPreview();
     this.UpdateAudioEncodings();
     this.IsModified = true;
 }
Esempio n. 3
0
        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);
                }
            }

            if (encoder.ShortName == "copy")
            {
                if (this.copyMaskChoices.Items.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
                {
                    // The fallback is explicitly set to "None", so drop the track.
                    if (this.Profile.AudioEncoderFallback == "none")
                    {
                        return(null);
                    }

                    encoder = HandBrakeEncoderHelpers.GetAudioEncoder(this.Profile.AudioEncoderFallback);
                }

                // Get the default output values for the input track and encoder
                var defaultSettings = AudioUtilities.GetDefaultSettings(inputTrack, encoder);

                // Apply the output values to the preview object
                UpdateAudioPreviewTrack(outputPreviewTrack, defaultSettings);
            }
            else
            {
                HBMixdown previewMixdown;
                previewMixdown = HandBrakeEncoderHelpers.SanitizeMixdown(audioVM.SelectedMixdown.Mixdown, encoder, (ulong)inputTrack.ChannelLayout);

                int previewSampleRate = audioVM.SampleRate;
                if (previewSampleRate == 0)
                {
                    previewSampleRate = inputTrack.SampleRate;
                }

                // Collect the output values in the AudioTrack object
                var outputTrack = new OutputAudioTrackInfo
                {
                    Encoder        = encoder,
                    Mixdown        = previewMixdown,
                    SampleRate     = HandBrakeEncoderHelpers.SanitizeSampleRate(encoder, previewSampleRate),
                    EncodeRateType = audioVM.EncodeRateType
                };

                if (audioVM.EncodeRateType == AudioEncodeRateType.Bitrate)
                {
                    int previewBitrate = audioVM.SelectedBitrate.Bitrate;
                    if (previewBitrate == 0)
                    {
                        previewBitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(encoder, previewSampleRate, previewMixdown);
                    }
                    else
                    {
                        previewBitrate = HandBrakeEncoderHelpers.SanitizeAudioBitrate(previewBitrate, encoder, previewSampleRate, previewMixdown);
                    }

                    outputTrack.Bitrate = previewBitrate;
                }
                else
                {
                    outputTrack.Quality = audioVM.AudioQuality;
                }

                outputTrack.Gain = audioVM.Gain;
                outputTrack.Drc  = audioVM.Drc;

                // Apply the output values to the preview object
                UpdateAudioPreviewTrack(outputPreviewTrack, outputTrack);
            }

            return(outputPreviewTrack);
        }
Esempio n. 4
0
		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;
		}
Esempio n. 5
0
		public void RemoveAudioEncoding(AudioEncodingViewModel audioEncodingVM)
		{
			this.AudioEncodings.Remove(audioEncodingVM);
			this.RaisePropertyChanged(() => this.HasAudioTracks);
			this.RefreshAudioPreview();
			this.UpdateAudioEncodings();
			this.IsModified = true;
		}
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }