public static IStackingEnvironment ConfigureInputMode(this IStackingEnvironment env, CommonOptions commonOptions)
        {
            if (!string.IsNullOrWhiteSpace(commonOptions.InputVideoFile))
            {
                env.Logger?.WriteLine("Using Video Input - you might occur some bugs.", Verbosity.Warning);

                env.InputMode = new FfmpegVideoReader(new FfmpegVideoReaderArguments
                {
                    InputFile    = commonOptions.InputVideoFile,
                    PathToFfmpeg = commonOptions.FfmpegLocation,
                    CustomArgs   = commonOptions.InputVideoArguments
                }, env.Factory, env.Logger);
                return(env);
            }
            if (commonOptions.UseInputPipe)
            {
                env.Logger?.WriteLine("Currently only BGR24 input supported", Verbosity.Warning);
                var inputSize = commonOptions.InputSize;
                if (string.IsNullOrWhiteSpace(inputSize))
                {
                    env.ThrowMe = true;
                    env.Logger?.WriteLine($"InputSize is not defined but necessary for using inputpipes", Verbosity.Error);
                }
                var wh = Regex.Split(inputSize ?? string.Empty, "[^0-9]");

                if (int.TryParse(wh[0], out int width) && int.TryParse(wh[1], out int height))
                {
                    env.InputMode = new ImageStreamReader <MutableByteImage>(
                        env.Logger,
                        env.Factory,
                        Console.OpenStandardOutput(width * height * 3),
                        width,
                        height,
                        PixelFormat.Format24bppRgb);
                }
                else
                {
                    env.Logger?.WriteLine($"InputSize is not parseable {commonOptions.InputSize}", Verbosity.Error);
                    env.ThrowMe = true;
                }


                return(env);
            }
            if (commonOptions.InputFiles != null && commonOptions.InputFiles.Any())
            {
                env.InputMode = new ImageMutliFileOrderedReader <MutableByteImage>(
                    env.Logger,
                    env.Factory,
                    new ReaderOptions {
                    Files = commonOptions.InputFiles.ToArray()
                });

                return(env);
            }
            if (!string.IsNullOrWhiteSpace(commonOptions.InputFolder))
            {
                env.Logger?.WriteLine("Currently only *.jpg input supported", Verbosity.Warning);
                if (!Directory.Exists(commonOptions.InputFolder))
                {
                    env.Logger?.WriteLine($"InputFolder does not exist {commonOptions.InputFolder}", Verbosity.Error);
                    env.ThrowMe = true;
                }
                else
                {
                    env.InputMode = new ImageMutliFileOrderedReader <MutableByteImage>(
                        env.Logger,
                        env.Factory,
                        new ReaderOptions
                    {
                        FolderName = commonOptions.InputFolder,
                        Filter     = commonOptions.InputFilter
                    });
                }
                return(env);
            }

            env.Logger?.WriteLine("No Input Mode defined", Verbosity.Error);
            env.ThrowMe = true;
            return(env);
        }
        public static IStackingEnvironment ConfigureCommonEnvironment(this IStackingEnvironment env, CommonOptions info)
        {
            env.Logger  = CreateLogger(info);
            env.Factory = new MutableByteImageFactory(env.Logger);

            env.ConfigureFilters(info.Filters);

            env.Logger?.WriteLine(info.ToString().Replace(",", Environment.NewLine), Verbosity.Info);

            env.ConfigureInputMode(info);

            env.ConfigureOuptutMode(info);

            return(env);
        }
        public static IStackingEnvironment ConfigureOuptutMode(this IStackingEnvironment env, CommonOptions commonOptions)
        {
            if (commonOptions.UseOutputPipe)
            {
                env.OutputMode = new ImageStreamWriter <MutableByteImage>(env.Logger, env.Factory, Console.OpenStandardOutput());
                return(env);
            }

            if (!string.IsNullOrWhiteSpace(commonOptions.OutputVideoFile))
            {
                if (!string.IsNullOrWhiteSpace(commonOptions.OutputFolder))
                {
                    env.Logger?.WriteLine("OutputFolder Option set, but is being ignored when using Video as output", Verbosity.Warning, true);
                }

                env.OutputMode = new FfmpegVideoWriter(
                    new FfmpegVideoWriterArguments
                {
                    OutputFile   = commonOptions.OutputVideoFile,
                    CustomArgs   = commonOptions.OutputVideoOptions,
                    PathToFfmpeg = commonOptions.FfmpegLocation
                },
                    env.Logger);
                return(env);
            }

            if (!string.IsNullOrWhiteSpace(commonOptions.OutputFolder))
            {
                env.OutputMode = new ImageFileWriter <MutableByteImage>(commonOptions.OutputFilePrefix, commonOptions.OutputFolder, env.Factory);
                return(env);
            }

            env.Logger?.WriteLine("No Output Mode defined", Verbosity.Error);
            env.Logger?.WriteLine("Consider specifying --UseOutputPipe or --OutputFolder", Verbosity.Error);
            env.Logger?.WriteLine("", Verbosity.Error);
            env.ThrowMe = true;
            return(env);
        }