示例#1
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var FFMPEGPath      = ffmpegPath.Get(context);
            var FFMPEGDirectory = FFMPEGPath.Substring(0, FFMPEGPath.LastIndexOf('\\'));

            FFMPEGPath = '"' + FFMPEGPath + '"';
            var inputFile       = InputFile.Get(context);
            var outputFolder    = OutputFolder.Get(context);
            var outputContainer = OutputContainer.Get(context);
            var command         = Command.Get(context);
            var fontFile        = FontFile.Get(context);
            var debuggingMode   = DebuggingMode.Get(context);
            var text            = Text.Get(context);


            string tempPath     = Path.GetTempPath();
            var    fontFileName = fontFile.Substring(fontFile.LastIndexOf(@"\"));

            fontFileName = fontFileName.Replace(@"\", "");

            String fontFilePath = Path.Combine(tempPath, fontFileName);

            if (!System.IO.File.Exists(fontFilePath))
            {
                System.IO.File.Copy(fontFile, fontFilePath, true);
            }

            var startInfo = new ProcessStartInfo(FFMPEGPath);

            startInfo.WindowStyle      = ProcessWindowStyle.Normal;
            startInfo.WorkingDirectory = tempPath;

            string inputContainer = inputFile.Substring(inputFile.LastIndexOf('.'));

            if (outputContainer == "")
            {
                outputContainer = inputContainer;
            }

            string fileNameWithoutExtensions = inputFile.Replace(inputContainer, "");
            var    fileName = fileNameWithoutExtensions.Substring(fileNameWithoutExtensions.LastIndexOf(@"\"));

            fileName = fileName.Replace(@"\", "");

            var uniqueId = (DateTime.Now.Ticks - new DateTime(2016, 1, 1).Ticks).ToString("x");

            startInfo.Arguments = "-i " + '"' + inputFile + '"' + " " + "-vf drawtext=enable='between(t,2,8)':\"fontfile = " + fontFileName + '"' + ":text=\"" + text + "\":fontcolor=white:fontsize=124:x=(w-text_w)/2:y=(h-text_h)/2 " + command + " " + '"' + outputFolder + @"\" + uniqueId + "." + outputContainer + '"';

            if (debuggingMode)
            {
                var processn = new Process();
                processn.StartInfo           = startInfo;
                processn.EnableRaisingEvents = true;
                processn.StartInfo.FileName  = "CMD.EXE";
                processn.StartInfo.Arguments = "/K " + '"' + @FFMPEGPath + " " + startInfo.Arguments + '"';
                processn.Start();
                processn.WaitForExit();
            }
            else
            {
                var processn = Process.Start(startInfo);
                processn.EnableRaisingEvents = true;

                processn.WaitForExit();
            }

            // Outputs
            return((ctx) => {
            });
        }