diff --git a/VideoNodes/FFMpegEncoder.cs b/VideoNodes/FFMpegEncoder.cs index 035e89b2..ac10361a 100644 --- a/VideoNodes/FFMpegEncoder.cs +++ b/VideoNodes/FFMpegEncoder.cs @@ -26,7 +26,7 @@ namespace FileFlows.VideoNodes this.Logger = logger; } - public (bool successs, string output) Encode(string input, string output, List arguments, bool dontAddInputFile = false) + public (bool successs, string output) Encode(string input, string output, List arguments, bool dontAddInputFile = false, bool dontAddOutputFile = false) { arguments ??= new List (); @@ -37,10 +37,13 @@ namespace FileFlows.VideoNodes arguments.Insert(2, "-y"); } - if (arguments.Last() != "-") - arguments.Add(output); - else - Logger.ILog("Last argument '-' skipping adding output file"); + if (dontAddOutputFile == false) + { + if (arguments.Last() != "-") + arguments.Add(output); + else + Logger.ILog("Last argument '-' skipping adding output file"); + } string argsString = String.Join(" ", arguments.Select(x => x.IndexOf(" ") > 0 ? "\"" + x + "\"" : x)); Logger.ILog(new string('=', ("FFMpeg.Arguments: " + argsString).Length)); diff --git a/VideoNodes/Tests/FFMPEGTests.cs b/VideoNodes/Tests/FFMPEGTests.cs index 64b8e4df..8c476b6c 100644 --- a/VideoNodes/Tests/FFMPEGTests.cs +++ b/VideoNodes/Tests/FFMPEGTests.cs @@ -30,14 +30,14 @@ namespace VideoNodes.Tests node.CommandLine = "-i {workingFile} {SomeVars} -o {output}"; node.Extension = ".mkv"; - var results = node.GetFFMPEGArgs(args); + var results = node.GetFFMPEGArgs(args, "file"); Assert.AreEqual("-i", results[0]); Assert.AreEqual(args.WorkingFile, results[1]); Assert.AreEqual("i", results[2]); Assert.AreEqual("am", results[3]); Assert.AreEqual("batman", results[4]); Assert.AreEqual("-o", results[5]); - Assert.IsTrue(results[6].EndsWith(".mkv")); + Assert.AreEqual("file", results[6]); } } diff --git a/VideoNodes/VideoNodes/EncodingNode.cs b/VideoNodes/VideoNodes/EncodingNode.cs index 17e946f8..503fbced 100644 --- a/VideoNodes/VideoNodes/EncodingNode.cs +++ b/VideoNodes/VideoNodes/EncodingNode.cs @@ -18,13 +18,13 @@ namespace FileFlows.VideoNodes private FFMpegEncoder Encoder; - protected bool Encode(NodeParameters args, string ffmpegExe, List ffmpegParameters, string extension = "mkv", string outputFile = "", bool updateWorkingFile = true, bool dontAddInputFile = false) + protected bool Encode(NodeParameters args, string ffmpegExe, List ffmpegParameters, string extension = "mkv", string outputFile = "", bool updateWorkingFile = true, bool dontAddInputFile = false, bool dontAddOutputFile = false) { string output; - return Encode(args, ffmpegExe, ffmpegParameters, out output, extension, outputFile, updateWorkingFile, dontAddInputFile); + return Encode(args, ffmpegExe, ffmpegParameters, out output, extension, outputFile, updateWorkingFile, dontAddInputFile: dontAddInputFile, dontAddOutputFile: dontAddOutputFile); } - protected bool Encode(NodeParameters args, string ffmpegExe, List ffmpegParameters, out string ouput, string extension = "mkv", string outputFile = "", bool updateWorkingFile = true, bool dontAddInputFile = false) + protected bool Encode(NodeParameters args, string ffmpegExe, List ffmpegParameters, out string ouput, string extension = "mkv", string outputFile = "", bool updateWorkingFile = true, bool dontAddInputFile = false, bool dontAddOutputFile = false) { if (string.IsNullOrEmpty(extension)) extension = "mkv"; @@ -46,7 +46,7 @@ namespace FileFlows.VideoNodes } } - var success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters, dontAddInputFile: dontAddInputFile); + var success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters, dontAddInputFile: dontAddInputFile, dontAddOutputFile: dontAddOutputFile); args.Logger.ILog("Encoding successful: " + success.successs); if (success.successs && updateWorkingFile) { diff --git a/VideoNodes/VideoNodes/FFMPEG.cs b/VideoNodes/VideoNodes/FFMPEG.cs index 546e99a1..db8c5fba 100644 --- a/VideoNodes/VideoNodes/FFMPEG.cs +++ b/VideoNodes/VideoNodes/FFMPEG.cs @@ -21,10 +21,8 @@ namespace FileFlows.VideoNodes public override string Icon => "far fa-file-video"; - public List GetFFMPEGArgs(NodeParameters args) + public List GetFFMPEGArgs(NodeParameters args, string outputFile) { - string outputFile = Path.Combine(args.TempPath, Guid.NewGuid().ToString() + "." + Extension); - string cmdLine = args.ReplaceVariables(CommandLine); List ffArgs = cmdLine.SplitCommandLine().Select(x => @@ -57,11 +55,18 @@ namespace FileFlows.VideoNodes if (string.IsNullOrEmpty(Extension)) Extension = "mkv"; - var ffArgs = GetFFMPEGArgs(args); + string outputFile = Path.Combine(args.TempPath, Guid.NewGuid().ToString() + "." + Extension); + var ffArgs = GetFFMPEGArgs(args, outputFile); - if (Encode(args, ffmpegExe, ffArgs) == false) + if (Encode(args, ffmpegExe, ffArgs, updateWorkingFile: false, dontAddInputFile: true, dontAddOutputFile: true) == false) return -1; + if (File.Exists(outputFile)) + { + args.Logger?.ILog("Output file exists, updating working file: " + outputFile); + args.SetWorkingFile(outputFile); + } + return 1; } catch (Exception ex)