Пример #1
0
        public void Should_SetVideoBufferSize_When_ContentIsCorrectSize_ForTransportStream()
        {
            var ffmpegProfile = new FFmpegProfile
            {
                Resolution = new Resolution {
                    Width = 1920, Height = 1080
                },
                VideoBufferSize = 2525
            };

            // not anamorphic
            var version = new MediaVersion
            {
                Width = 1920, Height = 1080, SampleAspectRatio = "1:1"
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                version,
                new MediaStream {
                Codec = "mpeg2video"
            },
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ScaledSize.IsNone.Should().BeTrue();
            actual.PadToDesiredResolution.Should().BeFalse();
            actual.VideoBufferSize.IfNone(0).Should().Be(2525);
        }
Пример #2
0
        public void Should_SetCopyVideoFormat_When_ContentIsCorrectSize_ForHttpLiveStreamingDirect()
        {
            var ffmpegProfile = new FFmpegProfile
            {
                Resolution = new Resolution {
                    Width = 1920, Height = 1080
                },
                VideoFormat = FFmpegProfileVideoFormat.H264
            };

            // not anamorphic
            var version = new MediaVersion
            {
                Width = 1920, Height = 1080, SampleAspectRatio = "1:1"
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.HttpLiveStreamingDirect,
                ffmpegProfile,
                version,
                new MediaStream {
                Codec = "mpeg2video"
            },
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ScaledSize.IsNone.Should().BeTrue();
            actual.PadToDesiredResolution.Should().BeFalse();
            actual.VideoFormat.Should().Be(FFmpegProfileVideoFormat.Copy);
        }
Пример #3
0
        public void Should_SetNormalizeLoudness_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                NormalizeLoudness = true
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream {
                Codec = "ac3"
            },
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.NormalizeLoudness.Should().BeTrue();
        }
    }
Пример #4
0
            public void Should_NotPadToDesiredResolution_When_NotNormalizingResolution()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with
                {
                    NormalizeResolution = false,
                    Resolution          = new Resolution {
                        Width = 1920, Height = 1080
                    }
                };

                // not anamorphic
                var version = new MediaVersion {
                    Width = 1918, Height = 1080, SampleAspectRatio = "1:1"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.ScaledSize.IsNone.Should().BeTrue();
                actual.PadToDesiredResolution.Should().BeFalse();
            }
Пример #5
0
        public void Should_SetDesiredVideoFormat_When_ContentIsPadded_ForTransportStream()
        {
            var ffmpegProfile = new FFmpegProfile
            {
                Resolution = new Resolution {
                    Width = 1920, Height = 1080
                },
                VideoFormat = FFmpegProfileVideoFormat.H264
            };

            // not anamorphic
            var version = new MediaVersion {
                Width = 1918, Height = 1080, SampleAspectRatio = "1:1"
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                version,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ScaledSize.IsNone.Should().BeTrue();
            actual.PadToDesiredResolution.Should().BeTrue();
            actual.VideoFormat.Should().Be(FFmpegProfileVideoFormat.H264);
        }
Пример #6
0
        public void Should_ScaleToEvenDimensions_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                Resolution = new Resolution {
                    Width = 1280, Height = 720
                }
            };

            var version = new MediaVersion {
                Width = 706, Height = 362, SampleAspectRatio = "32:27"
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                version,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            IDisplaySize scaledSize = actual.ScaledSize.IfNone(new MediaVersion {
                Width = 0, Height = 0
            });

            scaledSize.Width.Should().Be(1280);
            scaledSize.Height.Should().Be(554);
            actual.PadToDesiredResolution.Should().BeTrue();
        }
Пример #7
0
        public void Should_NotPadToDesiredResolution_When_UnscaledContentIsUnderSized_ForHttpLiveStreaming()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                Resolution = new Resolution {
                    Width = 1920, Height = 1080
                }
            };

            // not anamorphic
            var version = new MediaVersion {
                Width = 1918, Height = 1080, SampleAspectRatio = "1:1"
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.HttpLiveStreamingDirect,
                ffmpegProfile,
                version,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ScaledSize.IsNone.Should().BeTrue();
            actual.PadToDesiredResolution.Should().BeFalse();
        }
Пример #8
0
        public void ShouldNot_SetScaledSize_When_ScaledSizeWouldEqualContentSize_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                Resolution = new Resolution {
                    Width = 1920, Height = 1080
                }
            };

            // not anamorphic
            var version = new MediaVersion {
                Width = 1918, Height = 1080, SampleAspectRatio = "1:1"
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                version,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ScaledSize.IsNone.Should().BeTrue();
        }
