public static MetadataInfoTreeContainer GetMetadataInfo(FFmpegCommand command, StreamIdentifier streamId) { //first validate that the streamId does in fact belong to the command. if (!CommandHelperUtility.ReceiptBelongsToCommand(command, streamId)) { throw new ArgumentException("The provided streamId is not part of the provided ffmpeg command.", "streamId"); } var resourceIndex = CommandHelperUtility.IndexOfResource(command, streamId); if (resourceIndex > -1) { return ResourceMetadataInfo(command, resourceIndex); } var filterchainIndex = CommandHelperUtility.IndexOfFilterchain(command, streamId); if (filterchainIndex > -1) { return FilterchainMetadataInfo(command, filterchainIndex); } var outputIndex = CommandHelperUtility.IndexOfOutput(command, streamId); if (outputIndex > -1) { return OutputMetadataInfo(command, outputIndex); } return null; }
public static IStream StreamFromStreamIdentifier(FFmpegCommand command, StreamIdentifier streamId) { var commandInput = CommandInputFromStreamIdentifier(command, streamId); if (commandInput != null) { return(commandInput.Resource.Streams.FirstOrDefault(si => si.Map == streamId.Map)); } var commandOutput = CommandOutputFromStreamIdentifier(command, streamId); if (commandOutput != null) { return(commandOutput.Resource.Streams.FirstOrDefault(si => si.Map == streamId.Map)); } var filterchain = FilterchainFromStreamIdentifier(command, streamId); if (filterchain != null) { var filterchainOutput = filterchain.OutputList.First(si => si.Stream.Map == streamId.Map); return(filterchainOutput.Stream); } throw new StreamNotFoundException(); }
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.VideoMetadata.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; }
private void WriteFilterchain(FFmpegCommand command, Filterchain filterchain) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } WriteFilterchainIn(command, filterchain); var shouldIncludeDelimitor = false; filterchain.Filters.List.ForEach(filter => { if (shouldIncludeDelimitor) { _builderBase.Append(","); } else { _builderBase.Append(" "); shouldIncludeDelimitor = true; } filter.Setup(command, filterchain); WriteFilter(filter); }); WriteFilterchainOut(filterchain); }
private void WriteFilterchain(FFmpegCommand command, Filterchain filterchain) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } var context = FilterBindingContext.Create(filterchain.InputCount, filterchain.OutputCount); WriteFilterchainIn(command, filterchain); var shouldIncludeDelimitor = false; filterchain.Filters.ToList().ForEach(filter => { if (shouldIncludeDelimitor) { BuilderBase.Append(","); } else { BuilderBase.Append(" "); shouldIncludeDelimitor = true; } WriteFilter(filter, context); }); WriteFilterchainOut(filterchain); }
private void WriteFiltergraph(FFmpegCommand command, Filtergraph filtergraph) { if (filtergraph == null) { throw new ArgumentNullException("filtergraph"); } var shouldIncludeDelimitor = false; filtergraph.FilterchainList.ForEach(filterchain => { if (shouldIncludeDelimitor) { BuilderBase.Append(";"); } else { BuilderBase.Append(" -filter_complex \""); shouldIncludeDelimitor = true; } WriteFilterchain(command, filterchain); }); if (shouldIncludeDelimitor) { BuilderBase.Append("\""); } }
private void WriteFilterchain(FFmpegCommand command, Filterchain filterchain) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } var context = FilterBindingContext.Create(filterchain.InputCount, filterchain.OutputCount); WriteFilterchainIn(command, filterchain); var shouldIncludeDelimitor = false; filterchain.Filters.ToList().ForEach(filter => { if (shouldIncludeDelimitor) { BuilderBase.Append(","); } else { BuilderBase.Append(" "); shouldIncludeDelimitor = true; } WriteFilter(filter, context); }); WriteFilterchainOut(filterchain); }
public static Filtergraph Create(FFmpegCommand command) { return new Filtergraph { Owner = command }; }
private void WriteFilterchain(FFmpegCommand command, Filterchain filterchain) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } WriteFilterchainIn(command, filterchain); var shouldIncludeDelimitor = false; filterchain.Filters.List.ForEach(filter => { if (shouldIncludeDelimitor) { _builderBase.Append(","); } else { _builderBase.Append(" "); shouldIncludeDelimitor = true; } filter.Setup(command, filterchain); WriteFilter(filter); }); WriteFilterchainOut(filterchain); }
public static MetadataInfoTreeGroup Create(FFmpegCommand command, CommandOutput commandOutput) { var metadataInfoTreeGroup = new MetadataInfoTreeGroup(commandOutput.Settings); metadataInfoTreeGroup.Fill(command, commandOutput); return metadataInfoTreeGroup; }
public static MetadataInfoTreeGroup Create(FFmpegCommand command, Filterchain filterchain) { var metadataInfoTreeGroup = new MetadataInfoTreeGroup(filterchain); metadataInfoTreeGroup.Fill(command, filterchain); return metadataInfoTreeGroup; }
public static CommandOutput CommandOutputFromStreamIdentifier(FFmpegCommand command, StreamIdentifier streamId) { if (streamId == null) { throw new ArgumentNullException("streamId"); } return(command.Objects.Outputs.FirstOrDefault(i => i.GetStreamIdentifiers().Any(si => si.Map == streamId.Map))); }
internal static MetadataInfoTreeContainer ResourceMetadataInfo(FFmpegCommand command, int index) { if (command.Inputs.Count <= index) { return null; } return ExecuteStreamCalculator(MetadataInfoStreamCalculator.Create(command.Inputs[index])); }
internal static MetadataInfoTreeContainer FilterchainMetadataInfo(FFmpegCommand command, int index) { if (command.Filtergraph.Count <= index) { return null; } return ExecuteStreamCalculator(MetadataInfoStreamCalculator.Create(command, command.Filtergraph[index])); }
public static Filterchain FilterchainFromStreamIdentifier(FFmpegCommand command, StreamIdentifier streamId) { if (streamId == null) { throw new ArgumentNullException("streamId"); } return(command.Objects.Filtergraph.FilterchainList.FirstOrDefault(f => f.GetStreamIdentifiers().Any(r => r.Equals(streamId)))); }
public void WriteCommand(FFmpegCommand command) { command.Objects.Inputs.ForEach(WriteResource); WriteFiltergraph(command, command.Objects.Filtergraph); command.Objects.Outputs.ForEach(WriteOutput); WriteFinish(); }
public void WriteCommand(FFmpegCommand command) { command.Objects.Inputs.ForEach(WriteResource); WriteFiltergraph(command, command.Objects.Filtergraph); command.Objects.Outputs.ForEach(WriteOutput); WriteFinish(); }
public static int IndexOfResource(FFmpegCommand command, StreamIdentifier streamId) { var matchingResource = CommandInputFromStreamIdentifier(command, streamId); if (matchingResource == null) { return(-1); } return(command.Inputs.IndexOf(matchingResource)); }
public static int IndexOfOutput(FFmpegCommand command, StreamIdentifier streamId) { var matchingOutput = CommandOutputFromStreamIdentifier(command, streamId); if (matchingOutput == null) { return(-1); } return(command.Outputs.IndexOf(matchingOutput)); }
public static int IndexOfFilterchain(FFmpegCommand command, StreamIdentifier streamId) { var matchingFilterchain = FilterchainFromStreamIdentifier(command, streamId); if (matchingFilterchain == null) { return(-1); } return(command.Filtergraph.IndexOf(matchingFilterchain)); }
/// <summary> /// Method, called during [Render] to bring forward all the necessary resources, necessary action for maximum abstraction from the user. /// </summary> /// <param name="command">The command chain the current filter belongs to.</param> /// <param name="filterchain">The filterchain that the filter belongs to</param> public void Setup(FFmpegCommand command, Filterchain filterchain) { InputCount = filterchain.Resources.Count; if (InputCount == 0) { throw new InvalidOperationException("Cannot setup filter with a resource count of zero."); } if (InputCount > MaxInputs) { throw new InvalidOperationException("The filter has exceeded the maximum allowed number of inputs."); } }
public static CommandOutput SetupCommandOutput <TOutputType>(FFmpegCommand command, SettingsCollection settings, string fileName) where TOutputType : class, IContainer, new() { var settingsCopy = settings.Copy(); var commandOutput = CommandOutput.Create(Resource.CreateOutput <TOutputType>(), settingsCopy); commandOutput.Resource.Streams.AddRange(command.Inputs.SelectMany(i => i.Resource.Streams.Select(s => s.Copy()))); if (!string.IsNullOrWhiteSpace(fileName)) { commandOutput.Resource.Name = fileName; } return(commandOutput); }
public static bool ValidateFilters(FFmpegCommand command, Filterchain filterchain, List<StreamIdentifier> streamIds) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } return filterchain.Filters.List.TrueForAll(f => { if (!(f is IFilterValidator)) { return true; } return (f as IFilterValidator).Validate(command, filterchain, streamIds); }); }
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; }
private void Fill(FFmpegCommand command, Filterchain filterchain) { filterchain.ReceiptList.ForEach(streamId => { var resourceIndexOf = CommandHelper.IndexOfResource(command, streamId); if (resourceIndexOf > -1) { DependecyTree.Add(MetadataInfoTreeSource.Create(command.Inputs[resourceIndexOf])); } var filterchainIndexOf = CommandHelper.IndexOfFilterchain(command, streamId); if (filterchainIndexOf > -1) { DependecyTree.Add(Create(command, command.Filtergraph[filterchainIndexOf])); } }); }
public static void ProcessFilters(FFmpegCommand command, Filterchain filterchain) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } filterchain.Filters.List.ForEach(filter => { if (!(filter is IFilterProcessor)) { return; } (filter as IFilterProcessor).PrepCommands(command, filterchain); }); }
private void WriteFilterchainIn(FFmpegCommand command, Filterchain filterchain) { filterchain.ReceiptList.ForEach(streamId => { BuilderBase.Append(" "); var indexOfResource = command.Objects.Inputs.FindIndex(inputs => inputs.GetStreamIdentifiers().Any(s => s.Map == streamId.Map)); if (indexOfResource >= 0) { var commandResource = command.Objects.Inputs[indexOfResource]; var commandStream = commandResource.Resource.Streams.First(s => s.Map == streamId.Map); BuilderBase.Append(FormattingUtility.Map(commandStream, indexOfResource)); } else { BuilderBase.Append(FormattingUtility.Map(streamId.Map)); } }); }
private void WriteFilterchainIn(FFmpegCommand command, Filterchain filterchain) { filterchain.ReceiptList.ForEach(streamId => { BuilderBase.Append(" "); var indexOfResource = command.Objects.Inputs.FindIndex(inputs => inputs.GetStreamIdentifiers().Any(s => s.Map == streamId.Map)); if (indexOfResource >= 0) { var commandResource = command.Objects.Inputs[indexOfResource]; var commandStream = commandResource.Resource.Streams.First(s => s.Map == streamId.Map); BuilderBase.Append(FormattingUtility.Map(commandStream, indexOfResource)); } else { BuilderBase.Append(FormattingUtility.Map(streamId.Map)); } }); }
private void Fill(FFmpegCommand command, CommandOutput commandOutput) { //find the command output map setting, if the command output has map settings //then they make up its dependecy tree. var allSettingMaps = commandOutput.Settings.OfType<Map>(); if (allSettingMaps.Any()) { var streamIdListFromMaps = allSettingMaps.Select(map => StreamIdentifier.Create(command.Owner.Id, command.Id, map.Stream)).ToList(); Fill(command, streamIdListFromMaps); return; } //if the command output does not contain map settings then the dependency tree //is made up of all the input streams. command.Objects.Inputs.ForEach(commandResource => DependecyTree.Add(MetadataInfoTreeSource.Create(commandResource))); }
private CommandFactory Add(FFmpegCommand command, bool export) { if (command == null) { throw new ArgumentNullException("command"); } if (Contains(command)) { throw new ArgumentException("Command Factory already contains this command.", "command"); } if (command.Owner.Id != Id) { throw new ArgumentException("Command was not created as a child of this factory.", "command"); } command.Objects.Outputs.ForEach(output => output.IsExported = export); CommandList.Add(command); return(this); }
public void PrepCommands(FFmpegCommand command, Filterchain filterchain) { if (filterchain.OutputList.Count == 0) { throw new InvalidOperationException("A split cannot happen without a demo output to split on."); } if (filterchain.OutputList.Count > NumberOfStreams) { throw new InvalidOperationException("A split cannot happen when the supplied filterchain has to many demo outputs."); } if (filterchain.OutputList.Count == NumberOfStreams) { return; } for (var i = filterchain.OutputList.Count; i < NumberOfStreams; i++) { filterchain.OutputList.Add(filterchain.OutputList .First() .Copy()); } }
public static MetadataInfoStreamCalculator Create(FFmpegCommand command, CommandOutput commandOutput) { var infoStreamItem = MetadataInfoTreeGroup.Create(command, commandOutput); return new MetadataInfoStreamCalculator(infoStreamItem); }
internal static CommandOutputManager Create(FFmpegCommand owner) { return new CommandOutputManager(owner); }
public static CommandObjects Create(FFmpegCommand owner) { return new CommandObjects(owner); }
internal CommandStage(FFmpegCommand stageCommand) { Command = stageCommand; StreamIdentifiers = new List<StreamIdentifier>(); }
internal static CommandStage Create(FFmpegCommand stageCommand) { return(new CommandStage(stageCommand)); }
public override List<StreamIdentifier> SetupTemplate(FFmpegCommand command, List<StreamIdentifier> streamIdList) { if (streamIdList.Count > 1) { throw new InvalidOperationException("Pulsate requires one input video stream."); } if (FrameRate <=0) { throw new InvalidOperationException("Pulsate requires frame rate > 0."); } var streamFrom = streamIdList[0]; //output == // - (zoom-in, zoom-out) int zoomFrameDuration = Convert.ToInt32(Duration.TotalSeconds * 0.5 * FrameRate); // it's a half for zoom-in and another half for zoom-out //var zoomFrameDuration = 100; var streamSplit = command.Select(streamFrom) //.WithInput<VideoStream>(BackgroundImagePath,SettingsCollection.ForInput(new DurationInput(Duration))) //.Filter(new TrimVideo(null, Duration.TotalSeconds * 0.5, VideoUnitType.Seconds)) //.Filter(Filterchain.FilterTo<VideoStream>(new Fps(FrameRate),new Scale(Convert.ToInt32(meta.Width * 1.3), Convert.ToInt32(meta.Height * 1.3)))) .Filter(new TrimVideo(null, Duration.TotalSeconds * 0.5, VideoUnitType.Seconds)) .Filter(Filterchain.FilterTo<VideoStream>(new Split(2))); var zoomIn = streamSplit.Take(0) .Filter(Filterchain.FilterTo<VideoStream>(new ZoomPan("'min(zoom+0.1,1.2)'", zoomFrameDuration, "'iw/2-(iw/zoom/2)'", "'ih/2-(ih/zoom/2)'"))) ; var zoomOut = streamSplit.Take(1) .Filter(Filterchain.FilterTo<VideoStream>(new ZoomPan("'if(lte(zoom,1.0),1.2,max(1.001,zoom-0.1))'", zoomFrameDuration, "'iw/2-(iw/zoom/2)'", "'ih/2-(ih/zoom/2)'"))) ; var streamFromMetadata = MetadataHelpers.GetMetadataInfo(command, streamFrom); var meta = streamFromMetadata.VideoStream.VideoMetadata; var zoom = command .Select(zoomIn.StreamIdentifiers) .Select(zoomOut.StreamIdentifiers) .Filter(Filterchain.FilterTo<VideoStream>(new Concat())) .Filter(Filterchain.FilterTo<VideoStream>(new Scale(meta.Width, meta.Height))) .Filter(new TrimVideo(null, Duration.TotalSeconds, VideoUnitType.Seconds)) ; //var nsrc = new Color(); ////nsrc.Duration = Duration; //nsrc.FrameRate = FrameRate; //nsrc.Size = new System.Drawing.Size(Convert.ToInt32(meta.Width * 1.25), Convert.ToInt32(meta.Height * 1.25)); var overlay = new OverlayEx(); overlay.X = "W/2-w/2"; overlay.Y = "H/2-h/2"; overlay.Format = OverlayVideoFormatType.Rgb; var result = command //.WithInput<VideoStream>(BackgroundImagePath,SettingsCollection.ForInput(new DurationInput(Duration))) //.Filter(new TrimVideo(null, Duration.TotalSeconds * 0.5, VideoUnitType.Seconds)) //.Filter(Filterchain.FilterTo<VideoStream>(new Fps(FrameRate),new Scale(Convert.ToInt32(meta.Width * 1.3), Convert.ToInt32(meta.Height * 1.3)))) .Select(zoom.StreamIdentifiers) //.Filter(Filterchain.FilterTo<VideoStream>(overlay)) ; return result.StreamIdentifiers; }
public static MetadataInfoStreamCalculator Create(FFmpegCommand command, Filterchain filterchain) { var infoStreamItem = MetadataInfoTreeGroup.Create(command, filterchain); return new MetadataInfoStreamCalculator(infoStreamItem); }
private CommandObjects(FFmpegCommand owner) { Outputs = new List <CommandOutput>(); Inputs = new List <CommandInput>(); Filtergraph = Filtergraph.Create(owner); }
private CommandObjects(FFmpegCommand owner) { Outputs = new List<CommandOutput>(); Inputs = new List<CommandInput>(); Filtergraph = Filtergraph.Create(owner); }
internal static CommandOutputManager Create(FFmpegCommand owner) { return(new CommandOutputManager(owner)); }
public static bool ReceiptBelongsToCommand(FFmpegCommand command, StreamIdentifier streamId) { return(command.Owner.Id == streamId.FactoryId && command.Id == streamId.CommandId); }
internal static FiltergraphManager Create(FFmpegCommand owner) { return new FiltergraphManager(owner); }
private CommandOutputManager(FFmpegCommand owner) { Owner = owner; }
private FiltergraphManager(FFmpegCommand owner) { Owner = owner; }
private void WriteFiltergraph(FFmpegCommand command, Filtergraph filtergraph) { if (filtergraph == null) { throw new ArgumentNullException("filtergraph"); } var shouldIncludeDelimitor = false; filtergraph.FilterchainList.ForEach(filterchain => { if (shouldIncludeDelimitor) { BuilderBase.Append(";"); } else { BuilderBase.Append(" -filter_complex \""); shouldIncludeDelimitor = true; } WriteFilterchain(command, filterchain); }); if (shouldIncludeDelimitor) { BuilderBase.Append("\""); } }
/// <summary> /// Returns a boolean indicating if the command already exists in the factory /// </summary> public bool Contains(FFmpegCommand command) { return(CommandList.OfType <FFmpegCommand>() .Any(c => c.Id == command.Id)); }
internal void EmptyOperation(CommandFactory factory, FFmpegCommand command, bool success) { }
/// <summary> /// Adds a new command and marks the output to be exported. /// </summary> public CommandFactory AddCommandAsResource(FFmpegCommand command) { command.Objects.Outputs.ForEach(output => output.Resource.Path = ResourceManagement.CommandConfiguration.TempPath); return(Add(command, false)); }
private CommandOutputManager(FFmpegCommand owner) { Owner = owner; }
public static CommandObjects Create(FFmpegCommand owner) { return(new CommandObjects(owner)); }
internal CommandStage(FFmpegCommand stageCommand) { Command = stageCommand; StreamIdentifiers = new List <StreamIdentifier>(); }
private void Fill(FFmpegCommand command, List<StreamIdentifier> streamIdList) { streamIdList.ForEach(streamId => { var resourceIndexOf = CommandHelper.IndexOfResource(command, streamId); if (resourceIndexOf > -1) { DependecyTree.Add(MetadataInfoTreeSource.Create(command.Inputs[resourceIndexOf])); return; } var filterchainIndexOf = CommandHelper.IndexOfFilterchain(command, streamId); if (filterchainIndexOf > -1) { DependecyTree.Add(Create(command, command.Filtergraph[filterchainIndexOf])); } }); }