public static IStackingEnvironment ConfigureFilters(this IStackingEnvironment environment, IEnumerable <string> optionArgs) { environment.Filters = new List <IFilter <MutableByteImage> >(); if (optionArgs == null || !optionArgs.Any()) { environment.ThrowMe = true; return(environment); } var filteredOptionArgs = string.Join(' ', optionArgs) .Replace("--filters=", "") .Replace("--filters", "") .Split(" ", StringSplitOptions.RemoveEmptyEntries) .SelectMany(x => x.Split(',')).ToArray(); var parameterGroups = new List <List <string> >(); var previousList = new List <string> { filteredOptionArgs.First() }; foreach (var item in filteredOptionArgs.Skip(1)) { if (item.Contains("=")) { previousList.Add("--" + item.Trim(',')); continue; } parameterGroups.Add(previousList); previousList = new List <string> { item.Trim(',') }; } parameterGroups.Add(previousList); var factory = new MutableByteImageFilterFactory(true); foreach (var group in parameterGroups) { var result = Parser.Default .ParseArguments <MaxFilterOptions, MinFilterOptions, AttackDecayFilterOptions>(group) .WithParsed <MaxFilterOptions>(options => environment.Filters.Add(factory.CreateMaxFilter(options))) .WithParsed <MinFilterOptions>(options => environment.Filters.Add(factory.CreateMinFilter(options))) .WithParsed <AttackDecayFilterOptions>(options => environment.Filters.Add(factory.CreateAttackDecayFilter(options))) .WithNotParsed(e => Console.Write(e.ToString())); } return(environment); }
public async static Task Main(string[] args) { Console.WriteLine(args[0]); var filterFactory = new MutableByteImageFilterFactory(true); var filters = new List <IFilter <MutableByteImage> > { filterFactory.CreateMaxFilter(new MaxOptions { Name = "max", }), filterFactory.CreateAttackDecayFilter(new AttackOptions { Attack = 1f, Decay = 0.2f, Name = "attackHF", }), filterFactory.CreateAttackDecayFilter(new AttackOptions { Attack = 1f, Decay = 0.01f, Name = "attackHS", }), filterFactory.CreateAttackDecayFilter(new AttackOptions { Attack = 0.2f, Decay = 1f, Name = "attackLF", }), filterFactory.CreateAttackDecayFilter(new AttackOptions { Attack = 0.01f, Decay = 1f, Name = "attackLS", }), filterFactory.CreateMinFilter(new MinOptions { Name = "min", }), }; var str = args[0]; foreach (var filter in filters) { using var logger = new Logger(Console.Out); BoundedQueueFactory.Logger = logger; Console.WriteLine(str); var filename = Path.GetFileNameWithoutExtension(str); var factory = new MutableByteImageFactory(logger); /* var reader = new FfmpegVideoReader(new FfmpegVideoReaderArguments * { * InputFile = str * }, factory, logger);*/ var directoryName = (File.Exists(args[0])) ? Path.GetDirectoryName(args[0]) : args[0]; var commonExtension = Directory.GetFiles(directoryName) .Select(x => Path.GetExtension(x)) .GroupBy(x => x) .OrderBy(x => x.Count()).First(); var reader = new ImageMutliFileOrderedReader <MutableByteImage>(logger, factory, new ReaderOptions { FolderName = args[0], Filter = $"*{commonExtension.Key}", }); var processingStrategy = new StackProgressiveStrategy <MutableByteImage>(logger, factory); System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch(); st.Start(); //var writer = new ImageFileWriter<MutableByteImage>(filename, ".", factory); var resultingFilename = /* @"H:\timelapses\stackedVideo\" +*/ Path.GetRandomFileName() + filename + "-" + filter.Name + ".mp4"; if (File.Exists(resultingFilename)) { st.Stop(); Console.WriteLine($"Skipped {resultingFilename}"); continue; } var writer = new FfmpegVideoWriter(new FfmpegVideoWriterArguments { Framerate = 60, OutputFile = resultingFilename }, logger); await processingStrategy.Process(reader, new List <IFilter <MutableByteImage> > { filter }, writer); st.Stop(); Console.WriteLine($"it took {st.ElapsedMilliseconds}ms"); } }
private static (List <IFilter <MutableByteImage> > filters, bool throwMe) ParseFilterParameters(IEnumerable <string> optionArgs) { if (optionArgs.Count() == 0) { return(new List <IFilter <MutableByteImage> >(), true); } var parameterGroups = new List <List <string> >(); var previousList = new List <string> { optionArgs.First() }; foreach (var item in optionArgs.Skip(1)) { if (item.Contains("=")) { previousList.Add("--" + item.Trim(',')); continue; } parameterGroups.Add(previousList); previousList = new List <string> { item }; } parameterGroups.Add(previousList); var filters = new List <IFilter <MutableByteImage> >(); var factory = new MutableByteImageFilterFactory(true); foreach (var group in parameterGroups) { var result = Parser.Default .ParseArguments <MaxFilterOptions, MinFilterOptions, AttackDecayFilterOptions>(group) .WithParsed <MaxFilterOptions>(options => filters.Add(factory.CreateMaxFilter(options))) .WithParsed <MinFilterOptions>(options => filters.Add(factory.CreateMinFilter(options))) .WithParsed <AttackDecayFilterOptions>(options => filters.Add(factory.CreateAttackDecayFilter(options))) .WithNotParsed(e => Console.Write(e.ToString())); } return(filters, false); }