Exemple #1
0
        public void Cut(FFMpegCutOptions cutOptions, bool muteProgress = false)
        {
            EnsureFileDoesNotExist(cutOptions.OutputFile);
            var cutCommandBuilder = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                                    .StartFrom(cutOptions.Start)
                                    .InputFrom(cutOptions.InputFile)
                                    .DurationIs(cutOptions.Duration)
                                    .OutputVideoCodec(cutOptions.VideoCodec)
                                    .OutputAudioCodec(cutOptions.AudioCodec);

            if (!cutOptions.SimpleMode)
            {
                cutCommandBuilder = cutCommandBuilder.OutputScale(cutOptions.OutputSize);
            }
            cutCommandBuilder = cutCommandBuilder
                                .AppendCustom("-avoid_negative_ts 1 -max_muxing_queue_size 1000")
                                .OutputTo(cutOptions.OutputFile);
            if (!muteProgress)
            {
                cutCommandBuilder = cutCommandBuilder.WithProgressCallback(cutOptions.GlobalExportProgress.SetCurrentOperationProgress);
            }
            var command = cutCommandBuilder.WithStopSignal(this.stopSignal)
                          .WithPriority(this.ffmpegProcessPriorityClass)
                          .BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "CUT");
            if (!muteProgress)
            {
                cutOptions.GlobalExportProgress.IncreaseOperationsDone(command.ProcessId);
            }
        }
Exemple #2
0
        public void ConcatAndDrawImagesAndText(IList <string> inputFilesToConcat, IList <DrawImageTimeRecord> imagesTimeTable, List <TextTimeRecord> overlayText, Size finalScale, string outputFile, IGlobalExportProgress globalExportProgress)
        {
            EnsureFileDoesNotExist(outputFile);
            const int FontSizeFor1024Width = 30;
            var       fontSize             = finalScale.IsEmpty ? FontSizeFor1024Width : ((double)finalScale.Width / 1024) * FontSizeFor1024Width;
            var       command = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                                .ConcatDrawImagesAndText(inputFilesToConcat, imagesTimeTable, overlayText, finalScale, fontsPath, (int)fontSize)
                                .OutputVideoCodec(FFMpegCutOptions.DefaultVideoCodec)
                                .OutputPreset(PresetParameters.SuperFast)
                                .OutputAudioCodec(FFMpegCutOptions.DefaultAudioCodec)
                                .OutputTo(outputFile)
                                .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                                .WithStopSignal(this.stopSignal)
                                .WithPriority(this.ffmpegProcessPriorityClass)
                                .BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "DrawText");

            //одна операция для concat-a без постэффектов.
            var operationsCountForConcat = 1;
            var operationsCountForConcatAndDrawImagesAndText =
                Math.Max(operationsCountForConcat, Math.Max(imagesTimeTable.Count, overlayText.Count)) * 2;

            globalExportProgress.IncreaseOperationsDone(command.ProcessId, operationsCountForConcatAndDrawImagesAndText);
        }
Exemple #3
0
        public void ApplyTimeWarp(string inputFile, IList <TimeWarpRecord> timeWarps, string outputFile, IGlobalExportProgress globalExportProgress)
        {
            EnsureFileDoesNotExist(outputFile);
            var cutCommandBuilder = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                                    .InputFrom(inputFile)
                                    .ApplyTimeWarp(timeWarps)
                                    .OutputTo(outputFile)
                                    .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                                    .WithStopSignal(this.stopSignal)
                                    .WithPriority(this.ffmpegProcessPriorityClass);
            var command = cutCommandBuilder.BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "TIME_WARP");
            globalExportProgress.IncreaseOperationsDone(command.ProcessId, 1);
        }
Exemple #4
0
        public void Concat(string outputFile, Size outputSize, string vCodec, string aCodec, IGlobalExportProgress globalExportProgress, params string[] inputFiles)
        {
            EnsureFileDoesNotExist(outputFile);
            var command = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                          .ConcatInputsFrom(inputFiles)
                          .OutputVideoCodec(vCodec)
                          .OutputPreset(PresetParameters.SuperFast)
                          .OutputAudioCodec(aCodec)
                          .OutputTo(outputFile)
                          .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                          .WithStopSignal(this.stopSignal)
                          .WithPriority(this.ffmpegProcessPriorityClass)
                          .BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "CONCAT");
            globalExportProgress.IncreaseOperationsDone(command.ProcessId);
        }
