From bd5bd20a3d82043f1e353fb3edfbdeacdc8c86c5 Mon Sep 17 00:00:00 2001 From: John Andrews Date: Wed, 23 Mar 2022 14:00:15 +1300 Subject: [PATCH] added ReadVideoInfo node --- VideoNodes/VideoNodes.en.json | 7 +++ VideoNodes/VideoNodes/ReadVideoInfo.cs | 80 ++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 VideoNodes/VideoNodes/ReadVideoInfo.cs diff --git a/VideoNodes/VideoNodes.en.json b/VideoNodes/VideoNodes.en.json index 417c7950..d274fa25 100644 --- a/VideoNodes/VideoNodes.en.json +++ b/VideoNodes/VideoNodes.en.json @@ -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": { diff --git a/VideoNodes/VideoNodes/ReadVideoInfo.cs b/VideoNodes/VideoNodes/ReadVideoInfo.cs new file mode 100644 index 00000000..25063925 --- /dev/null +++ b/VideoNodes/VideoNodes/ReadVideoInfo.cs @@ -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 _Variables; + public override Dictionary Variables => _Variables; + public ReadVideoInfo() + { + _Variables = new Dictionary() + { + { "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 { + new VideoStream { } + }, + AudioStreams = new List { + new AudioStream { } + }, + SubtitleStreams = new List + { + 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; + } + } + } +} \ No newline at end of file