mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-05-08 04:30:03 -05:00
FF-1193 - Updated Audio Nodes to work with File Server
This commit is contained in:
@@ -33,7 +33,7 @@ public class AudioFileNormalization : AudioNode
|
||||
|
||||
long sampleRate = AudioInfo.Frequency > 0 ? AudioInfo.Frequency : 48_000;
|
||||
|
||||
var twoPass = DoTwoPass(args, ffmpegExe);
|
||||
var twoPass = DoTwoPass(args, ffmpegExe, LocalWorkingFile);
|
||||
if (twoPass.Success == false)
|
||||
{
|
||||
args.Logger?.WLog("Failed to normalize audio, skipping");
|
||||
@@ -42,11 +42,9 @@ public class AudioFileNormalization : AudioNode
|
||||
|
||||
ffArgs.AddRange(new[] { "-i", args.WorkingFile, "-c:a", AudioInfo.Codec, "-ar", sampleRate.ToString(), "-af", twoPass.Normalization });
|
||||
|
||||
string extension = new FileInfo(args.WorkingFile).Extension;
|
||||
if (extension.StartsWith("."))
|
||||
extension = extension.Substring(1);
|
||||
string extension = FileHelper.GetExtension(args.WorkingFile);
|
||||
|
||||
string outputFile = Path.Combine(args.TempPath, Guid.NewGuid() + "." + extension);
|
||||
string outputFile = FileHelper.Combine(args.TempPath, Guid.NewGuid() + "." + extension);
|
||||
ffArgs.Add(outputFile);
|
||||
|
||||
var result = args.Execute(new ExecuteArgs
|
||||
@@ -65,7 +63,7 @@ public class AudioFileNormalization : AudioNode
|
||||
}
|
||||
|
||||
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
||||
public static (bool Success, string Normalization) DoTwoPass(NodeParameters args, string ffmpegExe)
|
||||
public static (bool Success, string Normalization) DoTwoPass(NodeParameters args, string ffmpegExe, string localFile)
|
||||
{
|
||||
//-af loudnorm=I=-24:LRA=7:TP=-2.0"
|
||||
var result = args.Execute(new ExecuteArgs
|
||||
@@ -74,7 +72,7 @@ public class AudioFileNormalization : AudioNode
|
||||
ArgumentList = new[]
|
||||
{
|
||||
"-hide_banner",
|
||||
"-i", args.WorkingFile,
|
||||
"-i", localFile,
|
||||
"-af", "loudnorm=" + LOUDNORM_TARGET + ":print_format=json",
|
||||
"-f", "null",
|
||||
"-"
|
||||
|
||||
@@ -6,6 +6,21 @@ namespace FileFlows.AudioNodes
|
||||
{
|
||||
public override string Icon => "fas fa-music";
|
||||
|
||||
protected string LocalWorkingFile;
|
||||
|
||||
public override bool PreExecute(NodeParameters args)
|
||||
{
|
||||
var localFile = args.FileService.GetLocalPath(args.WorkingFile);
|
||||
if (localFile.IsFailed)
|
||||
{
|
||||
args.Logger?.ELog("Failed to get local file: " + localFile.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
LocalWorkingFile = localFile.Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected string GetFFmpeg(NodeParameters args)
|
||||
{
|
||||
string ffmpeg = args.GetToolPath("FFMpeg");
|
||||
@@ -14,7 +29,7 @@ namespace FileFlows.AudioNodes
|
||||
args.Logger.ELog("FFmpeg tool not found.");
|
||||
return "";
|
||||
}
|
||||
var fileInfo = new FileInfo(ffmpeg);
|
||||
var fileInfo = new System.IO.FileInfo(ffmpeg);
|
||||
if (fileInfo.Exists == false)
|
||||
{
|
||||
args.Logger.ELog("FFmpeg tool configured by ffmpeg file does not exist.");
|
||||
@@ -31,7 +46,7 @@ namespace FileFlows.AudioNodes
|
||||
args.Logger.ELog("FFMpeg tool not found.");
|
||||
return "";
|
||||
}
|
||||
var fileInfo = new FileInfo(ffmpeg);
|
||||
var fileInfo = new System.IO.FileInfo(ffmpeg);
|
||||
if (fileInfo.Exists == false)
|
||||
{
|
||||
args.Logger.ELog("FFmpeg tool configured by ffmpeg file does not exist.");
|
||||
@@ -43,10 +58,7 @@ namespace FileFlows.AudioNodes
|
||||
private const string Audio_INFO = "AudioInfo";
|
||||
internal void SetAudioInfo(NodeParameters args, AudioInfo AudioInfo, Dictionary<string, object> variables)
|
||||
{
|
||||
if (args.Parameters.ContainsKey(Audio_INFO))
|
||||
args.Parameters[Audio_INFO] = AudioInfo;
|
||||
else
|
||||
args.Parameters.Add(Audio_INFO, AudioInfo);
|
||||
args.Parameters[Audio_INFO] = AudioInfo;
|
||||
|
||||
if(AudioInfo.Artist.EndsWith(", The"))
|
||||
variables.AddOrUpdate("audio.Artist", "The " + AudioInfo.Artist.Substring(0, AudioInfo.Artist.Length - ", The".Length).Trim());
|
||||
|
||||
@@ -336,19 +336,19 @@ namespace FileFlows.AudioNodes
|
||||
|
||||
|
||||
var ffArgs = GetArguments(args, out string extension);
|
||||
string outputFile = Path.Combine(args.TempPath,
|
||||
Guid.NewGuid().ToString() + "." + (extension?.EmptyAsNull() ?? Extension));
|
||||
string outputFile = FileHelper.Combine(args.TempPath,
|
||||
Guid.NewGuid() + "." + (extension?.EmptyAsNull() ?? Extension));
|
||||
|
||||
ffArgs.Insert(0, "-hide_banner");
|
||||
ffArgs.Insert(1, "-y"); // tells ffmpeg to replace the file if already exists, which it shouldnt but just incase
|
||||
ffArgs.Insert(2, "-i");
|
||||
ffArgs.Insert(3, args.WorkingFile);
|
||||
ffArgs.Insert(3, LocalWorkingFile);
|
||||
ffArgs.Insert(4, "-vn"); // disables video
|
||||
|
||||
|
||||
if (Normalize)
|
||||
{
|
||||
var twoPass = AudioFileNormalization.DoTwoPass(args, ffmpegExe);
|
||||
var twoPass = AudioFileNormalization.DoTwoPass(args, ffmpegExe, LocalWorkingFile);
|
||||
if (twoPass.Success)
|
||||
{
|
||||
ffArgs.Add("-af");
|
||||
@@ -358,7 +358,7 @@ namespace FileFlows.AudioNodes
|
||||
|
||||
ffArgs.Add(outputFile);
|
||||
|
||||
args.Logger?.ILog("FFArgs: " + String.Join(" ", ffArgs.Select(x => x.IndexOf(" ") > 0 ? "\"" + x + "\"" : x).ToArray()));
|
||||
args.Logger?.ILog("FFArgs: " + string.Join(" ", ffArgs.Select(x => x.IndexOf(" ") > 0 ? "\"" + x + "\"" : x).ToArray()));
|
||||
|
||||
var result = args.Execute(new ExecuteArgs
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user