コード例 #1
0
 /// <summary>
 /// Applies an H264 profile.
 /// </summary>
 public FFmpegH264VideoCommandBuilder WithProfile(H264Profile profile)
 {
     if (profile == H264Profile.None)
     {
         return(this);
     }
     TryAddSimpleCommand($"-profile:v {profile.ToString().ToLowerInvariant()}", profile.ToString());
     return(this);
 }
コード例 #2
0
 public FFmpegVideoCommandBuilder WithProfile(H264Profile profile)
 {
     if (profile == H264Profile.none)
     {
         return(this);
     }
     TryAddSimpleCommand($"-profile:v {profile}", profile.ToString());
     return(this);
 }
コード例 #3
0
        protected void AdjustH264VideoEncoderConfiguration(Profile profile, VideoEncoderConfigurationOptions options)
        {
            if (profile.VideoEncoderConfiguration.H264 == null)
            {
                profile.VideoEncoderConfiguration.H264 = new H264Configuration();
            }

            H264Profile[] profiles = options.H264.H264ProfilesSupported;
            // The parameter of H264Profile is set the highest value that DUT supports as the order is High/Extended/Main/Baseline.
            H264Profile encoderProfile = H264Profile.High;

            // if high not supported...
            if (!profiles.Contains(H264Profile.High))
            {
                if (profiles.Contains(H264Profile.Extended))
                {
                    encoderProfile = H264Profile.Extended;
                }
                else
                {
                    // if Main supported
                    if (profiles.Contains(H264Profile.Main))
                    {
                        encoderProfile = H264Profile.Main;
                    }
                    else
                    {
                        // if Extended not supported.
                        encoderProfile = H264Profile.Baseline;
                    }
                }
            }

            profile.VideoEncoderConfiguration.H264.H264Profile = encoderProfile;

            if (options.H264.ResolutionsAvailable.Length > 0)
            {
                profile.VideoEncoderConfiguration.Resolution = options.H264.ResolutionsAvailable[0];
            }
            if (options.H264.GovLengthRange != null)
            {
                profile.VideoEncoderConfiguration.H264.GovLength =
                    options.H264.GovLengthRange.Min > 30 ? options.H264.GovLengthRange.Min : 30;
            }
            else
            {
                profile.VideoEncoderConfiguration.H264.GovLength = 30;
            }
        }
コード例 #4
0
ファイル: H264ProfileTests.cs プロジェクト: As-You-Like/Media
        public void Parse()
        {
            var bp_30   = new H264Profile(H264ProfileType.BP, 30);
            var main_30 = new H264Profile(H264ProfileType.MP, 30);
            var high_30 = new H264Profile(H264ProfileType.HiP, 30);

            Assert.Equal(bp_30, CodecInfo.Parse("avc1.42001e"));                                    // 66:0:30
            Assert.Equal(new H264Profile(H264ProfileType.BP, 31), CodecInfo.Parse("avc1.42001f"));  // 66:0:31
            Assert.Equal(new H264Profile(H264ProfileType.BP, 32), CodecInfo.Parse("avc1.420020"));  // 66:0:32
            Assert.Equal(high_30, CodecInfo.Parse("avc1.64001E"));                                  // 100:0:30
            Assert.Equal(new H264Profile(H264ProfileType.HiP, 41), CodecInfo.Parse("avc1.640029")); // 100:0:41

            Assert.Equal("avc1.42001e", bp_30.ToString());
            Assert.Equal("avc1.4d001e", main_30.ToString());
            Assert.Equal("avc1.64001e", high_30.ToString());
        }
