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(); //create a command adding a video and audio file var command = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetAudioFile()); //select the first two streams from the input command var splitVideo = command.Take(0) .Filter(Filterchain.FilterTo <VideoStream>(new Split(2))); var splitAudio = command.Take(1) .Filter(Filterchain.FilterTo <AudioStream>(new ASplit(2))); //map the first audio and video stream to the output command.Select(splitVideo.Take(0), splitAudio.Take(0)) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); command.Select(splitVideo.Take(1), splitAudio.Take(1)) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\bar.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); //render the output factory.Render(); }
public void Command_FilterchainManager_Verify() { var command = CommandHelper.CreateCommand(); command.AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetVideoFile()); var streamId1 = command.StreamIdentifier(0); var streamId2 = command.StreamIdentifier(1); var streamId3 = command.StreamIdentifier(2); var streamId4 = command.StreamIdentifier(3); var filterchain = Filterchain.FilterTo <VideoStream>(new Trim(1, 2, VideoUnitType.Seconds)); var filterchain2 = Filterchain.FilterTo <AudioStream>(new AEvalSrc()); Assert.Throws <ArgumentNullException>(() => command.FilterchainManager.Add(null)); Assert.Throws <InvalidOperationException>(() => command.FilterchainManager.Add(filterchain, null)); Assert.Throws <ArgumentNullException>(() => command.FilterchainManager.AddToEach(null)); Assert.Throws <ArgumentException>(() => command.FilterchainManager.AddToEach(filterchain, null)); Assert.DoesNotThrow(() => command.FilterchainManager.Add(filterchain2, null)); Assert.DoesNotThrow(() => command.FilterchainManager.Add(filterchain, streamId1)); Assert.DoesNotThrow(() => command.FilterchainManager.AddToEach(filterchain, streamId2, streamId3, streamId4)); Assert.True(command.Filtergraph.Count == 5); }
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); }
public void FilterchainIVideo_Add_Restriction() { var filterchain = Filterchain.FilterTo <VideoStream>(); Assert.DoesNotThrow(() => filterchain.Filters.Add(new Concat())); Assert.Throws <ForStreamInvalidException>(() => filterchain.Filters.Add(new AMix())); }
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); }
public void FilterchainIAudio_Add_Restriction() { var filterchain = Filterchain.FilterTo <AudioStream>(); filterchain.Filters.Add(new Concat()); Assert.Throws <ForStreamInvalidException>(() => filterchain.Filters.Add(new Fade())); }
public void Filterchain_Add_Duplicate() { var filterchain = Filterchain.FilterTo <VideoStream>(); filterchain.Filters.Add(new Overlay()); Assert.Throws <InvalidOperationException>(() => filterchain.Filters.Add(new Overlay())); }
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(); //create a command adding a two audio and video files var command = factory.CreateOutputCommand() .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetVideoFile()) .AddInput(Assets.Utilities.GetAudioFile()) .AddInput(Assets.Utilities.GetAudioFile()); //select the first two video streams and run concat filter var videoConcat = command.Select(command.Take(0), command.Take(1)) .Filter(Filterchain.FilterTo <VideoStream>(new Filters.Concat())); //select the first two audio streams and run concat filter var audioConcat = command.Select(command.Take(2), command.Take(3)) .Filter(Filterchain.FilterTo <VideoStream>(new Filters.Concat(1, 0))); command.Select(audioConcat, videoConcat) .MapTo <Mp4>(@"c:\source\ffmpeg\bin\temp\foo.mp4", SettingsCollection.ForOutput(new OverwriteOutput())); //render the output factory.Render(); }
public static Filtergraph FilterTo <TStreamType>(this Filtergraph filtergraph, int count, params IFilter[] filters) where TStreamType : class, IStream, new() { var filterchain = Filterchain.FilterTo <TStreamType>(count, filters); return(filtergraph.Add(filterchain)); }
public void FilterchainIVideo_RemoveAll() { var filterchain = Filterchain.FilterTo <VideoStream>( new Fade(), new ColorBalance()); Assert.True(filterchain.Filters.Count == 2); filterchain.Filters.RemoveAll(filter => true); Assert.True(filterchain.Filters.Count == 0); }
public void FilterchainIVideo_RemoveType() { var filterchain = Filterchain.FilterTo <VideoStream>( new Fade(), new ColorBalance()); Assert.True(filterchain.Filters.Contains <Fade>()); filterchain.Filters.Remove <Fade>(); Assert.False(filterchain.Filters.Contains <Fade>()); }
public void Filtergraph_Add() { var filtergraph = Filtergraph.Create(CommandHelper.CreateCommand()); var filterchain1 = Filterchain.FilterTo <AudioStream>(); var filterchain2 = Filterchain.FilterTo <VideoStream>(); filtergraph.Add(filterchain1); Assert.True(filtergraph.Count == 1); filtergraph.Add(filterchain2); Assert.True(filtergraph.Count == 2); }
public void Command_FilterWithNoStream() { var command = CommandHelper.CreateCommand(); var filterchain = Filterchain.FilterTo <AudioStream>(new AEvalSrc { Expression = "0" }); CommandStage stage = null; Assert.DoesNotThrow(() => stage = command.Filter(filterchain)); Assert.True(stage.StreamIdentifiers.Count == 1); }
public override List <StreamIdentifier> SetupTemplate(FFmpegCommand command, List <StreamIdentifier> streamIdList) { if (streamIdList.Count != 1) { throw new InvalidOperationException("Crossfade Concatenate requires two input video streams."); } //trim == // - trim filter // - reset PTS filter var result = command.Select(streamIdList) .Filter(Filterchain.FilterTo <VideoStream>(TrimFilter, new SetPts(SetPtsExpressionType.ResetTimestamp))); return(result.StreamIdentifiers); }
public void CommandFilterchainManager_Verify() { var factory = CommandFactory.Create(); var command = factory.CreateOutputCommand() .WithInput <VideoStream>(Assets.Utilities.GetVideoFile()) .WithInput <VideoStream>(Assets.Utilities.GetVideoFile()); var commandFilterchainManager = FiltergraphManager.Create(command.Command); var filterchain = Filterchain.FilterTo <VideoStream>(new Fps()); var filterchain2 = Filterchain.FilterTo <VideoStream>(new Concat()); var streamIds = new List <StreamIdentifier>(); Assert.DoesNotThrow(() => streamIds = commandFilterchainManager.AddToEach(filterchain, command.StreamIdentifiers.ToArray())); Assert.True(streamIds.Count == 2); Assert.DoesNotThrow(() => streamIds = commandFilterchainManager.Add(filterchain2, streamIds.ToArray())); Assert.True(streamIds.Count == 1); }
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(); //create a command adding a two audio files factory.CreateOutputCommand() .WithInput <AudioStream>(Assets.Utilities.GetAudioFile()) .WithInput <AudioStream>(Assets.Utilities.GetAudioFile()) .Filter(Filterchain.FilterTo <AudioStream>(new Filters.Concat(1, 0))) .MapTo <M4A>(@"c:\source\ffmpeg\bin\temp\foo.m4a", SettingsCollection.ForOutput(new OverwriteOutput())); //render the output factory.Render(); }
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); }