示例#1
0
        private async Task CutOneFile(FilesGroup step, ParallelProgressChild progress, CancellationToken cancellation)
        {
            var outputFormat = step.OutputEncoding ?? "-c copy";
            var file         = step.Files.Single();
            var filePath     = step.FilePath;

            var args = $"-i \"{file.FilePath}\" -ss {file.Start} -t {file.CutDuration} {outputFormat} -y \"{filePath}\"";

            Debug.WriteLine(args);

            await tasksLimit.WaitAsync(cancellation);

            try
            {
                using (var proc = StartProcess(FFMpegPath, str => UpdateProgress(str, progress), cancellation, args))
                {
                    await proc;
                }
            }
            finally
            {
                tasksLimit.Release();
            }
        }
示例#2
0
        private async Task ConcatMultipleFiles(FilesGroup step, ParallelProgressContainer progress, CancellationToken cancellation)
        {
            var outputFormat  = step.OutputEncoding ?? "-c copy";
            var concatFiles   = new List <string>();
            var tasks         = new List <Task>();
            var filesToDelete = new List <string>();
            var doneLock      = new object();

            try
            {
                foreach (var file in step.Files)
                {
                    cancellation.ThrowIfCancellationRequested();
                    if (Math.Abs(file.CutDuration - file.Duration) < 0.001)
                    {
                        concatFiles.Add(file.FilePath);
                    }
                    else
                    {
                        var newfile = Path.GetTempFileName() + Path.GetExtension(step.FilePath);

                        var tempargs = $"-i \"{file.FilePath}\" -ss {file.Start} -t {file.CutDuration} -c copy -y \"{newfile}\"";
                        Debug.WriteLine(tempargs);

                        var cutprogress = new ParallelProgressChild();
                        progress.Add(cutprogress);

                        await tasksLimit.WaitAsync(cancellation);

                        var tempproc = StartProcess(FFMpegPath, str => UpdateProgress(str, cutprogress, 0.5), cancellation, tempargs);

                        var fileCutDuration = file.CutDuration;

                        var task = tempproc.ContinueWith(
                            t =>
                        {
                            t.Result.Dispose();
                            tasksLimit.Release();
                        },
                            cancellation);
                        filesToDelete.Add(newfile);
                        concatFiles.Add(newfile);
                        tasks.Add(task);
                    }
                }

                await Task.WhenAll(tasks.ToArray());

                if (string.IsNullOrWhiteSpace(step.ComplexFilter))
                {
                    await ConcatFilesSimple(step, progress, concatFiles, outputFormat, cancellation);
                }
                else
                {
                    await ConcatFilesComplex(step, progress, concatFiles, cancellation);
                }
            }
            finally
            {
                foreach (var file in filesToDelete)
                {
                    File.Delete(file);
                }
            }
        }