added support for variables in nodes, and crated Renamer in basic nodes which can use variables to rename a file

This commit is contained in:
reven
2021-11-23 22:26:15 +13:00
parent 761b82dbff
commit 962fe7959c
21 changed files with 313 additions and 38 deletions
+8
View File
@@ -33,7 +33,15 @@ namespace FileFlows.VideoNodes
bool success = Encoder.Encode(args.WorkingFile, outputFile, ffmpegParameters);
args.Logger.ILog("Encoding succesful: " + success);
if (success)
{
args.SetWorkingFile(outputFile);
// get the new video info
var videoInfo = new VideoInfoHelper(ffmpegExe, args.Logger).Read(outputFile);
var newVariables = new Dictionary<string, object>();
SetVideoInfo(args, videoInfo, newVariables);
args.UpdateVariables(newVariables);
}
Encoder.AtTime -= AtTimeEvent;
Encoder = null;
return success;
+18
View File
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VideoNodes
{
internal static class ExtensionMethods
{
public static void AddOrUpdate(this Dictionary<string, object> dict, string key, object value) {
if (dict.ContainsKey(key))
dict[key] = value;
else
dict.Add(key, value);
}
}
}
+39 -1
View File
@@ -9,6 +9,21 @@ namespace FileFlows.VideoNodes
public override int Outputs => 1;
public override FlowElementType Type => FlowElementType.Input;
private Dictionary<string, object> _Variables;
public override Dictionary<string, object> Variables => _Variables;
public VideoFile()
{
_Variables = new Dictionary<string, object>()
{
{ "vi.VideoCodec", string.Empty },
{ "vi.AudioCodec", string.Empty },
{ "vi.AudioCodecs", string.Empty },
{ "vi.AudioLanguage", string.Empty },
{ "vi.AudioLanguages", string.Empty },
{ "vi.Resolution", string.Empty },
};
}
public override int Execute(NodeParameters args)
{
string ffmpegExe = GetFFMpegExe(args);
@@ -36,7 +51,30 @@ namespace FileFlows.VideoNodes
args.Logger.ILog($"Audio stream '{vs.Codec}' '{vs.Index}' '{vs.Language}");
}
SetVideoInfo(args, videoInfo);
SetVideoInfo(args, videoInfo, Variables);
Variables["vi.VideoCodec"] = videoInfo.VideoStreams[0].Codec;
if (videoInfo.AudioStreams?.Any() == true)
{
;
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec))
Variables["vi.AudioCodec"] = videoInfo.AudioStreams[0].Codec;
if(string.IsNullOrEmpty(videoInfo.AudioStreams[0].Language))
Variables["vi.AudioLanguage"] = videoInfo.AudioStreams[0].Language;
Variables["vi.AudioCodecs"] = string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false));
Variables["vi.AudioLanguages"] = string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false));
}
if (videoInfo.VideoStreams[0].Width == 1920)
Variables["vi.Resolution"] = "1080P";
else if (videoInfo.VideoStreams[0].Width == 3840)
Variables["vi.Resolution"] = "4k";
else if (videoInfo.VideoStreams[0].Width == 1280)
Variables["vi.Resolution"] = "720p";
else if (videoInfo.VideoStreams[0].Width < 1280)
Variables["vi.Resolution"] = "SD";
else
Variables["vi.Resolution"] = videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height;
return 1;
}
+29 -3
View File
@@ -1,6 +1,8 @@
namespace FileFlows.VideoNodes
{
using FileFlows.Plugin;
using global::VideoNodes;
public abstract class VideoNode : Node
{
public override string Icon => "fas fa-video";
@@ -63,13 +65,37 @@ namespace FileFlows.VideoNodes
}
private const string VIDEO_INFO = "VideoInfo";
protected void SetVideoInfo(NodeParameters args, VideoInfo info)
protected void SetVideoInfo(NodeParameters args, VideoInfo videoInfo, Dictionary<string, object> variables)
{
if (args.Parameters.ContainsKey(VIDEO_INFO))
args.Parameters[VIDEO_INFO] = info;
args.Parameters[VIDEO_INFO] = videoInfo;
else
args.Parameters.Add(VIDEO_INFO, info);
args.Parameters.Add(VIDEO_INFO, videoInfo);
variables.AddOrUpdate("vi.VideoCodec", videoInfo.VideoStreams[0].Codec);
if (videoInfo.AudioStreams?.Any() == true)
{
;
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec))
Variables.AddOrUpdate("vi.AudioCodec", videoInfo.AudioStreams[0].Codec);
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Language))
Variables.AddOrUpdate("vi.AudioLanguage", videoInfo.AudioStreams[0].Language);
Variables.AddOrUpdate("vi.AudioCodecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false)));
Variables.AddOrUpdate("vi.AudioLanguages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false)));
}
if (videoInfo.VideoStreams[0].Width == 1920)
Variables.AddOrUpdate("vi.Resolution", "1080P");
else if (videoInfo.VideoStreams[0].Width == 3840)
Variables.AddOrUpdate("vi.Resolution", "4k");
else if (videoInfo.VideoStreams[0].Width == 1280)
Variables.AddOrUpdate("vi.Resolution", "720P");
else if (videoInfo.VideoStreams[0].Width < 1280)
Variables.AddOrUpdate("vi.Resolution", "SD");
else
Variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height);
}
protected VideoInfo GetVideoInfo(NodeParameters args)
{
if (args.Parameters.ContainsKey(VIDEO_INFO) == false)
Binary file not shown.