mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-20 11:09:40 -06:00
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
namespace FileFlows.VideoNodes
|
|
{
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using FileFlows.Plugin;
|
|
using FileFlows.Plugin.Attributes;
|
|
|
|
public class FFMPEG : EncodingNode
|
|
{
|
|
public override int Outputs => 1;
|
|
|
|
[DefaultValue("-i {WorkingFile} {Output}")]
|
|
[TextArea(1)]
|
|
[Required]
|
|
public string CommandLine { get; set; }
|
|
|
|
[DefaultValue("mkv")]
|
|
[Text(2)]
|
|
[Required]
|
|
public string Extension { get; set; }
|
|
|
|
public override string Icon => "far fa-file-video";
|
|
|
|
public List<string> GetFFMPEGArgs(NodeParameters args, string outputFile)
|
|
{
|
|
string cmdLine = args.ReplaceVariables(CommandLine);
|
|
|
|
List<string> ffArgs = cmdLine.SplitCommandLine().Select(x =>
|
|
{
|
|
if (x.ToLower() == "{workingfile}") return args.WorkingFile;
|
|
if (x.ToLower() == "{output}") return outputFile;
|
|
return x;
|
|
}).ToList();
|
|
return ffArgs;
|
|
}
|
|
|
|
public override int Execute(NodeParameters args)
|
|
{
|
|
if (string.IsNullOrEmpty(CommandLine))
|
|
{
|
|
args.Logger.ELog("Command Line not set");
|
|
return -1;
|
|
}
|
|
try
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(Extension))
|
|
Extension = "mkv";
|
|
|
|
string outputFile = Path.Combine(args.TempPath, Guid.NewGuid().ToString() + "." + Extension);
|
|
var ffArgs = GetFFMPEGArgs(args, outputFile);
|
|
|
|
if (Encode(args, FFMPEG, 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)
|
|
{
|
|
args.Logger.ELog("Failed processing VideoFile: " + ex.Message);
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
} |