Пример #1
0
        public static void Run()
        {
            //set up ffmpeg command configuration with locations of default output folders, ffmpeg, and ffprobe.
            ResourceManagement.CommandConfiguration = CommandConfiguration.Create(
                @"c:\source\ffmpeg\bin\temp",
                @"c:\source\ffmpeg\bin\ffmpeg.exe",
                @"c:\source\ffmpeg\bin\ffprobe.exe");

            //create a factory
            var factory = CommandFactory.Create();

            //set up the output and input settings
            var inputSettings  = SettingsCollection.ForInput(new SeekPositionInput(1d));
            var outputSettings = SettingsCollection.ForOutput(
                new BitRateVideo(3000),
                new DurationOutput(10d));

            //create a command adding a two audio files
            var command = factory.CreateOutputCommand();

            var output = command.WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings)
                         .To <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", outputSettings)
                         .First();

            //use the metadata helper calculation engine to determine a snapshot of what the output duration should be.
            var metadataInfo = MetadataHelpers.GetMetadataInfo(command, output.GetStreamIdentifier());

            System.Console.ForegroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine("Metadata snapshot:");
            Console.WriteLine(string.Format("Duration: {0}", metadataInfo.VideoStream.VideoMetadata.Duration));
            Console.WriteLine(string.Format("Has Video: {0}", metadataInfo.HasVideo));
            Console.WriteLine(string.Format("Has Audio: {0}", metadataInfo.HasAudio));
            System.Console.ForegroundColor = ConsoleColor.White;
        }
Пример #2
0
        public void InputToFilterToOutput_Verify()
        {
            var baseline = Resource.From(Utilities.GetVideoFile())
                           .LoadMetadata()
                           .Streams
                           .OfType <VideoStream>()
                           .First();
            var calculatedSeconds  = (baseline.Info.VideoMetadata.Duration.TotalSeconds * 3d) - 2d;
            var calculatedDuration = TimeSpan.FromSeconds(calculatedSeconds);

            var filterchain = Filterchain.FilterTo <VideoStream>(new Split(3));

            var split = CommandFactory.Create()
                        .CreateOutputCommand()
                        .WithInput <VideoStream>(Utilities.GetVideoFile())
                        .Filter(filterchain);

            var concat1 = split.Command
                          .Select(split.StreamIdentifiers[1])
                          .Select(split.StreamIdentifiers[1])
                          .Filter(new Dissolve(1d));

            var concat2 = concat1.Select(split.StreamIdentifiers[2])
                          .Filter(new Dissolve(1d));

            var output = concat2.MapTo <Mp4>().First();

            var metadataInfo1 = MetadataHelpers.GetMetadataInfo(concat2.Command, concat2.StreamIdentifiers.FirstOrDefault());
            var metadataInfo2 = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier());

            Assert.True(metadataInfo1.VideoStream.VideoMetadata.Duration == calculatedDuration);
            Assert.True(metadataInfo2.VideoStream.VideoMetadata.Duration == calculatedDuration);
        }
Пример #3
0
        public override List <StreamIdentifier> SetupTemplate(FFmpegCommand command, List <StreamIdentifier> streamIdList)
        {
            if (streamIdList.Count != 2)
            {
                throw new InvalidOperationException("Crossfade Concatenate requires two input video streams.");
            }

            var streamTo   = streamIdList[1];
            var streamFrom = streamIdList[0];

            //grab the current length of the streamId specified
            var streamFromMetadata = MetadataHelpers.GetMetadataInfo(command, streamFrom);

            //from ==
            // - split
            //   - 1: start -> (end - durationOf)
            //   - 2: (end - durationOf) -> end

            //to ==
            // - split
            //   - 1: start -> (start + durationOf)
            //   - 2: (start + durationOf) -> end

            //blend ==
            // - from:2 / to:1

            //output ==
            // - (from:1, blend, to:2)

            var endMinusDuration = streamFromMetadata.VideoStream.Duration - Duration;

            var fromSplit = command.Select(streamFrom)
                            .Filter(Filterchain.FilterTo <VideoStream>(new Split(2)));

            var fromMain = fromSplit.Take(0)
                           .Filter(new TrimVideo(null, endMinusDuration.TotalSeconds, VideoUnitType.Seconds));

            var fromBlend = fromSplit.Take(1)
                            .Filter(new TrimVideo(endMinusDuration.TotalSeconds, null, VideoUnitType.Seconds));

            var toSplit = command.Select(streamTo)
                          .Filter(Filterchain.FilterTo <VideoStream>(new Split(2)));

            var toBlend = toSplit.Take(0)
                          .Filter(new TrimVideo(null, Duration.TotalSeconds, VideoUnitType.Seconds));

            var toMain = toSplit.Take(1)
                         .Filter(new TrimVideo(Duration.TotalSeconds, null, VideoUnitType.Seconds));

            var blendOut = command.Select(toBlend.StreamIdentifiers)
                           .Select(fromBlend.StreamIdentifiers)
                           .Filter(Filterchain.FilterTo <VideoStream>(new Blend(string.Format(CrossfadeAlgorithm, Duration.TotalSeconds))));

            var result = command.Select(fromMain.StreamIdentifiers)
                         .Select(blendOut.StreamIdentifiers)
                         .Select(toMain.StreamIdentifiers)
                         .Filter(Filterchain.FilterTo <VideoStream>(new Concat()));

            return(result.StreamIdentifiers);
        }
