diff --git a/BasicNodes/File/FileExists.cs b/BasicNodes/File/FileExists.cs
index 5dad6569..4ba8a2a5 100644
--- a/BasicNodes/File/FileExists.cs
+++ b/BasicNodes/File/FileExists.cs
@@ -1,47 +1,45 @@
-namespace FileFlows.BasicNodes.File
+namespace FileFlows.BasicNodes.File;
+using FileFlows.Plugin;
+using FileFlows.Plugin.Attributes;
+
+public class FileExists: Node
{
- using FileFlows.Plugin;
- using FileFlows.Plugin.Attributes;
+ public override int Inputs => 1;
+ public override int Outputs => 2;
- public class FileExists: Node
+ public override FlowElementType Type => FlowElementType.Logic;
+ public override string Icon => "fas fa-question-circle";
+
+ public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/file-exists";
+
+
+ [TextVariable(1)]
+ public string FileName { get; set; }
+
+ public override int Execute(NodeParameters args)
{
- public override int Inputs => 1;
- public override int Outputs => 2;
-
- public override FlowElementType Type => FlowElementType.Logic;
- public override string Icon => "fas fa-question-circle";
-
- public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/file-exists";
-
-
- [TextVariable(1)]
- public string FileName { get; set; }
-
- public override int Execute(NodeParameters args)
+ string file = args.ReplaceVariables(FileName ?? string.Empty, true);
+ if(string.IsNullOrWhiteSpace(file))
{
- string file = args.ReplaceVariables(FileName ?? string.Empty, true);
- if(string.IsNullOrWhiteSpace(file))
+ args.Logger?.ELog("FileName not set");
+ return -1;
+ }
+ try
+ {
+ file = args.MapPath(file);
+ var fileInfo = new FileInfo(file);
+ if (fileInfo.Exists)
{
- args.Logger?.ELog("FileName not set");
- return -1;
- }
- try
- {
- file = args.MapPath(file);
- var fileInfo = new FileInfo(file);
- if (fileInfo.Exists)
- {
- args.Logger?.ILog("File does exist: " + file);
- return 1;
- }
- args.Logger?.ILog("File does NOT exist: " + file);
- return 2;
- }
- catch (Exception ex)
- {
- args.Logger?.ELog($"Failed testing if file '{file}' exists: " + ex.Message);
- return -1;
+ args.Logger?.ILog("File does exist: " + file);
+ return 1;
}
+ args.Logger?.ILog("File does NOT exist: " + file);
+ return 2;
+ }
+ catch (Exception ex)
+ {
+ args.Logger?.ELog($"Failed testing if file '{file}' exists: " + ex.Message);
+ return -1;
}
}
}
\ No newline at end of file
diff --git a/BasicNodes/Tests/FileExistsTests.cs b/BasicNodes/Tests/FileExistsTests.cs
new file mode 100644
index 00000000..6e75cce9
--- /dev/null
+++ b/BasicNodes/Tests/FileExistsTests.cs
@@ -0,0 +1,23 @@
+#if(DEBUG)
+
+using FileFlows.BasicNodes.File;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace BasicNodes.Tests;
+
+[TestClass]
+public class FileExistsTests
+{
+ [TestMethod]
+ public void BasicTest()
+ {
+ var logger = new TestLogger();
+ var args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", logger, false, string.Empty);
+
+ var element = new FileExists();
+ element.FileName = "{folder.Orig.FullName}/{file.Orig.FileNameNoExtension}.en.srt";
+ element.Execute(args);
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioAddTrack.cs b/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioAddTrack.cs
index a43647c3..fa533299 100644
--- a/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioAddTrack.cs
+++ b/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioAddTrack.cs
@@ -108,21 +108,56 @@ public class FfmpegBuilderAudioAddTrack : FfmpegBuilderNode
return _BitrateOptions;
}
}
+
+
+ ///
+ /// Gets or sets the sample rate
+ ///
+ [DefaultValue(0)]
+ [Select(nameof(SampleRateOptions), 4)]
+ public int SampleRate { get; set; }
+
+ private static List _SampleRateOptions;
+ ///
+ /// Gets the sample rate options
+ ///
+ public static List SampleRateOptions
+ {
+ get
+ {
+ if (_SampleRateOptions == null)
+ {
+ _SampleRateOptions = new List
+ {
+ new () { Label = "Automatic", Value = 0},
+ new () { Label = "Same as source", Value = 1},
+ new () { Label = "44.1Khz", Value = 44100 },
+ new () { Label = "48Khz", Value = 48000 },
+ new () { Label = "88.2Khz", Value = 88200 },
+ new () { Label = "96Khz", Value = 96000 },
+ new () { Label = "176.4Khz", Value = 176400 },
+ new () { Label = "192Khz", Value = 192000 }
+ };
+ }
+ return _SampleRateOptions;
+ }
+ }
+
///
/// Gets or sets the language of the nee track
///
[DefaultValue("eng")]
- [TextVariable(4)]
+ [TextVariable(5)]
public string Language { get; set; }
///
/// Gets or sets if the title of the new track should be removed
///
- [Boolean(5)]
+ [Boolean(6)]
public bool RemoveTitle { get; set; }
///
/// Gets or sets the title of the new track
///
- [TextVariable(6)]
+ [TextVariable(7)]
[ConditionEquals(nameof(RemoveTitle), false)]
public string NewTitle { get; set; }
@@ -165,7 +200,8 @@ public class FfmpegBuilderAudioAddTrack : FfmpegBuilderNode
}
else
{
- audio.EncodingParameters.AddRange(GetNewAudioTrackParameters(Codec, Channels, Bitrate));
+ int sampleRate = SampleRate == 1 ? audio.Stream.SampleRate : SampleRate;
+ audio.EncodingParameters.AddRange(GetNewAudioTrackParameters(Codec, Channels, Bitrate, sampleRate));
if (this.Channels > 0)
audio.Channels = this.Channels;
}
@@ -252,52 +288,42 @@ public class FfmpegBuilderAudioAddTrack : FfmpegBuilderNode
/// the codec of the new track
/// the channels of the new track
/// the bitrate of the new track
+ /// the sample rate
/// the new track parameters
- internal static string[] GetNewAudioTrackParameters(string codec, float channels, int bitrate)
+ internal static string[] GetNewAudioTrackParameters(string codec, float channels, int bitrate, int sampleRate)
{
if (codec == "opus")
codec = "libopus";
+
+ // Prepare the options list
+ var options = new List
+ {
+ "-map", "0:a:{sourceTypeIndex}",
+ "-c:a:{index}",
+ codec
+ };
- if (channels == 0)
+ // Handle channels
+ if (channels > 0)
{
- // same as source
- if (bitrate == 0)
- {
- return new[]
- {
- "-map", "0:a:{sourceTypeIndex}",
- "-c:a:{index}",
- codec
- };
- }
- return new[]
- {
- "-map", "0:a:{sourceTypeIndex}",
- "-c:a:{index}",
- codec,
- "-b:a:{index}", bitrate + "k"
- };
+ options.Add("-ac:a:{index}");
+ options.Add(channels.ToString());
}
- else
+
+ // Handle bitrate
+ if (bitrate > 0)
{
- if (bitrate == 0)
- {
- return new[]
- {
- "-map", "0:a:{sourceTypeIndex}",
- "-c:a:{index}",
- codec,
- "-ac:a:{index}", channels.ToString()
- };
- }
- return new[]
- {
- "-map", "0:a:{sourceTypeIndex}",
- "-c:a:{index}",
- codec,
- "-ac:a:{index}", channels.ToString(),
- "-b:a:{index}", bitrate + "k"
- };
+ options.Add("-b:a:{index}");
+ options.Add(bitrate + "k");
}
+
+ // Handle sample rate
+ if (sampleRate > 0)
+ {
+ options.Add("-ar:a:{index}");
+ options.Add(sampleRate.ToString());
+ }
+
+ return options.ToArray();
}
}
diff --git a/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConvert.cs b/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConvert.cs
index 3732cdb8..fbcad09f 100644
--- a/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConvert.cs
+++ b/VideoNodes/FfmpegBuilderNodes/Audio/FfmpegBuilderAudioConvert.cs
@@ -136,7 +136,7 @@ public class FfmpegBuilderAudioConverter : FfmpegBuilderNode
if (codecSame && channelsSame && bitrateSame)
return false;
- stream.EncodingParameters.AddRange(FfmpegBuilderAudioAddTrack.GetNewAudioTrackParameters(Codec, Channels, Bitrate));
+ stream.EncodingParameters.AddRange(FfmpegBuilderAudioAddTrack.GetNewAudioTrackParameters(Codec, Channels, Bitrate, 0));
return true;
}
}
diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json
index c8802a1a..32c9a05a 100644
--- a/VideoNodes/VideoNodes.en.json
+++ b/VideoNodes/VideoNodes.en.json
@@ -95,6 +95,8 @@
"Bitrate-Help": "Bitrate of the new audio track",
"Codec": "Codec",
"Codec-Help": "The codec to use to encode the audio",
+ "SampleRate": "Sample Rate",
+ "SampleRate-Help": "The sample rate to use for the new audio track",
"Language": "Language",
"Language-Help": "Optional [ISO 639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) language code to use. Will attempt to find an audio track with this language code if not the best audio track will be used.",
"NewTitle": "New Title",