From 4e5d464753659206d42394e8a41e2b4acc30a137 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Tue, 16 Jun 2020 07:42:35 +0200 Subject: [PATCH] Add demux concat --- .../FFMpeg/Arguments/DemuxConcatArgument.cs | 32 +++++++++++++++++++ FFMpegCore/FFMpeg/FFMpegArguments.cs | 1 + 2 files changed, 33 insertions(+) create mode 100644 FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs diff --git a/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs b/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs new file mode 100644 index 0000000..2570db8 --- /dev/null +++ b/FFMpegCore/FFMpeg/Arguments/DemuxConcatArgument.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.IO; + +namespace FFMpegCore.Arguments +{ + /// + /// Represents parameter of concat argument + /// Used for creating video from multiple images or videos + /// + public class DemuxConcatArgument : IInputArgument + { + public readonly IEnumerable Values; + public DemuxConcatArgument(IEnumerable values) + { + Values = values; + } + private readonly string _tempFileName = Path.Combine(FFMpegOptions.Options.TempDirectory, Guid.NewGuid() + ".txt"); + + public void Pre() + { + File.WriteAllLines(_tempFileName, Values); + } + + public void Post() + { + File.Delete(_tempFileName); + } + + public string Text => $"-f concat -safe 0 -i \"{_tempFileName}\""; + } +} \ No newline at end of file diff --git a/FFMpegCore/FFMpeg/FFMpegArguments.cs b/FFMpegCore/FFMpeg/FFMpegArguments.cs index 40e72c7..d3b900c 100644 --- a/FFMpegCore/FFMpeg/FFMpegArguments.cs +++ b/FFMpegCore/FFMpeg/FFMpegArguments.cs @@ -32,6 +32,7 @@ private FFMpegArguments(IInputArgument inputArgument) public static FFMpegArguments FromInputFiles(params FileInfo[] files) => new FFMpegArguments(new InputArgument(false, files)); public static FFMpegArguments FromInputFiles(bool verifyExists, params FileInfo[] files) => new FFMpegArguments(new InputArgument(verifyExists, files)); public static FFMpegArguments FromConcatenation(params string[] files) => new FFMpegArguments(new ConcatArgument(files)); + public static FFMpegArguments FromDemuxConcatenation(params string[] files) => new FFMpegArguments(new ConcatArgument(files)); public static FFMpegArguments FromPipe(IPipeSource writer) => new FFMpegArguments(new InputPipeArgument(writer));