コード例 #5
0
        protected void AdjustH264VideoEncoderConfiguration(Profile profile, VideoEncoderConfigurationOptions options)
        {
            if (profile.VideoEncoderConfiguration.H264 == null)
            {
                profile.VideoEncoderConfiguration.H264 = new H264Configuration();
            }

            H264Profile[] profiles       = options.H264.H264ProfilesSupported;
            H264Profile   encoderProfile = H264Profile.Baseline;

            // if baseline not supported...
            if (!profiles.Contains(H264Profile.Baseline))
            {
                if (profiles.Contains(H264Profile.Main))
                {
                    encoderProfile = H264Profile.Main;
                }
                else
                {
                    // if Main not supported
                    if (profiles.Contains(H264Profile.Extended))
                    {
                        encoderProfile = H264Profile.Extended;
                    }
                    else
                    {
                        // if Extended not supported.
                        encoderProfile = H264Profile.High;
                    }
                }
            }

            profile.VideoEncoderConfiguration.H264.H264Profile = encoderProfile;

            if (options.H264.GovLengthRange != null)
            {
                profile.VideoEncoderConfiguration.H264.GovLength =
                    options.H264.GovLengthRange.Min > 30 ? options.H264.GovLengthRange.Min : 30;
            }
            else
            {
                profile.VideoEncoderConfiguration.H264.GovLength = 30;
            }
        }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="width">Width of frame in pixels</param>
 /// <param name="height">Height of frame in pixels</param>
 /// <param name="bitrate">The bitrate in kb/s</param>
 /// <param name="preset">h264 preset</param>
 /// <param name="profile">h264 profile</param>
 public Quality(int width, int height, int bitrate, H264Preset preset, H264Profile profile)
     : this(width, height, bitrate, preset)
 {
     Profile = profile;
 }
コード例 #7
0
 public static RTCH264Profile ToPlatformNative(this H264Profile nativePort) => (RTCH264Profile)nativePort;
コード例 #8
0
ファイル: H264ProfileTests.cs プロジェクト: As-You-Like/Media
 public void DoesNotDropMiddle()
 {
     Assert.Equal("avc1.4d401e", H264Profile.Parse("avc1.4d401e").Name);
 }
コード例 #9
0
        public void H264VideoEncoderConfiguration()
        {
            RunTest(() =>
            {
                VideoEncoderConfiguration[] configs = GetVideoEncoderConfigurations();
                string reason;
                Assert(ValidateVideoEncoderConfigs(configs, out reason), reason, Resources.StepValidatingVideoEncoderConfigs_Title);

                VideoEncoderConfigurationOptions options = null;
                VideoEncoderConfiguration config         = GetVideoEncoderConfiguration(configs, VideoEncoding.H264, out options);

                config.Encoding         = VideoEncoding.H264;
                config.Resolution       = options.H264.ResolutionsAvailable[0];
                config.Quality          = options.QualityRange.Max;
                config.H264             = new H264Configuration();
                config.H264.GovLength   = options.H264.GovLengthRange.Max + 1;//invalid param
                config.H264.H264Profile = H264Profile.Baseline;
                config.MPEG4            = null;
                if (config.RateControl != null)
                {
                    config.RateControl.FrameRateLimit   = options.H264.FrameRateRange.Min;
                    config.RateControl.EncodingInterval = options.H264.EncodingIntervalRange.Min;
                }
                string details = string.Format("Setting invalid configuration (/VideoEncoderConfiguration/H264/GovLength = {0})", config.H264.GovLength);
                SetInvalidVideoEncoderConfiguration(config, false, details);

                VideoResolution highest = null;
                VideoResolution lowest  = null;
                VideoResolution median  = null;

                FindResolutions(options.H264.ResolutionsAvailable, out highest, out lowest, out median);

                Func <List <H264Profile>, H264Profile> firstSupported =
                    new Func <List <H264Profile>, H264Profile>(
                        (list) =>
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (options.H264.H264ProfilesSupported.Contains(list[i]))
                        {
                            return(list[i]);
                        }
                    }
                    return(options.H264.H264ProfilesSupported[0]);
                });

                List <H264Profile> profiles = new List <H264Profile>();
                profiles.Add(H264Profile.Baseline);
                profiles.Add(H264Profile.Main);
                profiles.Add(H264Profile.Extended);
                profiles.Add(H264Profile.High);

                H264Profile profile = firstSupported(profiles);


                config.H264.H264Profile         = profile;
                config.RateControl              = new VideoRateControl();
                config.RateControl.BitrateLimit = 64000;

                // max

                config.Resolution = highest;
                config.Quality    = options.QualityRange.Max;
                config.RateControl.FrameRateLimit   = options.H264.FrameRateRange.Max;
                config.RateControl.EncodingInterval = options.H264.EncodingIntervalRange.Min;
                config.H264.GovLength = options.H264.GovLengthRange.Min;

                SetVideoEncoderConfiguration(config, false, false, "SetVideoEncoderConfiguration (use max values)");
                VideoEncoderConfiguration newConfig = GetVideoEncoderConfiguration(config.token);

                bool ok = ConfigurationValid(newConfig, VideoEncoding.H264, highest, out reason);

                Action checkProfile =
                    new Action(
                        () =>
                {
                    if (newConfig.H264.H264Profile != config.H264.H264Profile)
                    {
                        ok           = false;
                        string error = string.Format("H264Profile is incorrect. Expected: {0}, actual: {1} ",
                                                     config.H264.H264Profile, newConfig.H264.H264Profile);
                        if (string.IsNullOrEmpty(reason))
                        {
                            reason = error;
                        }
                        else
                        {
                            reason += System.Environment.NewLine;
                            reason += error;
                        }
                    }
                });

                checkProfile();
                Assert(ok, reason, "Check that the DUT accepted values passed");

                // Min

                profiles.Clear();
                profiles.Add(H264Profile.Main);
                profiles.Add(H264Profile.Extended);
                profiles.Add(H264Profile.High);
                profiles.Add(H264Profile.Baseline);

                profile = firstSupported(profiles);


                config.Resolution = lowest;
                config.Quality    = options.QualityRange.Min;
                config.RateControl.FrameRateLimit   = options.H264.FrameRateRange.Min;
                config.RateControl.EncodingInterval = options.H264.EncodingIntervalRange.Max;
                config.H264.GovLength   = options.H264.GovLengthRange.Max;
                config.H264.H264Profile = profile;

                SetVideoEncoderConfiguration(config, false, false, "SetVideoEncoderConfiguration (use min values)");
                newConfig = GetVideoEncoderConfiguration(config.token);

                ok = ConfigurationValid(newConfig, VideoEncoding.H264, lowest, out reason);
                checkProfile();
                Assert(ok, reason, "Check that the DUT accepted values passed");

                // Average


                profiles.Clear();
                profiles.Add(H264Profile.Extended);
                profiles.Add(H264Profile.High);
                profiles.Add(H264Profile.Baseline);
                profiles.Add(H264Profile.Main);

                profile = firstSupported(profiles);

                config.Resolution = median;
                config.Quality    = options.QualityRange.Average();
                config.RateControl.FrameRateLimit   = options.H264.FrameRateRange.Average();
                config.RateControl.EncodingInterval = options.H264.EncodingIntervalRange.Average();
                config.H264.GovLength   = options.H264.GovLengthRange.Average();
                config.H264.H264Profile = profile;

                SetVideoEncoderConfiguration(config, false, false, "SetVideoEncoderConfiguration (use average values)");
                newConfig = GetVideoEncoderConfiguration(config.token);

                ok = ConfigurationValid(newConfig, VideoEncoding.H264, median, out reason);
                checkProfile();
                Assert(ok, reason, "Check that the DUT accepted values passed");
            });
        }
