C# Script
Allows you to execute C# code in a flow. This has full access to the Flow and all the exposed properties.
These run effectively with the same abilities as a Plugin flow element, and can access public plugin methods easily.
It can var you make decision paths based on previous flow elements, compute variables for future flow elements, log information, and many more features.
Return Codes
Number | Description |
---|---|
1+ | Specifies which output is to be called. Define the number of outputs using the Outputs field. This will add more output connections to the flow element. |
0 | Completes the flow successfully. This will immediately stop the flow and mark it as successful. |
-1 | Indicates an error and stops the flow. This will mark the flow as unsuccessful. |
See C# Scripting for a complete reference
Examples
Different outputs based on file size
if(Variables.file.Size > 10_000_000_000) // 10GB
return 1; // output 1
if(Variables.file.Size > 2_000_000_000) // 2GB
return 2; // output 2
var reducedSize = (Variables.file.Size / Variables.file.Orig.Size) * 100;
if(reducedSize < 10)
return 0; // its too small, something went wrong
return 3; // output 3
Copying files in a Function
// file here is a FileInfo object which makes it easy to get the short filename (file.Name)
foreach(var file in new System.IO.DirectoryInfo('/mnt/source').GetFiles('*.*'))
{
System.IO.File.Copy(file.FullName, '/mnt/destination/' + file.Name);
}
// alternative, where file is a string of the full filename
foreach(var file in System.IO.Directory.GetFiles('/mnt/source', '*.*')
{
System.IO.File.Copy(file, '/mnt/destination/' + file.Substring(file.LastIndexOf('/') + 1));
}
Disable all but first Audio / Subtitle
This example function will disable all subtitle and all but the very first Audio track
This must be used between a FFmpeg Builder: Start
and FFmpeg Builder: Executor
for(var i=1;i<Variables?.FfmpegBuilderModel?.AudioStreams?.Length ?? 0 ?? 0;i++)
{
var audio = Variables.FfmpegBuilderModel.AudioStreams[i];
audio.Deleted = true;
}
for(var i=0;i<Variables?.FfmpegBuilderModel?.SubtitleStreams?.Length ?? 0 ?? 0;i++)
{
var sub = Variables.FfmpegBuilderModel.SubtitleStreams[i];
sub.Deleted = true;
}
return 1;
Disable all but first English/Japanese Audio
This example function disables all but the first English and Japanese Audio track found
This must be used between a FFmpeg Builder: Start
and FFmpeg Builder: Executor
var foundEnglish = false;
var foundJapanese = false;
var first = null;
for(var i=0;i<Variables?.FfmpegBuilderModel?.AudioStreams?.Length ?? 0;i++)
{
var audioStream = Variables.FfmpegBuilderModel.AudioStreams[i];
audioStream.Deleted = true;
if(i === 0)
first = audioStream;
var isEnglish = System.Text.RegularExpressions.Regex.IsMatch(audioStream.Language ?? "", @"^en", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
var isJapanese = System.Text.RegularExpressions.Regex.IsMatch(audioStream.Language ?? "", @"^(jp|jap)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if(foundEnglish && foundJapanese)
{
// already found japanese and english remove the rest of the audio
continue;
}
if(foundEnglish && isEnglish)
{
// already found english
continue;
}
if(foundJapanese && isJapanese)
{
// already found japanese
continue;
}
// else we want to keep this track, so make sure its not deleted
audioStream.Deleted = false;
if(isEnglish)
foundEnglish = true;
if(isJapanese)
foundJapanese = true;
}
if(foundEnglish === false && foundJapanese === false && first)
{
// enable the first audio for safety
first.Deleted = false;
}
return 1;
Clear Video Title
This example will clear all titles from video streams
This must be used between a FFmpeg Builder: Start
and FFmpeg Builder: Executor
for(var i=0;i<Variables?.FfmpegBuilderModel?.VideoStreams?.Length ?? 0;i++)
{
var video = Variables.FfmpegBuilderModel.VideoStreams[i];
video.Title = '';
}
return 1;
Set Audio Stream 0 as default
This example will iterate all audio streams in the FFmpeg Builder and set the first audio stream as the default stream.
This must be used between a FFmpeg Builder: Start
and FFmpeg Builder: Executor
var length = Variables?.FfmpegBuilderModel?.AudioStreams?.Length ?? 0;
if(length == 0)
{
Logger.ILog('No audio stream found"');
return 1;
}
Logger.ILog('Found audio streams: ' + length);
for(var i=0;i<length;i++)
{
var audio = Variables.FfmpegBuilderModel.AudioStreams[i];
if(audio)
audio.IsDefault = i === 0;
}
return 1;
Checking a File Exists
This example will look if a file exists in the source directory.
This is helpful if you want to skip processing of files if a certain file exists in that folder.
var dir = new System.IO.FileInfo(Variables.file.FullName).Directory;
var exists = dir.GetFiles("*.ffignore").Length > 0;
Logger.ILog("ffignore exists: " + exists);
return exists ? 1 : 2;