Пример #9
0
            public void Should_SetDesiredVideoCodec_When_ContentIsPadded_ForTransportStream()
            {
                var ffmpegProfile = new FFmpegProfile
                {
                    NormalizeResolution = true,
                    Resolution          = new Resolution {
                        Width = 1920, Height = 1080
                    },
                    NormalizeVideoCodec = false,
                    VideoCodec          = "testCodec"
                };

                // not anamorphic
                var version = new MediaVersion {
                    Width = 1918, Height = 1080, SampleAspectRatio = "1:1"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.ScaledSize.IsNone.Should().BeTrue();
                actual.PadToDesiredResolution.Should().BeTrue();
                actual.VideoCodec.Should().Be("testCodec");
            }
Пример #10
0
            Should_SetVideoBufferSize_When_ContentIsCorrectSize_And_NormalizingWrongCodec_ForTransportStream()
            {
                var ffmpegProfile = new FFmpegProfile
                {
                    NormalizeResolution = true,
                    Resolution          = new Resolution {
                        Width = 1920, Height = 1080
                    },
                    NormalizeVideoCodec = true,
                    VideoBufferSize     = 2525
                };

                // not anamorphic
                var version = new MediaVersion
                {
                    Width = 1920, Height = 1080, SampleAspectRatio = "1:1", VideoCodec = "mpeg2video"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.ScaledSize.IsNone.Should().BeTrue();
                actual.PadToDesiredResolution.Should().BeFalse();
                actual.VideoBufferSize.IfNone(0).Should().Be(2525);
            }
Пример #11
0
        public void Should_SetAudioSampleRate_With_CorrectFormat_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                AudioFormat     = FFmpegProfileAudioFormat.Ac3,
                AudioSampleRate = 48
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream {
                Codec = "ac3"
            },
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.AudioSampleRate.IfNone(0).Should().Be(48);
        }
Пример #12
0
        public void Should_SetAudioDuration_With_CorrectFormat_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                AudioSampleRate = 48,
                AudioFormat     = FFmpegProfileAudioFormat.Ac3
            };

            var version = new MediaVersion
            {
                SampleAspectRatio = "1:1", Width = 1920, Height = 1080, Duration = TimeSpan.FromMinutes(5)
            }; // not pulled from here

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                version,
                new MediaStream(),
                new MediaStream {
                Codec = "ac3"
            },
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.FromMinutes(2),
                false,
                None);

            actual.AudioDuration.IfNone(TimeSpan.MinValue).Should().Be(TimeSpan.FromMinutes(2));
        }
Пример #13
0
            public void Should_SetRealtime_ForTransportStream()
            {
                FFmpegProfile ffmpegProfile = TestProfile();

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    new MediaVersion(),
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.RealtimeOutput.Should().BeTrue();
            }
Пример #14
0
            public void Should_UseSpecifiedThreadCount_ForHttpLiveStreaming()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with {
                    ThreadCount = 7
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.HttpLiveStreaming,
                    ffmpegProfile,
                    new MediaVersion(),
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.ThreadCount.Should().Be(7);
            }
Пример #15
0
            public void Should_SetFormatFlags_ForHttpLiveStreaming()
            {
                FFmpegProfile ffmpegProfile = TestProfile();

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.HttpLiveStreaming,
                    ffmpegProfile,
                    new MediaVersion(),
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                string[] expected = { "+genpts", "+discardcorrupt", "+igndts" };
                actual.FormatFlags.Count.Should().Be(expected.Length);
                actual.FormatFlags.Should().Contain(expected);
            }
Пример #16
0
            public void ShouldNot_SetScaledSize_When_NotNormalizingResolution_ForTransportStream()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with {
                    NormalizeResolution = false
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    new MediaVersion(),
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.ScaledSize.IsNone.Should().BeTrue();
            }
Пример #17
0
            public void Should_SetStreamSeek_When_PlaybackIsLate_ForHttpLiveStreaming()
            {
                DateTimeOffset now = DateTimeOffset.Now;

                FFmpegProfile ffmpegProfile = TestProfile();

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.HttpLiveStreaming,
                    ffmpegProfile,
                    new MediaVersion(),
                    now,
                    now.AddMinutes(5));

                actual.StreamSeek.IsSome.Should().BeTrue();
                actual.StreamSeek.IfNone(TimeSpan.Zero).Should().Be(TimeSpan.FromMinutes(5));
            }
Пример #18
0
            public void Should_UseHardwareAcceleration()
            {
                FFmpegProfile ffmpegProfile =
                    TestProfile() with {
                    HardwareAcceleration = HardwareAccelerationKind.Qsv
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    new MediaVersion(),
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.HardwareAcceleration.Should().Be(HardwareAccelerationKind.Qsv);
            }
        }
Пример #19
0
        public void Should_SetRealtime_ForHttpLiveStreaming()
        {
            FFmpegProfile ffmpegProfile = TestProfile();

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.HttpLiveStreamingDirect,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.RealtimeOutput.Should().BeTrue();
        }
Пример #20
0
        public void Should_Not_GenPts_ForHlsSegmenter()
        {
            FFmpegProfile ffmpegProfile = TestProfile();

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.HttpLiveStreamingSegmenter,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.FormatFlags.Should().NotContain("+genpts");
        }
