added ReadVideoInfo node

This commit is contained in:
John Andrews
2022-03-23 14:00:15 +13:00
parent b0b0067f6c
commit bd5bd20a3d
2 changed files with 87 additions and 0 deletions

View File

@@ -136,6 +136,13 @@
"Force-Help": "If the file should be always remuxed into a MKV container even when it already is in a MKV container.\ni.e. a new temporary file will always be created."
}
},
"ReadVideoInfo": {
"Descritption": "Reads the video information from the current working file and updates the vi variables.",
"Outputs": {
"1": "File was a video file and information read into flow",
"2": "File was not a video file or failed to be read"
}
},
"RemuxToMP4": {
"Descritption": "Remuxes a video file into a MP4 container. All streams will be copied to the new container",
"Outputs": {

View File

@@ -0,0 +1,80 @@
namespace FileFlows.VideoNodes
{
using FileFlows.Plugin;
public class ReadVideoInfo: EncodingNode
{
public override string Icon => "fas fa-video";
public override int Outputs => 2;
private Dictionary<string, object> _Variables;
public override Dictionary<string, object> Variables => _Variables;
public ReadVideoInfo()
{
_Variables = new Dictionary<string, object>()
{
{ "vi.Video.Codec", "hevc" },
{ "vi.Audio.Codec", "ac3" },
{ "vi.Audio.Codecs", "ac3,aac"},
{ "vi.Audio.Language", "eng" },
{ "vi.Audio.Languages", "eng, mao" },
{ "vi.Resolution", "1080p" },
{ "vi.Duration", 1800 },
{ "vi.VideoInfo", new VideoInfo()
{
Bitrate = 10_000_000,
VideoStreams = new List<VideoStream> {
new VideoStream { }
},
AudioStreams = new List<AudioStream> {
new AudioStream { }
},
SubtitleStreams = new List<SubtitleStream>
{
new SubtitleStream { }
}
}
},
{ "vi.Width", 1920 },
{ "vi.Height", 1080 },
};
}
public override int Execute(NodeParameters args)
{
string ffmpegExe = GetFFMpegExe(args);
if (string.IsNullOrEmpty(ffmpegExe))
return -1;
try
{
var videoInfo = new VideoInfoHelper(ffmpegExe, args.Logger).Read(args.WorkingFile);
if (videoInfo.VideoStreams.Any() == false)
{
args.Logger.ILog("No video streams detected.");
return 2;
}
foreach (var vs in videoInfo.VideoStreams)
{
args.Logger.ILog($"Video stream '{vs.Codec}' '{vs.Index}'");
}
foreach (var vs in videoInfo.AudioStreams)
{
args.Logger.ILog($"Audio stream '{vs.Codec}' '{vs.Index}' '{vs.Language}");
}
SetVideoInfo(args, videoInfo, Variables);
return 1;
}
catch (Exception ex)
{
args.Logger.WLog("Failed processing VideoFile: " + ex.Message);
return 2;
}
}
}
}