Fix GIF hue shift issues

This commit is contained in:
N00MKRAD
2023-12-26 22:59:17 +01:00
parent 55d4b8e87b
commit 355d44a5b3
4 changed files with 17 additions and 5 deletions

View File

@@ -1,6 +1,5 @@
using Flowframes.IO; using Flowframes.IO;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Flowframes.Data namespace Flowframes.Data
@@ -19,6 +18,8 @@ namespace Flowframes.Data
private readonly string[] validColorSpaces = new string[] { "bt709", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100", private readonly string[] validColorSpaces = new string[] { "bt709", "bt470m", "bt470bg", "smpte170m", "smpte240m", "linear", "log100",
"log316", "iec61966-2-4", "bt1361e", "iec61966-2-1", "bt2020-10", "bt2020-12", "smpte2084", "smpte428", "arib-std-b67" }; "log316", "iec61966-2-4", "bt1361e", "iec61966-2-1", "bt2020-10", "bt2020-12", "smpte2084", "smpte428", "arib-std-b67" };
public VidExtraData () { }
public VidExtraData(string ffprobeOutput) public VidExtraData(string ffprobeOutput)
{ {
string[] lines = ffprobeOutput.SplitIntoLines(); string[] lines = ffprobeOutput.SplitIntoLines();

View File

@@ -82,7 +82,8 @@ namespace Flowframes.Main
Fraction maxFps = max.Contains("/") ? new Fraction(max) : new Fraction(max.GetFloat()); Fraction maxFps = max.Contains("/") ? new Fraction(max) : new Fraction(max.GetFloat());
bool fpsLimit = maxFps.GetFloat() > 0f && s.outFps.GetFloat() > maxFps.GetFloat(); bool fpsLimit = maxFps.GetFloat() > 0f && s.outFps.GetFloat() > maxFps.GetFloat();
VidExtraData extraData = await FfmpegCommands.GetVidExtraInfo(s.inPath); bool gifInput = I.currentMediaFile.Format.Upper() == "GIF"; // If input is GIF, we don't need to check the color space etc
VidExtraData extraData = gifInput ? new VidExtraData() : await FfmpegCommands.GetVidExtraInfo(s.inPath);
string extraArgsIn = await FfmpegEncode.GetFfmpegExportArgsIn(s.outFps, s.outItsScale); string extraArgsIn = await FfmpegEncode.GetFfmpegExportArgsIn(s.outFps, s.outItsScale);
string extraArgsOut = await FfmpegEncode.GetFfmpegExportArgsOut(fpsLimit ? maxFps : new Fraction(), extraData, s.outSettings); string extraArgsOut = await FfmpegEncode.GetFfmpegExportArgsOut(fpsLimit ? maxFps : new Fraction(), extraData, s.outSettings);

View File

@@ -49,7 +49,8 @@ namespace Flowframes.Media
if (Interpolate.currentMediaFile != null && Interpolate.currentMediaFile.VideoStreams.Any()) if (Interpolate.currentMediaFile != null && Interpolate.currentMediaFile.VideoStreams.Any())
{ {
pixFmt = Interpolate.currentMediaFile.VideoStreams.First().PixelFormat.Lower(); pixFmt = Interpolate.currentMediaFile.VideoStreams.First().PixelFormat;
pixFmt = SimplifyPixFmt(pixFmt);
} }
bool inputHighBitDepth = pixFmt.Contains("p10") || pixFmt.Contains("p16"); bool inputHighBitDepth = pixFmt.Contains("p10") || pixFmt.Contains("p16");
@@ -65,7 +66,7 @@ namespace Flowframes.Media
else if (extension == "jpg") else if (extension == "jpg")
{ {
// Fallback to YUV420P if not in list of supported formats // Fallback to YUV420P if not in list of supported formats
if (!new[] { "yuvj420p", "yuvj422p", "yuvj444p", "yuv420p", "yuv422p", "yuv444p" }.Contains(pixFmt)) if (!new[] { "yuv420p", "yuv422p", "yuv444p" }.Contains(pixFmt))
{ {
pixFmt = "yuv420p"; pixFmt = "yuv420p";
} }
@@ -97,6 +98,14 @@ namespace Flowframes.Media
return args; return args;
} }
private static string SimplifyPixFmt (string pixFmt)
{
pixFmt = pixFmt.Lower();
pixFmt = pixFmt.Replace("yuvj", "yuv");
pixFmt = pixFmt.Replace("bgra", "rgba");
return pixFmt;
}
public static async Task VideoToFrames(string inputFile, string framesDir, bool alpha, Fraction rate, bool deDupe, bool delSrc, Size size, string format) public static async Task VideoToFrames(string inputFile, string framesDir, bool alpha, Fraction rate, bool deDupe, bool delSrc, Size size, string format)
{ {
Logger.Log("Extracting video frames from input video..."); Logger.Log("Extracting video frames from input video...");

View File

@@ -98,7 +98,8 @@ namespace Flowframes.Os
if (s.Dedupe && !s.Realtime) if (s.Dedupe && !s.Realtime)
l.Add(GetRedupeLines(s)); l.Add(GetRedupeLines(s));
l.Add($"clip = vs.core.resize.Bicubic(clip, format=vs.YUV444P16, matrix_s={(loadFrames ? "'470bg'" : "cMatrix")})"); // Convert RGB to YUV. Always use 470bg if input is frames bool use470bg = loadFrames && Interpolate.currentMediaFile.Format.Upper() != "GIF";
l.Add($"clip = vs.core.resize.Bicubic(clip, format=vs.YUV444P16, matrix_s={(use470bg ? "'470bg'" : "cMatrix")})"); // Convert RGB to YUV. Always use 470bg if input is YUV frames
if (!s.Dedupe) // Ignore trimming code when using deduping that that already handles trimming in the frame order file if (!s.Dedupe) // Ignore trimming code when using deduping that that already handles trimming in the frame order file
{ {