mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-05-12 14:38:53 -05:00
fixed issue with video info not being updated after encoding
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
namespace FileFlows.VideoNodes
|
||||
{
|
||||
internal class ResolutionHelper
|
||||
{
|
||||
public enum Resolution
|
||||
{
|
||||
Unknown,
|
||||
r480p,
|
||||
r720p,
|
||||
r1080p,
|
||||
r4k,
|
||||
}
|
||||
|
||||
public static Resolution GetResolution(VideoInfo videoInfo)
|
||||
{
|
||||
var video = videoInfo?.VideoStreams?.FirstOrDefault();
|
||||
if (video == null)
|
||||
return Resolution.Unknown;
|
||||
return GetResolution(video.Width, video.Height);
|
||||
}
|
||||
|
||||
public static Resolution GetResolution(int width, int height)
|
||||
{
|
||||
// so if the video is in portait mode, we test the height as if it were the width
|
||||
int w = Math.Max(width, height);
|
||||
int h = Math.Min(width, height);
|
||||
|
||||
if (Between(w, 1860, 1980))
|
||||
return Resolution.r1080p;
|
||||
else if (Between(w, 3780, 3900))
|
||||
return Resolution.r4k;
|
||||
else if (Between(w, 1220, 1340))
|
||||
return Resolution.r720p;
|
||||
else if (Between(w, 600, 700))
|
||||
return Resolution.r480p;
|
||||
|
||||
return Resolution.Unknown;
|
||||
}
|
||||
|
||||
|
||||
private static bool Between(int value, int lower, int max) => value >= lower && value <= max;
|
||||
}
|
||||
}
|
||||
@@ -26,15 +26,29 @@ namespace VideoNodes.Tests
|
||||
args.GetToolPathActual = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
|
||||
|
||||
node.VideoCodec = "h265";
|
||||
node.AudioCodec = "aac";
|
||||
node.Language = "DE";
|
||||
|
||||
|
||||
new VideoFile().Execute(args);
|
||||
|
||||
TestVideoInfo(args, "h264", "eac3");
|
||||
|
||||
int output = node.Execute(args);
|
||||
|
||||
Assert.AreEqual(1, output);
|
||||
TestVideoInfo(args, "hevc", "aac");
|
||||
}
|
||||
|
||||
private void TestVideoInfo(FileFlows.Plugin.NodeParameters parameters, string videoCodec, string audioCodec)
|
||||
{
|
||||
Assert.AreEqual(videoCodec, parameters.Variables["vi.Video.Codec"]);
|
||||
Assert.AreEqual(audioCodec, parameters.Variables["vi.Audio.Codec"]);
|
||||
var videoInfo = parameters.Variables["vi.VideoInfo"] as VideoInfo;
|
||||
Assert.AreEqual(videoCodec, videoInfo.VideoStreams[0].Codec);
|
||||
Assert.AreEqual(audioCodec, videoInfo.AudioStreams[0].Codec);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -125,6 +125,42 @@ namespace VideoNodes.Tests
|
||||
Assert.AreEqual(-1, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void VideoScaler_VideoInfoUpdated_Test()
|
||||
{
|
||||
const string file = @"D:\videos\problemfile\sample fileflows.mkv";
|
||||
var vi = new VideoInfoHelper(@"C:\utils\ffmpeg\ffmpeg.exe", new TestLogger());
|
||||
var vii = vi.Read(file);
|
||||
|
||||
VideoScaler node = new();
|
||||
var args = new FileFlows.Plugin.NodeParameters(file, new TestLogger(), false, string.Empty);
|
||||
args.GetToolPathActual = (string tool) => @"C:\utils\ffmpeg\ffmpeg.exe";
|
||||
args.TempPath = @"D:\videos\temp";
|
||||
|
||||
node.VideoCodec = "h265";
|
||||
|
||||
|
||||
new VideoFile().Execute(args);
|
||||
|
||||
TestVideoInfo(args, "h264", 1280, 720, "720p");
|
||||
|
||||
node.Resolution = "1920:-2";
|
||||
int output = node.Execute(args);
|
||||
|
||||
Assert.AreEqual(1, output);
|
||||
|
||||
TestVideoInfo(args, "hevc", 1920, 1080, "1080p");
|
||||
}
|
||||
|
||||
private void TestVideoInfo(FileFlows.Plugin.NodeParameters parameters, string videoCodec, int width, int height, string resolution)
|
||||
{
|
||||
Assert.AreEqual(videoCodec, parameters.Variables["vi.Video.Codec"]);
|
||||
Assert.AreEqual(resolution, parameters.Variables["vi.Resolution"]);
|
||||
var videoInfo = parameters.Variables["vi.VideoInfo"] as VideoInfo;
|
||||
Assert.AreEqual(videoCodec, videoInfo.VideoStreams[0].Codec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -54,9 +54,7 @@ namespace FileFlows.VideoNodes
|
||||
|
||||
// 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);
|
||||
SetVideoInfo(args, videoInfo, this.Variables ?? new Dictionary<string, object>());
|
||||
}
|
||||
Encoder.AtTime -= AtTimeEvent;
|
||||
Encoder = null;
|
||||
|
||||
@@ -81,27 +81,25 @@ namespace FileFlows.VideoNodes
|
||||
variables.AddOrUpdate("vi.Video.Codec", videoInfo.VideoStreams[0].Codec);
|
||||
if (videoInfo.AudioStreams?.Any() == true)
|
||||
{
|
||||
;
|
||||
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec))
|
||||
Variables.AddOrUpdate("vi.Audio.Codec", videoInfo.AudioStreams[0].Codec);
|
||||
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Codec))
|
||||
Variables.AddOrUpdate("vi.Audio.Channels", videoInfo.AudioStreams[0].Channels);
|
||||
if (string.IsNullOrEmpty(videoInfo.AudioStreams[0].Language))
|
||||
Variables.AddOrUpdate("vi.Audio.Language", videoInfo.AudioStreams[0].Language);
|
||||
Variables.AddOrUpdate("vi.Audio.Codecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
Variables.AddOrUpdate("vi.Audio.Languages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
variables.AddOrUpdate("vi.Audio.Codec", videoInfo.AudioStreams[0].Codec?.EmptyAsNull());
|
||||
variables.AddOrUpdate("vi.Audio.Channels", videoInfo.AudioStreams[0].Channels > 0 ? (object)videoInfo.AudioStreams[0].Channels : null);
|
||||
variables.AddOrUpdate("vi.Audio.Language", videoInfo.AudioStreams[0].Language?.EmptyAsNull());
|
||||
variables.AddOrUpdate("vi.Audio.Codecs", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Codec).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
variables.AddOrUpdate("vi.Audio.Languages", string.Join(", ", videoInfo.AudioStreams.Select(x => x.Language).Where(x => string.IsNullOrEmpty(x) == false)));
|
||||
}
|
||||
|
||||
if (videoInfo.VideoStreams[0].Width == 1920)
|
||||
Variables.AddOrUpdate("vi.Resolution", "1080");
|
||||
else if (videoInfo.VideoStreams[0].Width == 3840)
|
||||
Variables.AddOrUpdate("vi.Resolution", "4l");
|
||||
else if (videoInfo.VideoStreams[0].Width == 1280)
|
||||
Variables.AddOrUpdate("vi.Resolution", "720p");
|
||||
else if (videoInfo.VideoStreams[0].Width < 1280)
|
||||
Variables.AddOrUpdate("vi.Resolution", "SD");
|
||||
var resolution = ResolutionHelper.GetResolution(videoInfo.VideoStreams[0].Width, videoInfo.VideoStreams[0].Height);
|
||||
if(resolution == ResolutionHelper.Resolution.r1080p)
|
||||
variables.AddOrUpdate("vi.Resolution", "1080p");
|
||||
else if (resolution == ResolutionHelper.Resolution.r4k)
|
||||
variables.AddOrUpdate("vi.Resolution", "4K");
|
||||
else if (resolution == ResolutionHelper.Resolution.r720p)
|
||||
variables.AddOrUpdate("vi.Resolution", "720p");
|
||||
else if (resolution == ResolutionHelper.Resolution.r480p)
|
||||
variables.AddOrUpdate("vi.Resolution", "480p");
|
||||
else if (videoInfo.VideoStreams[0].Width < 900 && videoInfo.VideoStreams[0].Height < 800)
|
||||
variables.AddOrUpdate("vi.Resolution", "SD");
|
||||
else
|
||||
Variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height);
|
||||
variables.AddOrUpdate("vi.Resolution", videoInfo.VideoStreams[0].Width + "x" + videoInfo.VideoStreams[0].Height);
|
||||
|
||||
args.UpdateVariables(variables);
|
||||
}
|
||||
|
||||
@@ -101,13 +101,14 @@ namespace FileFlows.VideoNodes
|
||||
|
||||
if (Force == false)
|
||||
{
|
||||
if (Between(videoInfo.VideoStreams[0].Width, 1860, 1980) && Resolution.StartsWith("1920"))
|
||||
var resolution = ResolutionHelper.GetResolution(videoInfo);
|
||||
if(resolution == ResolutionHelper.Resolution.r1080p && Resolution.StartsWith("1920"))
|
||||
return 2;
|
||||
else if (Between(videoInfo.VideoStreams[0].Width, 3780, 3900) && Resolution.StartsWith("3840"))
|
||||
else if (resolution == ResolutionHelper.Resolution.r4k && Resolution.StartsWith("3840"))
|
||||
return 2;
|
||||
else if (Between(videoInfo.VideoStreams[0].Width, 1220, 1340) && Resolution.StartsWith("1280"))
|
||||
else if (resolution == ResolutionHelper.Resolution.r720p && Resolution.StartsWith("1280"))
|
||||
return 2;
|
||||
else if (Between(videoInfo.VideoStreams[0].Width, 600, 700) && Resolution.StartsWith("640"))
|
||||
else if (resolution == ResolutionHelper.Resolution.r480p && Resolution.StartsWith("640"))
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -143,7 +144,5 @@ namespace FileFlows.VideoNodes
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private bool Between(int value, int lower, int max) => value >= lower && value <= max;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -19,6 +19,11 @@
|
||||
Gets or sets if this library will use fingerprinting to determine if a file already is known
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FileFlows.Shared.Models.Library.ExcludeHidden">
|
||||
<summary>
|
||||
Gets or sets if hidden files and folders should be excluded from the library
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FileFlows.Shared.Models.Library.LastScanned">
|
||||
<summary>
|
||||
When the library was last scanned
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user