public void Cut_Concat_Effect3Videos_Test() { const string OutputFile = OutputFolder + "Cut_Effect_Concat3Videos.avi"; const string FileToConcat1 = OutputFolder + "1EpisodeToConcat_tmp.avi"; const string FileToConcat2 = OutputFolder + "2EpisodeToConcat_tmp.avi"; const string FileToConcat2TW = OutputFolder + "2EpisodeToConcat_tmpTW.avi"; const string FileToConcat3 = OutputFolder + "3EpisodeToConcat_tmp.avi"; string source = Path.Combine(this.InputFolder, SampleFiles.RealInputVideoAVI2); var ffmpeg = new FFMpeg(this.temporaryFilesStorage); var cutOptions1 = FFMpegCutOptions.BuildSimpleCatOptions(source, FileToConcat1, 100, 20, GlobalExportProgress.Empty); ffmpeg.Cut(cutOptions1); var cutOptions2 = FFMpegCutOptions.BuildSimpleCatOptions(source, FileToConcat2, 300, 20, GlobalExportProgress.Empty); ffmpeg.Cut(cutOptions2); var cutOptions3 = FFMpegCutOptions.BuildSimpleCatOptions(source, FileToConcat3, 600, 20, GlobalExportProgress.Empty); ffmpeg.Cut(cutOptions3); ffmpeg.Concat(OutputFile, "copy", "copy", GlobalExportProgress.Empty, FileToConcat1, FileToConcat2, FileToConcat3); ffmpeg.ApplyTimeWarp(OutputFile, new List <TimeWarpRecord> { new TimeWarpRecord(23, 32, 2), new TimeWarpRecord(43, 52, 2) }, FileToConcat2TW, GlobalExportProgress.Empty); Assert.IsTrue(File.Exists(OutputFile)); }
protected virtual void CutAndConcatAndRenderTextAndImageAndTimeWarps(List <FFMpegCutInfo> cutInfos, FFMpeg ffMpeg, TemporaryFilesStorage temporaryFilesStorage) { var textTimeTableForConcatenatedEpisodeGroups = new List <TextTimeRecord>(); var imagesTimeTableForConcatenatedEpisodeGroups = new List <DrawImageTimeRecord>(); var timeWarpForConcatenatedEpisodeGroups = new List <TimeWarpRecord>(); var currentPosition = 0.0; foreach (var videoRenderOption in this.VideoRenderOptions) { if (videoRenderOption.OverlayTextTimeTable != null && videoRenderOption.OverlayTextTimeTable.Any()) { textTimeTableForConcatenatedEpisodeGroups.AddRange( videoRenderOption.OverlayTextTimeTable.Select(v => new TextTimeRecord(v.Lines, v.StartSecond + currentPosition, v.EndSecond + currentPosition))); } if (videoRenderOption.ImagesTimeTable != null && videoRenderOption.ImagesTimeTable.Any()) { imagesTimeTableForConcatenatedEpisodeGroups.AddRange( videoRenderOption.ImagesTimeTable.Select(v => new DrawImageTimeRecord(v.ImageData, v.LeftOffset, v.TopOffset, v.ImageStartSecond + currentPosition, v.ImageEndSecond + currentPosition))); } if (videoRenderOption.TimeWarpSettings != null && videoRenderOption.TimeWarpSettings.Any()) { timeWarpForConcatenatedEpisodeGroups.AddRange( videoRenderOption.TimeWarpSettings.Select(v => new TimeWarpRecord(v.StartSecond + currentPosition, v.EndSecond + currentPosition, v.Coefficient))); } currentPosition += videoRenderOption.DurationSeconds; } var pathForConcatenatedEpisodes = timeWarpForConcatenatedEpisodeGroups.Any() ? temporaryFilesStorage.GetIntermediateFile(Path.GetExtension(this.outputFile)) : this.outputFile; ffMpeg.CutAndConcatAndDrawImagesAndText( cutInfos, imagesTimeTableForConcatenatedEpisodeGroups, textTimeTableForConcatenatedEpisodeGroups, this.OutputSize, pathForConcatenatedEpisodes, this.globalExportProgress); if (timeWarpForConcatenatedEpisodeGroups.Any()) { ffMpeg.ApplyTimeWarp(pathForConcatenatedEpisodes, timeWarpForConcatenatedEpisodeGroups, this.outputFile, this.globalExportProgress); } }
private void CutAndDrawTextAndDrawImageAndApplyTimeWarp( FFMpeg ffMpeg, FFMpegCutOptions cutOptions, TemporaryFilesStorage temporaryFilesStorage) { EnsureFileDoesNotExist(cutOptions.OutputFile); var extensionForResultFile = Path.GetExtension(cutOptions.OutputFile); var imagesExist = cutOptions.ImagesTimeTable != null && cutOptions.ImagesTimeTable.Any(); var timeWarpExists = cutOptions.TimeWarps != null && cutOptions.TimeWarps.Any(); if (!cutOptions.OverlayText.Any() && !imagesExist && !timeWarpExists) { ffMpeg.Cut(cutOptions); return; } var intermediateFile1 = temporaryFilesStorage.GetIntermediateFile(extensionForResultFile); ffMpeg.Cut(cutOptions.CloneWithOtherOutput(intermediateFile1)); if (cutOptions.OverlayText.Any()) { var intermediateFile2 = (imagesExist || timeWarpExists) ? temporaryFilesStorage.GetIntermediateFile(extensionForResultFile) : cutOptions.OutputFile; ffMpeg.DrawText(intermediateFile1, cutOptions.OverlayText, intermediateFile2, cutOptions.GlobalExportProgress); File.Delete(intermediateFile1); intermediateFile1 = intermediateFile2; } if (imagesExist) { var intermediateFile3 = timeWarpExists ? temporaryFilesStorage.GetIntermediateFile(extensionForResultFile) : cutOptions.OutputFile; ffMpeg.DrawImage(intermediateFile1, cutOptions.ImagesTimeTable, intermediateFile3, cutOptions.GlobalExportProgress); File.Delete(intermediateFile1); intermediateFile1 = intermediateFile3; } if (timeWarpExists) { ffMpeg.ApplyTimeWarp(intermediateFile1, cutOptions.TimeWarps, cutOptions.OutputFile, this.globalExportProgress); File.Delete(intermediateFile1); } }