/// <summary>
 /// Sanitizes a mixdown given the output codec and input channel layout.
 /// </summary>
 /// <param name="mixdown">
 /// The desired mixdown.
 /// </param>
 /// <param name="encoder">
 /// The output encoder to be used.
 /// </param>
 /// <param name="layout">
 /// The input channel layout.
 /// </param>
 /// <returns>
 /// A sanitized mixdown value.
 /// </returns>
 public static HBMixdown SanitizeMixdown(HBMixdown mixdown, HBAudioEncoder encoder, ulong layout)
 {
     int sanitizedMixdown = HBFunctions.hb_mixdown_get_best((uint)encoder.Id, layout, mixdown.Id);
     return Mixdowns.Single(m => m.Id == sanitizedMixdown);
 }
Example #2
0
 /// <summary>
 /// Determines if DRC can be applied to the given track with the given encoder.
 /// </summary>
 /// <param name="trackNumber">The track Number.</param>
 /// <param name="encoder">The encoder to use for DRC.</param>
 /// <param name="title">The title.</param>
 /// <returns>True if DRC can be applied to the track with the given encoder.</returns>
 public bool CanApplyDrc(int trackNumber, HBAudioEncoder encoder, int title)
 {
     return HBFunctions.hb_audio_can_apply_drc2(this.hbHandle, title, trackNumber, encoder.Id) > 0;
 }
 /// <summary>
 /// Determines if the given encoder supports the given mixdown.
 /// </summary>
 /// <param name="mixdown">
 /// The mixdown to evaluate.
 /// </param>
 /// <param name="encoder">
 /// The encoder to evaluate.
 /// </param>
 /// <returns>
 /// True if the encoder supports the mixdown.
 /// </returns>
 public static bool MixdownHasCodecSupport(HBMixdown mixdown, HBAudioEncoder encoder)
 {
     return HBFunctions.hb_mixdown_has_codec_support(mixdown.Id, (uint) encoder.Id) > 0;
 }
 /// <summary>
 /// Sanitizes an audio bitrate given the output codec, sample rate and mixdown.
 /// </summary>
 /// <param name="audioBitrate">
 /// The desired audio bitrate.
 /// </param>
 /// <param name="encoder">
 /// The output encoder to be used.
 /// </param>
 /// <param name="sampleRate">
 /// The output sample rate to be used.
 /// </param>
 /// <param name="mixdown">
 /// The mixdown to be used.
 /// </param>
 /// <returns>
 /// A sanitized audio bitrate.
 /// </returns>
 public static int SanitizeAudioBitrate(int audioBitrate, HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
 {
     return HBFunctions.hb_audio_bitrate_get_best((uint)encoder.Id, audioBitrate, sampleRate, mixdown.Id);
 }
 /// <summary>
 /// Gets the default audio bitrate for the given parameters.
 /// </summary>
 /// <param name="encoder">
 /// The encoder to use.
 /// </param>
 /// <param name="sampleRate">
 /// The sample rate to use.
 /// </param>
 /// <param name="mixdown">
 /// The mixdown to use.
 /// </param>
 /// <returns>
 /// The default bitrate for these parameters.
 /// </returns>
 public static int GetDefaultBitrate(HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
 {
     return HBFunctions.hb_audio_bitrate_get_default((uint) encoder.Id, sampleRate, mixdown.Id);
 }
 /// <summary>
 /// Gets the default mixdown for the given audio encoder and channel layout.
 /// </summary>
 /// <param name="encoder">
 /// The output codec to be used.
 /// </param>
 /// <param name="layout">
 /// The input channel layout.
 /// </param>
 /// <returns>
 /// The default mixdown for the given codec and channel layout.
 /// </returns>
 public static HBMixdown GetDefaultMixdown(HBAudioEncoder encoder, ulong layout)
 {
     int defaultMixdown = HBFunctions.hb_mixdown_get_default((uint)encoder.Id, layout);
     return Mixdowns.Single(m => m.Id == defaultMixdown);
 }
 /// <summary>
 /// Determines if DRC can be applied to the given track with the given encoder.
 /// </summary>
 /// <param name="trackNumber">
 /// The track Number.
 /// </param>
 /// <param name="encoder">
 /// The encoder to use for DRC.
 /// </param>
 /// <param name="title">
 /// The title.
 /// </param>
 /// <returns>
 /// True if DRC can be applied to the track with the given encoder.
 /// </returns>
 public static bool CanApplyDrc(int trackNumber, HBAudioEncoder encoder, int title)
 {
     return HBFunctions.hb_audio_can_apply_drc2(HandBrakeInstanceManager.LastScanHandle, title, trackNumber, encoder.Id) > 0;
 }
        /// <summary>
        /// Gets the bitrate limits for the given audio codec, sample rate and mixdown.
        /// </summary>
        /// <param name="encoder">
        /// The audio encoder used.
        /// </param>
        /// <param name="sampleRate">
        /// The sample rate used (Hz).
        /// </param>
        /// <param name="mixdown">
        /// The mixdown used.
        /// </param>
        /// <returns>
        /// Limits on the audio bitrate for the given settings.
        /// </returns>
        public static BitrateLimits GetBitrateLimits(HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
        {
            int low = 0;
            int high = 0;

            HBFunctions.hb_audio_bitrate_get_limits((uint)encoder.Id, sampleRate, mixdown.Id, ref low, ref high);

            return new BitrateLimits { Low = low, High = high };
        }
 /// <summary>
 /// The get default audio compression.
 /// </summary>
 /// <param name="encoder">
 /// The encoder.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public static double GetDefaultAudioCompression(HBAudioEncoder encoder)
 {
     return HBFunctions.hb_audio_compression_get_default((uint)encoder.Id);
 }
 /// <summary>
 /// Determines if the given encoder is compatible with the given track.
 /// </summary>
 /// <param name="codecId">
 /// The codec Id.
 /// </param>
 /// <param name="encoder">
 /// The encoder to examine.
 /// </param>
 /// <returns>
 /// True if the given encoder is comatible with the given audio track.
 /// </returns>
 /// <remarks>
 /// Only works with passthrough encoders.
 /// </remarks>
 public static bool AudioEncoderIsCompatible(int codecId, HBAudioEncoder encoder)
 {
     return (codecId & encoder.Id) > 0;
 }
 /// <summary>
 /// The get default quality.
 /// </summary>
 /// <param name="encoder">
 /// The encoder.
 /// </param>
 /// <returns>
 /// The <see cref="double"/>.
 /// </returns>
 public static double GetDefaultQuality(HBAudioEncoder encoder)
 {
    return HBFunctions.hb_audio_quality_get_default((uint)encoder.Id);
 }
        /// <summary>
        /// Converts a native HB encoder structure to an Encoder model.
        /// </summary>
        /// <param name="encoder">
        /// The structure to convert.
        /// </param>
        /// <returns>
        /// The converted model.
        /// </returns>
        public static HBAudioEncoder NativeToAudioEncoder(hb_encoder_s encoder)
        {
            var result = new HBAudioEncoder
                             {
                                 Id = encoder.codec,
                                 ShortName = encoder.short_name,
                                 DisplayName = encoder.name,
                                 CompatibleContainers = encoder.muxers,
                                 QualityLimits = HandBrakeEncoderHelpers.GetAudioQualityLimits(encoder.codec),
                                 DefaultQuality = HBFunctions.hb_audio_quality_get_default((uint)encoder.codec),
                                 CompressionLimits = HandBrakeEncoderHelpers.GetAudioCompressionLimits(encoder.codec),
                                 DefaultCompression =
                                 HBFunctions.hb_audio_compression_get_default((uint)encoder.codec)
                             };

            return result;
        }
        /// <summary>
        /// Converts a native HB encoder structure to an Encoder model.
        /// </summary>
        /// <param name="encoder">
        /// The structure to convert.
        /// </param>
        /// <returns>
        /// The converted model.
        /// </returns>
        internal static HBAudioEncoder NativeToAudioEncoder(hb_encoder_s encoder)
        {
            var result = new HBAudioEncoder(
                encoder.muxers,
                HandBrakeEncoderHelpers.GetAudioCompressionLimits(encoder.codec),
                HBFunctions.hb_audio_compression_get_default((uint)encoder.codec),
                HBFunctions.hb_audio_quality_get_default((uint)encoder.codec),
                encoder.name,
                encoder.codec,
                HandBrakeEncoderHelpers.GetAudioQualityLimits(encoder.codec),
                encoder.short_name);

            return result;
        }
        /// <summary>
        /// Sanitizes a mixdown given the output codec and input channel layout.
        /// </summary>
        /// <param name="mixdown">
        /// The desired mixdown.
        /// </param>
        /// <param name="encoder">
        /// The output encoder to be used.
        /// </param>
        /// <param name="layout">
        /// The input channel layout.
        /// </param>
        /// <returns>
        /// A sanitized mixdown value.
        /// </returns>
        public static HBMixdown SanitizeMixdown(HBMixdown mixdown, HBAudioEncoder encoder, ulong layout)
        {
            if (mixdown == null)
            {
                return null;
            }

            int sanitizedMixdown = HBFunctions.hb_mixdown_get_best((uint)encoder.Id, layout, mixdown.Id);
            if (sanitizedMixdown != -1)
            {
                return Mixdowns.Single(m => m.Id == sanitizedMixdown);
            }
            return Mixdowns.FirstOrDefault(); // "none"
        }
 /// <summary>
 /// Determines if a mixdown is available for a given track and encoder.
 /// </summary>
 /// <param name="mixdown">
 /// The mixdown to evaluate.
 /// </param>
 /// <param name="encoder">
 /// The encoder to evaluate.
 /// </param>
 /// <param name="channelLayout">channel layout of the source track</param>
 /// <returns>True if available.</returns>
 public static bool MixdownIsSupported(HBMixdown mixdown, HBAudioEncoder encoder, int channelLayout)
 {
     return HBFunctions.hb_mixdown_is_supported(mixdown.Id, (uint)encoder.Id, (uint)channelLayout) > 0;
 }