コード例 #1
0
        public static EncodingSettings CreateAudioSettings(CodecEnum codec, RateControlEnum rateControl, int value)
        {
            switch (codec)
            {
            case CodecEnum.Aac:
                switch (rateControl)
                {
                case RateControlEnum.ConstantBitRate:
                    if (value < 0)
                    {
                        throw new ArgumentException("ConstantBitRate for ACC must be beetwenn greater than 0 kbps");
                    }
                    break;

                case RateControlEnum.None:
                    if (rateControl != RateControlEnum.None)
                    {
                        throw new ArgumentException($"{nameof(RateControlEnum)}:{RateControlEnum.None} is only allowed with {nameof(RateControlEnum)}:{rateControl}");
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(rateControl), rateControl, null);
                }
                break;

            case CodecEnum.None:
                if (rateControl != RateControlEnum.Remove)
                {
                    throw new ArgumentException($"{nameof(CodecEnum)}:{codec} is only allowed with {nameof(RateControlEnum)}:{RateControlEnum.Remove}");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(codec), codec, null);
            }

            return(new EncodingSettings
            {
                Codec = codec,
                RateControl = rateControl,
                Present = PresetsEnum.Medium,
                Value = value,
                Media = MediaEnum.Audio
            });
        }
コード例 #2
0
        public static EncodingSettings CreateVideoSettings(CodecEnum codec, RateControlEnum rateControl, PresetsEnum present, int value)
        {
            switch (codec)
            {
            case CodecEnum.h265:
                switch (rateControl)
                {
                case RateControlEnum.ConstantRateFactor:
                    if (value < 0 || value > 51)
                    {
                        throw new ArgumentException("CRF must be beetwenn 0 (best) and 51 (worst)");
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(rateControl), rateControl, null);
                }
                break;

            case CodecEnum.Copy:
                if (rateControl != RateControlEnum.None)
                {
                    throw new ArgumentException($"{nameof(CodecEnum)}:{CodecEnum.Copy} is only allowed with {nameof(RateControlEnum)}:{rateControl}");
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(codec), codec, null);
            }

            return(new EncodingSettings
            {
                Codec = codec,
                RateControl = rateControl,
                Present = present,
                Value = value,
                Media = MediaEnum.Video
            });
        }