Пример #4
0
        public void InputSettingsToOutput_Verify()
        {
            var inputSettings = SettingsCollection.ForInput(
                new StartAt(1d),
                new DurationInput(3d));

            var output = CommandFactory.Create()
                         .CreateOutputCommand()
                         .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings)
                         .To <Mp4>()
                         .First();

            var metadataInfo = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier());

            Assert.True(metadataInfo.VideoStream.VideoMetadata.Duration == TimeSpan.FromSeconds(3));
        }
Пример #5
0
        public void InputSettingsToOutputSettingsOverDuration_Verify()
        {
            var inputSettings  = SettingsCollection.ForInput(new StartAt(1d));
            var outputSettings = SettingsCollection.ForOutput(
                new BitRateVideo(3000),
                new DurationOutput(10d));

            var output = CommandFactory.Create()
                         .CreateOutputCommand()
                         .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings)
                         .To <Mp4>(outputSettings)
                         .First();

            var metadataInfo = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier());

            Assert.True(metadataInfo.VideoStream.VideoMetadata.Duration == TimeSpan.FromSeconds(9)); // we have a 10 second video, and start 1 second in, this should only be 9
            Assert.True(metadataInfo.VideoStream.VideoMetadata.BitRate == 3000000L);
        }
Пример #6
0
        public void InputToOutput_Verify()
        {
            var baseline = Resource.From(Utilities.GetVideoFile())
                           .LoadMetadata()
                           .Streams
                           .OfType <VideoStream>()
                           .First();

            var output = CommandFactory.Create()
                         .CreateOutputCommand()
                         .WithInput <VideoStream>(Utilities.GetVideoFile())
                         .To <Mp4>()
                         .First();

            var metadataInfo = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier());

            Assert.True(metadataInfo.VideoStream.VideoMetadata.Duration == baseline.Info.VideoMetadata.Duration);
        }
Пример #7
0
        public void InputSettingsToOutputSettings_Verify()
        {
            var inputSettings  = SettingsCollection.ForInput(new StartAt(1d));
            var outputSettings = SettingsCollection.ForOutput(
                new BitRateVideo(3000),
                new DurationOutput(5d));

            var output = CommandFactory.Create()
                         .CreateOutputCommand()
                         .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings)
                         .To <Mp4>(outputSettings)
                         .First();

            var metadataInfo = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier());

            Assert.True(metadataInfo.VideoStream.Duration == TimeSpan.FromSeconds(3)); // this is because the input is only 4 seconds, we start at 1
            Assert.True(metadataInfo.VideoStream.BitRate == 3000000L);
        }
Пример #8
0
        public void InputSettingsToFilterToOutputSettings_Verify()
        {
            var baseline = Resource.From(Utilities.GetVideoFile())
                           .LoadMetadata()
                           .Streams
                           .OfType <VideoStream>()
                           .First();
            var calculatedSeconds  = ((baseline.Info.Duration.TotalSeconds - 1) * 3d) - 2d;
            var calculatedDuration = TimeSpan.FromSeconds(calculatedSeconds);

            var inputSettings  = SettingsCollection.ForInput(new StartAt(1d));
            var outputSettings = SettingsCollection.ForOutput(
                new BitRateVideo(3000),
                new DurationOutput(5d));

            var filterchain = Filterchain.FilterTo <VideoStream>(new Split(3));

            var split = CommandFactory.Create()
                        .CreateOutputCommand()
                        .WithInput <VideoStream>(Utilities.GetVideoFile(), inputSettings)
                        .Filter(filterchain);

            var concat1 = split.Command
                          .Select(split.StreamIdentifiers[0])
                          .Select(split.StreamIdentifiers[1])
                          .Filter(new CrossfadeConcatenate(1d));

            var concat2 = concat1.Select(split.StreamIdentifiers[2])
                          .Filter(new CrossfadeConcatenate(1d));

            var output = concat2.MapTo <Mp4>(outputSettings).First();

            var metadataInfo1 = MetadataHelpers.GetMetadataInfo(concat2.Command, concat2.StreamIdentifiers.FirstOrDefault());
            var metadataInfo2 = MetadataHelpers.GetMetadataInfo(output.Owner, output.GetStreamIdentifier());

            Assert.True(metadataInfo1.VideoStream.Duration == calculatedDuration);
            Assert.True(metadataInfo2.VideoStream.Duration == TimeSpan.FromSeconds(5));
            Assert.True(metadataInfo2.VideoStream.BitRate == 3000000L);
        }