Пример #21
0
            public void Should_SetAudioBufferSize_When_NormalizingWrongCodec_ForTransportStream()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with
                {
                    NormalizeAudioCodec = true,
                    AudioBufferSize     = 2424
                };

                var version = new MediaVersion {
                    AudioCodec = "ac3"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.AudioBufferSize.IfNone(0).Should().Be(2424);
            }
Пример #22
0
            public void Should_SetCopyAudioCodec_When_NormalizingWrongCodec_ForHttpLiveStreaming()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with
                {
                    NormalizeAudioCodec = true,
                    AudioCodec          = "aac"
                };

                var version = new MediaVersion {
                    AudioCodec = "ac3"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.HttpLiveStreaming,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.AudioCodec.Should().Be("copy");
            }
Пример #23
0
        public void Should_SetFormatFlags_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile();

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            string[] expected = { "+genpts", "+discardcorrupt", "+igndts" };
            actual.FormatFlags.Count.Should().Be(expected.Length);
            actual.FormatFlags.Should().Contain(expected);
        }
Пример #24
0
        public void Should_UseSpecifiedThreadCount_ForHttpLiveStreamingSegmenter()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with {
                ThreadCount = 7
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.HttpLiveStreamingSegmenter,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ThreadCount.Should().Be(7);
        }
Пример #25
0
        public void Should_SetStreamSeek_When_PlaybackIsLate_ForTransportStream()
        {
            DateTimeOffset now = DateTimeOffset.Now;

            FFmpegProfile ffmpegProfile = TestProfile();

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream(),
                now,
                now.AddMinutes(5),
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.StreamSeek.IsSome.Should().BeTrue();
            actual.StreamSeek.IfNone(TimeSpan.Zero).Should().Be(TimeSpan.FromMinutes(5));
        }
Пример #26
0
        public void Should_Not_UseSpecifiedThreadCount_ForTransportStream()
        {
            // MPEG-TS requires realtime output which is hardcoded to a single thread

            FFmpegProfile ffmpegProfile = TestProfile() with {
                ThreadCount = 7
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream(),
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.ThreadCount.Should().Be(1);
        }
Пример #27
0
            public void ShouldNot_SetAudioSampleRate_When_CorrectCodec_ForTransportStream()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with
                {
                    NormalizeAudioCodec = true,
                    NormalizeAudio      = true,
                    AudioCodec          = "ac3",
                    AudioSampleRate     = 48
                };

                var version = new MediaVersion {
                    AudioCodec = "ac3"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.AudioSampleRate.IsNone.Should().BeTrue();
            }
Пример #28
0
    public Command WrapSegmenter(string ffmpegPath, bool saveReports, Channel channel, string scheme, string host)
    {
        FFmpegPlaybackSettings playbackSettings = _playbackSettingsCalculator.ConcatSettings;

        Process process = new FFmpegProcessBuilder(ffmpegPath, saveReports, _logger)
                          .WithThreads(1)
                          .WithQuiet()
                          .WithFormatFlags(playbackSettings.FormatFlags)
                          .WithRealtimeOutput(true)
                          .WithInput($"http://localhost:{Settings.ListenPort}/iptv/channel/{channel.Number}.m3u8?mode=segmenter")
                          .WithMap("0")
                          .WithCopyCodec()
                          .WithMetadata(channel, None)
                          .WithFormat("mpegts")
                          .WithPipe()
                          .Build();

        return(Cli.Wrap(process.StartInfo.FileName)
               .WithArguments(process.StartInfo.ArgumentList)
               .WithValidation(CommandResultValidation.None)
               .WithEnvironmentVariables(process.StartInfo.Environment.ToDictionary(kvp => kvp.Key, kvp => kvp.Value))
               .WithStandardErrorPipe(PipeTarget.ToStream(Stream.Null)));
    }
Пример #29
0
        public void Should_SetAudioChannels_ForTransportStream()
        {
            FFmpegProfile ffmpegProfile = TestProfile() with
            {
                AudioChannels = 6
            };

            FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                StreamingMode.TransportStream,
                ffmpegProfile,
                TestVersion,
                new MediaStream(),
                new MediaStream {
                Codec = "ac3"
            },
                DateTimeOffset.Now,
                DateTimeOffset.Now,
                TimeSpan.Zero,
                TimeSpan.Zero,
                false,
                None);

            actual.AudioChannels.IfNone(0).Should().Be(6);
        }
Пример #30
0
            public void ShouldNot_SetScaledSize_When_ContentIsCorrectSize_ForTransportStream()
            {
                FFmpegProfile ffmpegProfile = TestProfile() with
                {
                    NormalizeResolution = true,
                    Resolution          = new Resolution {
                        Width = 1920, Height = 1080
                    }
                };

                // not anamorphic
                var version = new MediaVersion {
                    Width = 1920, Height = 1080, SampleAspectRatio = "1:1"
                };

                FFmpegPlaybackSettings actual = _calculator.CalculateSettings(
                    StreamingMode.TransportStream,
                    ffmpegProfile,
                    version,
                    DateTimeOffset.Now,
                    DateTimeOffset.Now);

                actual.ScaledSize.IsNone.Should().BeTrue();
            }