Beispiel #1
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);
        }
Beispiel #2
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();
        }
    }
Beispiel #3
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();
            }
Beispiel #4
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);
        }
Beispiel #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);
        }
Beispiel #6
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);
        }
Beispiel #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();
        }
Beispiel #8
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");
            }
Beispiel #9
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();
        }
Beispiel #10
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();
        }
Beispiel #11
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);
            }
Beispiel #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));
        }
        public async Task <FFmpegProfileViewModel> Handle(NewFFmpegProfile request, CancellationToken cancellationToken)
        {
            int defaultResolutionId = await _configElementRepository
                                      .GetValue <int>(ConfigElementKey.FFmpegDefaultResolutionId)
                                      .IfNoneAsync(0);

            List <Resolution> allResolutions = await _resolutionRepository.GetAll();

            Option <Resolution> maybeDefaultResolution = allResolutions.Find(r => r.Id == defaultResolutionId);
            Resolution          defaultResolution      = maybeDefaultResolution.Match(identity, () => allResolutions.Head());

            return(ProjectToViewModel(FFmpegProfile.New("New Profile", defaultResolution)));
        }
Beispiel #14
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();
            }
Beispiel #15
0
        public static Unit Initialize(TvContext context)
        {
            if (context.Resolutions.Any())
            {
                return Unit.Default;
            }

            var resolutions = new List<Resolution>
            {
                new() { Id = 1, Name = "720x480", Width = 720, Height = 480 },
                new() { Id = 2, Name = "1280x720", Width = 1280, Height = 720 },
                new() { Id = 3, Name = "1920x1080", Width = 1920, Height = 1080 },
                new() { Id = 4, Name = "3840x2160", Width = 3840, Height = 2160 }
            };
            context.Resolutions.AddRange(resolutions);
            context.SaveChanges();

            var resolutionConfig = new ConfigElement
            {
                Key = ConfigElementKey.FFmpegDefaultResolutionId.Key,
                Value = "3" // 1920x1080
            };
            context.ConfigElements.Add(resolutionConfig);
            context.SaveChanges();

            var defaultProfile = FFmpegProfile.New("1920x1080 x264 ac3", resolutions[2]);
            context.FFmpegProfiles.Add(defaultProfile);
            context.SaveChanges();

            var profileConfig = new ConfigElement
            {
                Key = ConfigElementKey.FFmpegDefaultProfileId.Key,
                Value = defaultProfile.Id.ToString()
            };
            context.ConfigElements.Add(profileConfig);
            context.SaveChanges();

            var defaultChannel = new Channel(Guid.NewGuid())
            {
                Number = "1",
                Name = "ErsatzTV",
                FFmpegProfile = defaultProfile,
                StreamingMode = StreamingMode.TransportStream
            };
            context.Channels.Add(defaultChannel);
            context.SaveChanges();

            // TODO: create looping static image that mentions configuring via web
            return Unit.Default;
        }
    }
Beispiel #16
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);
            }
Beispiel #17
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);
            }
Beispiel #18
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();
            }
Beispiel #19
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));
            }
Beispiel #20
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);
            }
        }
Beispiel #21
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();
        }
Beispiel #22
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");
        }
Beispiel #23
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);
            }
Beispiel #24
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");
            }
Beispiel #25
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);
        }
Beispiel #26
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);
        }
Beispiel #27
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));
        }
Beispiel #28
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();
            }
Beispiel #29
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);
        }
Beispiel #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();
            }