コード例 #10
0
        public static void UpdateVideoEncoderConfiguration(VideoEncoderConfiguration vec,
                                                           VideoEncoding encoding,
                                                           VideoEncoderConfigurationOptions videoOptions)
        {
            vec.Encoding = encoding;

            switch (encoding)
            {
            case VideoEncoding.JPEG:

                VideoResolution resolution = videoOptions.JPEG.ResolutionsAvailable.OrderBy(R => R.Height * R.Width).Last();

                vec.H264       = null;
                vec.MPEG4      = null;
                vec.Resolution = videoOptions.JPEG.ResolutionsAvailable.First();
                vec.Quality    = videoOptions.QualityRange.Average();

                if (vec.RateControl == null && (videoOptions.JPEG.EncodingIntervalRange != null ||
                                                videoOptions.JPEG.FrameRateRange != null ||
                                                (videoOptions.Extension != null && videoOptions.Extension.JPEG != null && videoOptions.Extension.JPEG.BitrateRange != null)))
                {
                    vec.RateControl = new VideoRateControl();
                }

                if (videoOptions.JPEG.EncodingIntervalRange != null)
                {
                    vec.RateControl.EncodingInterval = videoOptions.JPEG.EncodingIntervalRange.Average();
                }
                if (videoOptions.JPEG.FrameRateRange != null)
                {
                    vec.RateControl.FrameRateLimit = videoOptions.JPEG.FrameRateRange.Average();
                }
                if (videoOptions.Extension != null && videoOptions.Extension.JPEG != null && videoOptions.Extension.JPEG.BitrateRange != null)
                {
                    vec.RateControl.BitrateLimit = videoOptions.Extension.JPEG.BitrateRange.Average();
                }
                break;

            case VideoEncoding.MPEG4:
                vec.H264 = null;
                if (vec.MPEG4 == null)
                {
                    vec.MPEG4 = new Mpeg4Configuration();
                }
                vec.Quality            = videoOptions.QualityRange.Average();
                vec.MPEG4.Mpeg4Profile = videoOptions.MPEG4.Mpeg4ProfilesSupported.Contains(Mpeg4Profile.SP)
                                ? Mpeg4Profile.SP
                                : Mpeg4Profile.ASP;

                vec.Resolution = videoOptions.MPEG4.ResolutionsAvailable[0];

                if (vec.RateControl == null && (videoOptions.MPEG4.EncodingIntervalRange != null ||
                                                videoOptions.MPEG4.FrameRateRange != null ||
                                                (videoOptions.Extension != null && videoOptions.Extension.MPEG4 != null && videoOptions.Extension.MPEG4.BitrateRange != null)))
                {
                    vec.RateControl = new VideoRateControl();
                }

                if (videoOptions.MPEG4.EncodingIntervalRange != null)
                {
                    vec.RateControl.EncodingInterval = videoOptions.MPEG4.EncodingIntervalRange.Average();
                }
                if (videoOptions.MPEG4.FrameRateRange != null)
                {
                    vec.RateControl.FrameRateLimit = videoOptions.MPEG4.FrameRateRange.Average();
                }
                if (videoOptions.Extension != null && videoOptions.Extension.MPEG4 != null && videoOptions.Extension.MPEG4.BitrateRange != null)
                {
                    vec.RateControl.BitrateLimit = videoOptions.Extension.MPEG4.BitrateRange.Average();
                }

                if (videoOptions.MPEG4.GovLengthRange != null)
                {
                    vec.MPEG4.GovLength = videoOptions.MPEG4.GovLengthRange.Min > 30
                                              ?
                                          videoOptions.MPEG4.GovLengthRange.Min
                                              :
                                          (videoOptions.MPEG4.GovLengthRange.Max < 30) ? videoOptions.MPEG4.GovLengthRange.Max : 30;
                }
                else
                {
                    vec.MPEG4.GovLength = 30;
                }

                break;

            case VideoEncoding.H264:
                vec.MPEG4 = null;
                if (vec.H264 == null)
                {
                    vec.H264 = new H264Configuration();
                }
                vec.Quality = videoOptions.QualityRange.Average();

                H264Profile h264Profile = H264Profile.High;
                if (videoOptions.H264.H264ProfilesSupported.Contains(H264Profile.Baseline))
                {
                    h264Profile = H264Profile.Baseline;
                }
                else if (videoOptions.H264.H264ProfilesSupported.Contains(H264Profile.Main))
                {
                    h264Profile = H264Profile.Main;
                }
                else if (videoOptions.H264.H264ProfilesSupported.Contains(H264Profile.Extended))
                {
                    h264Profile = H264Profile.Extended;
                }
                vec.H264.H264Profile = h264Profile;

                vec.Resolution = videoOptions.MPEG4.ResolutionsAvailable[0];

                if (vec.RateControl == null && (videoOptions.H264.EncodingIntervalRange != null ||
                                                videoOptions.H264.FrameRateRange != null ||
                                                (videoOptions.Extension != null && videoOptions.Extension.H264 != null && videoOptions.Extension.H264.BitrateRange != null)))
                {
                    vec.RateControl = new VideoRateControl();
                }

                if (videoOptions.H264.EncodingIntervalRange != null)
                {
                    vec.RateControl.EncodingInterval = videoOptions.H264.EncodingIntervalRange.Average();
                }
                if (videoOptions.H264.FrameRateRange != null)
                {
                    vec.RateControl.FrameRateLimit = videoOptions.H264.FrameRateRange.Average();
                }
                if (videoOptions.Extension != null && videoOptions.Extension.H264 != null && videoOptions.Extension.H264.BitrateRange != null)
                {
                    vec.RateControl.BitrateLimit = videoOptions.Extension.H264.BitrateRange.Average();
                }

                if (videoOptions.H264.GovLengthRange != null)
                {
                    vec.H264.GovLength = videoOptions.H264.GovLengthRange.Min > 30
                                             ?
                                         videoOptions.H264.GovLengthRange.Min
                                             :
                                         (videoOptions.H264.GovLengthRange.Max < 30) ? videoOptions.H264.GovLengthRange.Max : 30;
                }
                else
                {
                    vec.H264.GovLength = 30;
                }


                break;
            }
        }