Exemple #5
0
        public void Convert(string inputFile, string outputFile, IGlobalExportProgress globalExportProgress)
        {
            EnsureFileDoesNotExist(outputFile);
            var command = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                          .AppendCustom("-fflags +genpts")
                          .InputFrom(inputFile)
                          .OutputVideoCodec("copy")
                          .OutputAudioCodec("copy -map 0")
                          .OutputTo(outputFile)
                          .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                          .WithStopSignal(this.stopSignal)
                          .WithPriority(this.ffmpegProcessPriorityClass)
                          .BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "CONVERT");
            globalExportProgress.IncreaseOperationsDone(command.ProcessId);
        }
Exemple #6
0
        public void DrawText(string inputFile, List <TextTimeRecord> overlayText, string outputFile, IGlobalExportProgress globalExportProgress)
        {
            EnsureFileDoesNotExist(outputFile);
            const int FontSize = 30;
            var       command  = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                                 .InputFrom(inputFile)
                                 .DrawText(overlayText, fontsPath, FontSize)
                                 .OutputVideoCodec(FFMpegCutOptions.DefaultVideoCodec)
                                 .OutputAudioCodec(FFMpegCutOptions.DefaultAudioCodec)
                                 .OutputTo(outputFile)
                                 .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                                 .WithStopSignal(this.stopSignal)
                                 .WithPriority(this.ffmpegProcessPriorityClass)
                                 .BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "DrawText");
            globalExportProgress.IncreaseOperationsDone(command.ProcessId);
        }
Exemple #7
0
        public void CutAndConcatAndDrawImagesAndText(IList <FFMpegCutInfo> cutInfosToConcat, IList <DrawImageTimeRecord> imagesTimeTable, List <TextTimeRecord> overlayText, Size finalScale, string outputFile, IGlobalExportProgress globalExportProgress)
        {
            EnsureFileDoesNotExist(outputFile);
            const int FontSizeFor1024Width = 30;
            var       fontSize             = finalScale.IsEmpty ? FontSizeFor1024Width : ((double)finalScale.Width / 1024) * FontSizeFor1024Width;
            var       command = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                                .CutConcatDrawImagesAndText(cutInfosToConcat, imagesTimeTable, overlayText, finalScale, fontsPath, (int)fontSize)
                                .OutputVideoCodec(FFMpegCutOptions.DefaultVideoCodec)
                                .OutputPreset(PresetParameters.SuperFast)
                                .OutputAudioCodec(FFMpegCutOptions.DefaultAudioCodec)
                                .Fix2FramesLeftError()
                                .OutputTo(outputFile)
                                .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                                .WithStopSignal(this.stopSignal)
                                .WithPriority(this.ffmpegProcessPriorityClass)
                                .BuildCommand(pathToFfMpegExe, cutInfosToConcat.Aggregate(0.0, (t, c) => t + c.EndSecond - c.StartSecond));

            this.ExecuteFFMpegCommand(command, "DrawText");

            globalExportProgress.IncreaseOperationsDone(command.ProcessId, 1);
        }
Exemple #8
0
        public void DrawImage(string inputFile, List <DrawImageTimeRecord> imagesTimeTable, string outputFile, IGlobalExportProgress globalExportProgress)
        {
            if (!imagesTimeTable.Any())
            {
                return;
            }
            EnsureFileDoesNotExist(outputFile);
            var command = new FFMpegCommandBuilder(this.temporaryFilesStorage)
                          .InputFrom(inputFile)
                          .DrawImages(imagesTimeTable)
                          .OutputVideoCodec(FFMpegCutOptions.DefaultVideoCodec)
                          .OutputAudioCodec(FFMpegCutOptions.DefaultAudioCodec)
                          .OutputTo(outputFile)
                          .WithProgressCallback(globalExportProgress.SetCurrentOperationProgress)
                          .WithStopSignal(this.stopSignal)
                          .WithPriority(this.ffmpegProcessPriorityClass)
                          .BuildCommand(pathToFfMpegExe);

            this.ExecuteFFMpegCommand(command, "DrawImage");
            globalExportProgress.IncreaseOperationsDone(command.ProcessId);
        }