Beispiel #1
0
        static void ConfigureEncoderForQuality(SettingsDictionary settings, NativeEncoder encoder)
        {
            Contract.Requires(settings != null);
            Contract.Requires(encoder != null);

            encoder.SetVbr(VbrMode.Mtrh);

            if (!string.IsNullOrEmpty(settings["ForceCBR"]))
            {
                throw new InvalidSettingException(Resources.SampleEncoderUnexpectedForceCBR);
            }

            float vbrQuality;

            if (string.IsNullOrEmpty(settings["VBRQuality"]))
            {
                vbrQuality = 2;
            }
            else if (!float.TryParse(settings["VBRQuality"], out vbrQuality) || vbrQuality < 0 || vbrQuality >= 10)
            {
                throw new InvalidSettingException(string.Format(CultureInfo.CurrentCulture,
                                                                Resources.SampleEncoderBadVBRQuality, settings["VBRQuality"]));
            }

            encoder.SetVbrQuality(vbrQuality);
        }
Beispiel #2
0
        static void ConfigureEncoderForBitRate(SettingsDictionary settings, NativeEncoder encoder)
        {
            Contract.Requires(settings != null);
            Contract.Requires(encoder != null);

            uint bitRate;

            if (!uint.TryParse(settings["BitRate"], out bitRate) || bitRate < 8 || bitRate > 320)
            {
                throw new InvalidSettingException(string.Format(CultureInfo.CurrentCulture,
                                                                Resources.SampleEncoderBadBitRate, settings["BitRate"]));
            }

            // Default to an average bitrate, unless a constant bitrate is specified:
            if (string.IsNullOrEmpty(settings["ForceCBR"]) ||
                string.Compare(settings["ForceCBR"], bool.FalseString, StringComparison.OrdinalIgnoreCase) == 0)
            {
                encoder.SetVbr(VbrMode.Abr);
                encoder.SetMeanBitRate((int)bitRate);
            }
            else if (string.Compare(settings["ForceCBR"], bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0)
            {
                encoder.SetBitRate((int)bitRate);
            }
            else
            {
                throw new InvalidSettingException(string.Format(CultureInfo.CurrentCulture,
                                                                Resources.SampleEncoderBadForceCBR, settings["ForceCBR"]));
            }
        }