Case-sensitive rename operation (1/2)

This commit is contained in:
n00mkrad
2021-08-23 16:49:40 +02:00
parent 9162b5971b
commit 2c14fa9515
89 changed files with 12 additions and 36463 deletions

View File

@@ -1,31 +0,0 @@
using Flowframes.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
public struct AI
{
public string aiName;
public string aiNameShort;
public string friendlyName;
public string description;
public string pkgDir;
public int[] supportedFactors;
public bool multiPass; // Are multiple passes needed to get to the desired interp factor?
public AI(string aiNameArg, string friendlyNameArg, string descArg, string pkgDirArg, int[] factorsArg, bool multiPassArg = false)
{
aiName = aiNameArg;
aiNameShort = aiNameArg.Split(' ')[0].Split('_')[0];
friendlyName = friendlyNameArg;
description = descArg;
pkgDir = pkgDirArg;
supportedFactors = factorsArg;
multiPass = multiPassArg;
}
}
}

View File

@@ -1,18 +0,0 @@
using System.Globalization;
namespace Flowframes.Data
{
class AudioTrack
{
public int streamIndex;
public string metadata;
public string codec;
public AudioTrack(int streamNum, string metaStr, string codecStr)
{
streamIndex = streamNum;
metadata = metaStr.Trim().Replace("_", ".").Replace(" ", ".");
codec = codecStr.Trim().Replace("_", ".");
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
class Filetypes
{
public static readonly string[] imagesOpenCv = new string[] { ".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tif", ".tiff" };
public static readonly string[] imagesInterpCompat = new string[] { ".png", ".jpg", ".jpeg", ".webp", ".bmp" };
}
}

View File

@@ -1,256 +0,0 @@
using System;
using System.Windows.Navigation;
namespace Flowframes.Data
{
public struct Fraction
{
public int Numerator;
public int Denominator;
public static Fraction Zero = new Fraction(0, 0);
public Fraction(int numerator, int denominator)
{
this.Numerator = numerator;
this.Denominator = denominator;
//If denominator negative...
if (this.Denominator < 0)
{
//...move the negative up to the numerator
this.Numerator = -this.Numerator;
this.Denominator = -this.Denominator;
}
}
public Fraction(int numerator, Fraction denominator)
{
//divide the numerator by the denominator fraction
this = new Fraction(numerator, 1) / denominator;
}
public Fraction(Fraction numerator, int denominator)
{
//multiply the numerator fraction by 1 over the denominator
this = numerator * new Fraction(1, denominator);
}
public Fraction(Fraction fraction)
{
Numerator = fraction.Numerator;
Denominator = fraction.Denominator;
}
public Fraction(float value)
{
Numerator = (value * 10000f).RoundToInt();
Denominator = 10000;
this = GetReduced();
}
public Fraction(string text)
{
try
{
string[] numbers = text.Split('/');
Numerator = numbers[0].GetInt();
Denominator = numbers[1].GetInt();
}
catch
{
try
{
Numerator = text.GetFloat().RoundToInt();
Denominator = 1;
}
catch
{
Numerator = 0;
Denominator = 0;
}
}
Logger.Log($"Fraction from String: Fraction(\"{text}\") => {Numerator}/{Denominator}", true);
}
private static int getGCD(int a, int b)
{
//Drop negative signs
a = Math.Abs(a);
b = Math.Abs(b);
//Return the greatest common denominator between two integers
while (a != 0 && b != 0)
{
if (a > b)
a %= b;
else
b %= a;
}
if (a == 0)
return b;
else
return a;
}
private static int getLCD(int a, int b)
{
//Return the Least Common Denominator between two integers
return (a * b) / getGCD(a, b);
}
public Fraction ToDenominator(int targetDenominator)
{
//Multiply the fraction by a factor to make the denominator
//match the target denominator
Fraction modifiedFraction = this;
//Cannot reduce to smaller denominators
if (targetDenominator < this.Denominator)
return modifiedFraction;
//The target denominator must be a factor of the current denominator
if (targetDenominator % this.Denominator != 0)
return modifiedFraction;
if (this.Denominator != targetDenominator)
{
int factor = targetDenominator / this.Denominator;
modifiedFraction.Denominator = targetDenominator;
modifiedFraction.Numerator *= factor;
}
return modifiedFraction;
}
public Fraction GetReduced()
{
//Reduce the fraction to lowest terms
Fraction modifiedFraction = this;
try
{
//While the numerator and denominator share a greatest common denominator,
//keep dividing both by it
int gcd = 0;
while (Math.Abs(gcd = getGCD(modifiedFraction.Numerator, modifiedFraction.Denominator)) != 1)
{
modifiedFraction.Numerator /= gcd;
modifiedFraction.Denominator /= gcd;
}
//Make sure only a single negative sign is on the numerator
if (modifiedFraction.Denominator < 0)
{
modifiedFraction.Numerator = -this.Numerator;
modifiedFraction.Denominator = -this.Denominator;
}
}
catch (Exception e)
{
Logger.Log($"Failed to reduce fraction ({modifiedFraction}): {e.Message}", true);
}
return modifiedFraction;
}
public Fraction GetReciprocal()
{
//Flip the numerator and the denominator
return new Fraction(this.Denominator, this.Numerator);
}
public static Fraction operator +(Fraction fraction1, Fraction fraction2)
{
//Check if either fraction is zero
if (fraction1.Denominator == 0)
return fraction2;
else if (fraction2.Denominator == 0)
return fraction1;
//Get Least Common Denominator
int lcd = getLCD(fraction1.Denominator, fraction2.Denominator);
//Transform the fractions
fraction1 = fraction1.ToDenominator(lcd);
fraction2 = fraction2.ToDenominator(lcd);
//Return sum
return new Fraction(fraction1.Numerator + fraction2.Numerator, lcd).GetReduced();
}
public static Fraction operator -(Fraction fraction1, Fraction fraction2)
{
//Get Least Common Denominator
int lcd = getLCD(fraction1.Denominator, fraction2.Denominator);
//Transform the fractions
fraction1 = fraction1.ToDenominator(lcd);
fraction2 = fraction2.ToDenominator(lcd);
//Return difference
return new Fraction(fraction1.Numerator - fraction2.Numerator, lcd).GetReduced();
}
public static Fraction operator *(Fraction fract, int multi)
{
int numerator = fract.Numerator * multi;
int denomenator = fract.Denominator;
return new Fraction(numerator, denomenator).GetReduced();
}
public static Fraction operator *(Fraction fract, float multi)
{
int numerator = (fract.Numerator * multi).RoundToInt();
int denomenator = fract.Denominator;
return new Fraction(numerator, denomenator).GetReduced();
}
public static Fraction operator *(Fraction fraction1, Fraction fraction2)
{
int numerator = fraction1.Numerator * fraction2.Numerator;
int denomenator = fraction1.Denominator * fraction2.Denominator;
return new Fraction(numerator, denomenator).GetReduced();
}
public static Fraction operator /(Fraction fraction1, Fraction fraction2)
{
return new Fraction(fraction1 * fraction2.GetReciprocal()).GetReduced();
}
public double ToDouble()
{
return (double)this.Numerator / this.Denominator;
}
public override string ToString()
{
return Numerator + "/" + Denominator;
}
public float GetFloat()
{
if (Denominator < 1) // Avoid div by zero
return 0f;
return (float)Numerator / (float)Denominator;
}
public long GetLong()
{
return (long)Numerator / (long)Denominator;
}
public string GetString()
{
return ((float)Numerator / Denominator).ToString();
}
}
}

View File

@@ -1,28 +0,0 @@
using Flowframes.IO;
using System;
using System.Collections.Generic;
namespace Flowframes.Data
{
class Implementations
{
public static AI rifeCuda = new AI("RIFE_CUDA", "RIFE", "CUDA/Pytorch Implementation of RIFE (Nvidia Only!)", "rife-cuda", new int[] { 2, 4, 8, 16 });
public static AI rifeNcnn = new AI("RIFE_NCNN", "RIFE (NCNN)", "Vulkan/NCNN Implementation of RIFE", "rife-ncnn", new int[] { 2, 4, 8 }, true);
public static AI flavrCuda = new AI("FLAVR_CUDA", "FLAVR", "Experimental Pytorch Implementation of FLAVR (Nvidia Only!)", "flavr-cuda", new int[] { 2, 4, 8 });
public static AI dainNcnn = new AI("DAIN_NCNN", "DAIN (NCNN)", "Vulkan/NCNN Implementation of DAIN", "dain-ncnn", new int[] { 2, 3, 4, 5, 6, 7, 8 });
public static AI xvfiCuda = new AI("XVFI_CUDA", "XVFI", "CUDA/Pytorch Implementation of XVFI (Nvidia Only!)", "xvfi-cuda", new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
public static List<AI> networks = new List<AI> { rifeCuda, rifeNcnn, flavrCuda, dainNcnn, xvfiCuda };
public static AI GetAi (string aiName)
{
foreach(AI ai in networks)
{
if (ai.aiName == aiName)
return ai;
}
return networks[0];
}
}
}

View File

@@ -1,252 +0,0 @@
using Flowframes.Media;
using Flowframes.Data;
using Flowframes.IO;
using Flowframes.Main;
using Flowframes.MiscUtils;
using Flowframes.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualBasic.Logging;
namespace Flowframes
{
public class InterpSettings
{
public string inPath;
public string outPath;
public AI ai;
public Fraction inFps;
public Fraction inFpsDetected;
public Fraction outFps;
public float interpFactor;
public Interpolate.OutMode outMode;
public ModelCollection.ModelInfo model;
public string tempFolder;
public string framesFolder;
public string interpFolder;
public bool inputIsFrames;
public Size inputResolution;
public Size scaledResolution;
public bool alpha;
public bool stepByStep;
public string framesExt;
public string interpExt;
public InterpSettings(string inPathArg, string outPathArg, AI aiArg, Fraction inFpsDetectedArg, Fraction inFpsArg, int interpFactorArg, Interpolate.OutMode outModeArg, ModelCollection.ModelInfo modelArg)
{
inPath = inPathArg;
outPath = outPathArg;
ai = aiArg;
inFpsDetected = inFpsDetectedArg;
inFps = inFpsArg;
interpFactor = interpFactorArg;
outFps = inFpsArg * interpFactorArg;
outMode = outModeArg;
model = modelArg;
alpha = false;
stepByStep = false;
framesExt = "";
interpExt = "";
try
{
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
inputIsFrames = IOUtils.IsPathDirectory(inPath);
}
catch
{
Logger.Log("Tried to create InterpSettings struct without an inpath. Can't set tempFolder, framesFolder and interpFolder.", true);
tempFolder = "";
framesFolder = "";
interpFolder = "";
inputIsFrames = false;
}
inputResolution = new Size(0, 0);
scaledResolution = new Size(0, 0);
RefreshExtensions();
}
public InterpSettings (string serializedData)
{
inPath = "";
outPath = "";
ai = Implementations.networks[0];
inFpsDetected = new Fraction();
inFps = new Fraction();
interpFactor = 0;
outFps = new Fraction();
outMode = Interpolate.OutMode.VidMp4;
model = null;
alpha = false;
stepByStep = false;
inputResolution = new Size(0, 0);
scaledResolution = new Size(0, 0);
framesExt = "";
interpExt = "";
Dictionary<string, string> entries = new Dictionary<string, string>();
foreach(string line in serializedData.SplitIntoLines())
{
if (line.Length < 3) continue;
string[] keyValuePair = line.Split('|');
entries.Add(keyValuePair[0], keyValuePair[1]);
}
foreach (KeyValuePair<string, string> entry in entries)
{
switch (entry.Key)
{
case "INPATH": inPath = entry.Value; break;
case "OUTPATH": outPath = entry.Value; break;
case "AI": ai = Implementations.GetAi(entry.Value); break;
case "INFPSDETECTED": inFpsDetected = new Fraction(entry.Value); break;
case "INFPS": inFps = new Fraction(entry.Value); break;
case "OUTFPS": outFps = new Fraction(entry.Value); break;
case "INTERPFACTOR": interpFactor = float.Parse(entry.Value); break;
case "OUTMODE": outMode = (Interpolate.OutMode)Enum.Parse(typeof(Interpolate.OutMode), entry.Value); break;
case "MODEL": model = AiModels.GetModelByName(ai, entry.Value); break;
case "INPUTRES": inputResolution = FormatUtils.ParseSize(entry.Value); break;
case "OUTPUTRES": scaledResolution = FormatUtils.ParseSize(entry.Value); break;
case "ALPHA": alpha = bool.Parse(entry.Value); break;
case "STEPBYSTEP": stepByStep = bool.Parse(entry.Value); break;
case "FRAMESEXT": framesExt = entry.Value; break;
case "INTERPEXT": interpExt = entry.Value; break;
}
}
try
{
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
inputIsFrames = IOUtils.IsPathDirectory(inPath);
}
catch
{
Logger.Log("Tried to create InterpSettings struct without an inpath. Can't set tempFolder, framesFolder and interpFolder.", true);
tempFolder = "";
framesFolder = "";
interpFolder = "";
inputIsFrames = false;
}
RefreshExtensions();
}
public void UpdatePaths (string inPathArg, string outPathArg)
{
inPath = inPathArg;
outPath = outPathArg;
tempFolder = InterpolateUtils.GetTempFolderLoc(inPath, outPath);
framesFolder = Path.Combine(tempFolder, Paths.framesDir);
interpFolder = Path.Combine(tempFolder, Paths.interpDir);
inputIsFrames = IOUtils.IsPathDirectory(inPath);
}
public async Task<Size> GetInputRes()
{
await RefreshResolutions();
return inputResolution;
}
public async Task<Size> GetScaledRes()
{
await RefreshResolutions();
return scaledResolution;
}
async Task RefreshResolutions ()
{
if (inputResolution.IsEmpty || scaledResolution.IsEmpty)
{
inputResolution = await GetMediaResolutionCached.GetSizeAsync(inPath);
scaledResolution = InterpolateUtils.GetOutputResolution(inputResolution, false, true);
}
}
public void RefreshAlpha ()
{
try
{
bool alphaModel = model.supportsAlpha;
bool outputSupportsAlpha = (outMode == Interpolate.OutMode.ImgPng || outMode == Interpolate.OutMode.VidGif);
string ext = inputIsFrames ? Path.GetExtension(IOUtils.GetFilesSorted(inPath).First()).ToLower() : Path.GetExtension(inPath).ToLower();
alpha = (alphaModel && outputSupportsAlpha && (ext == ".gif" || ext == ".png" || ext == ".apng"));
Logger.Log($"RefreshAlpha: model.supportsAlpha = {alphaModel} - outputSupportsAlpha = {outputSupportsAlpha} - " +
$"input ext: {ext} => alpha = {alpha}", true);
}
catch (Exception e)
{
Logger.Log("RefreshAlpha Error: " + e.Message, true);
alpha = false;
}
}
public enum FrameType { Import, Interp, Both };
public void RefreshExtensions(FrameType type = FrameType.Both)
{
bool pngOutput = outMode == Interpolate.OutMode.ImgPng;
bool aviHqChroma = outMode == Interpolate.OutMode.VidAvi && Config.Get(Config.Key.aviColors) != "yuv420p";
bool proresHqChroma = outMode == Interpolate.OutMode.VidProRes && Config.GetInt(Config.Key.proResProfile) > 3;
bool forceHqChroma = pngOutput || aviHqChroma || proresHqChroma;
Logger.Log($"RefreshExtensions({type}) - alpha = {alpha} pngOutput = {pngOutput} aviHqChroma = {aviHqChroma} proresHqChroma = {proresHqChroma}", true);
if (alpha || forceHqChroma) // Force PNG if alpha is enabled, or output is not 4:2:0 subsampled
{
if(type == FrameType.Both || type == FrameType.Import)
framesExt = ".png";
if (type == FrameType.Both || type == FrameType.Interp)
interpExt = ".png";
}
else
{
if (type == FrameType.Both || type == FrameType.Import)
framesExt = (Config.GetBool(Config.Key.jpegFrames) ? ".jpg" : ".png");
if (type == FrameType.Both || type == FrameType.Interp)
interpExt = (Config.GetBool(Config.Key.jpegInterp) ? ".jpg" : ".png");
}
Logger.Log($"RefreshExtensions - Using '{framesExt}' for imported frames, using '{interpExt}' for interpolated frames", true);
}
public string Serialize ()
{
string s = $"INPATH|{inPath}\n";
s += $"OUTPATH|{outPath}\n";
s += $"AI|{ai.aiName}\n";
s += $"INFPSDETECTED|{inFpsDetected}\n";
s += $"INFPS|{inFps}\n";
s += $"OUTFPS|{outFps}\n";
s += $"INTERPFACTOR|{interpFactor}\n";
s += $"OUTMODE|{outMode}\n";
s += $"MODEL|{model.name}\n";
s += $"INPUTRES|{inputResolution.Width}x{inputResolution.Height}\n";
s += $"OUTPUTRES|{scaledResolution.Width}x{scaledResolution.Height}\n";
s += $"ALPHA|{alpha}\n";
s += $"STEPBYSTEP|{stepByStep}\n";
s += $"FRAMESEXT|{framesExt}\n";
s += $"INTERPEXT|{interpExt}\n";
return s;
}
}
}

View File

@@ -1,63 +0,0 @@
using Flowframes.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
namespace Flowframes.Data
{
public class ModelCollection
{
public AI ai;
public List<ModelInfo> models;
public class ModelInfo
{
public AI ai;
public string name;
public string desc;
public string dir;
public bool supportsAlpha;
public bool isDefault;
public ModelInfo(AI ai, string name, string desc, string dir, bool supportsAlpha, bool isDefault)
{
this.ai = ai;
this.name = name;
this.desc = desc;
this.dir = dir;
this.supportsAlpha = supportsAlpha;
this.isDefault = isDefault;
}
public string GetUiString()
{
return $"{name} - {desc}{(supportsAlpha ? " (Supports Transparency)" : "")}{(isDefault ? " (Recommended)" : "")}";
}
public override string ToString()
{
return $"{name} - {desc} ({dir}){(supportsAlpha ? " (Supports Transparency)" : "")}{(isDefault ? " (Recommended)" : "")}";
}
}
public ModelCollection(AI ai, string jsonContentOrPath)
{
if (IOUtils.IsPathValid(jsonContentOrPath) && File.Exists(jsonContentOrPath))
jsonContentOrPath = File.ReadAllText(jsonContentOrPath);
models = new List<ModelInfo>();
dynamic data = JsonConvert.DeserializeObject(jsonContentOrPath);
foreach (var item in data)
{
bool alpha = false;
bool.TryParse((string)item.supportsAlpha, out alpha);
bool def = false;
bool.TryParse((string)item.isDefault, out def);
models.Add(new ModelInfo(ai, (string)item.name, (string)item.desc, (string)item.dir, alpha, def));
}
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
class Padding
{
public const int inputFrames = 9;
public const int inputFramesRenamed = 8;
public const int interpFrames = 8;
}
}

View File

@@ -1,75 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
namespace Flowframes.IO
{
class Paths
{
public const string framesDir = "frames";
public const string interpDir = "interp";
public const string chunksDir = "vchunks";
public const string resumeDir = "resumedata";
public const string scenesDir = "scenes";
public const string symlinksSuffix = "-symlinks";
public const string alphaSuffix = "-a";
public const string prevSuffix = "-previous";
public const string fpsLimitSuffix = "-fpsLimit";
public const string backupSuffix = ".bak";
public const string frameOrderPrefix = "frames";
public const string audioSuffix = "audio";
public const string audioVideoDir = "av";
public const string licensesDir = "licenses";
public static string GetFrameOrderFilename(float factor)
{
return $"{frameOrderPrefix}-{factor.ToStringDot()}x.ini";
}
public static string GetFrameOrderFilenameChunk (int from, int to)
{
return $"{frameOrderPrefix}-chunk-{from}-{to}.ini";
}
public static string GetExe()
{
return System.Reflection.Assembly.GetEntryAssembly().GetName().CodeBase.Replace("file:///", "");
}
public static string GetExeDir()
{
return AppDomain.CurrentDomain.BaseDirectory;
}
public static string GetVerPath()
{
return Path.Combine(GetDataPath(), "ver.ini");
}
public static string GetDataPath ()
{
string path = Path.Combine(GetExeDir(), "FlowframesData");
Directory.CreateDirectory(path);
return path;
}
public static string GetPkgPath()
{
string path = Path.Combine(GetDataPath(), "pkgs");
Directory.CreateDirectory(path);
return path;
}
public static string GetLogPath()
{
string path = Path.Combine(GetDataPath(), "logs");
Directory.CreateDirectory(path);
return path;
}
}
}

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
class PseudoUniqueFile
{
public string path;
public long filesize;
public PseudoUniqueFile (string pathArg, long filesizeArg)
{
path = pathArg;
filesize = filesizeArg;
}
}
}

View File

@@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flowframes.Data
{
public struct ResumeState
{
public bool autoEncode;
public int interpolatedInputFrames;
public ResumeState (bool autoEncArg, int lastInterpInFrameArg)
{
autoEncode = autoEncArg;
interpolatedInputFrames = lastInterpInFrameArg;
}
public ResumeState(string serializedData)
{
autoEncode = false;
interpolatedInputFrames = 0;
Dictionary<string, string> entries = new Dictionary<string, string>();
foreach (string line in serializedData.SplitIntoLines())
{
if (line.Length < 3) continue;
string[] keyValuePair = line.Split('|');
entries.Add(keyValuePair[0], keyValuePair[1]);
}
foreach (KeyValuePair<string, string> entry in entries)
{
switch (entry.Key)
{
case "AUTOENC": autoEncode = bool.Parse(entry.Value); break;
case "INTERPOLATEDINPUTFRAMES": interpolatedInputFrames = entry.Value.GetInt(); break;
}
}
}
public override string ToString ()
{
string s = $"AUTOENC|{autoEncode}\n";
if (!autoEncode)
{
s += $"INTERPOLATEDINPUTFRAMES|{interpolatedInputFrames}";
}
return s;
}
}
}

View File

@@ -1,20 +0,0 @@
using System.Globalization;
namespace Flowframes.Data
{
class SubtitleTrack
{
public int streamIndex;
public string lang;
//public string langFriendly;
public string encoding;
public SubtitleTrack(int streamNum, string metaStr, string encodingStr)
{
streamIndex = streamNum;
lang = metaStr.Trim().Replace("_", ".").Replace(" ", ".");
//langFriendly = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaStr.ToLower().Trim().Replace("_", ".").Replace(" ", "."));
encoding = encodingStr.Trim();
}
}
}

View File

@@ -1,122 +0,0 @@
using Flowframes.IO;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Flowframes.Data
{
class VidExtraData
{
// Color
public string colorSpace = "";
public string colorRange = "";
public string colorTransfer = "";
public string colorPrimaries = "";
// Aspect Ratio
public string displayRatio = "";
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" };
public VidExtraData(string ffprobeOutput)
{
string[] lines = ffprobeOutput.SplitIntoLines();
if (!Config.GetBool(Config.Key.keepColorSpace, true))
return;
foreach (string line in lines)
{
if (line.Contains("color_range"))
{
colorRange = line.Split('=').LastOrDefault();
continue;
}
if (line.Contains("color_space"))
{
colorSpace = line.Split('=').LastOrDefault();
continue;
}
if (line.Contains("color_transfer"))
{
colorTransfer = line.Split('=').LastOrDefault();
continue;
}
if (line.Contains("color_primaries"))
{
colorPrimaries = line.Split('=').LastOrDefault();
continue;
}
if (line.Contains("display_aspect_ratio") && Config.GetBool(Config.Key.keepAspectRatio, true))
{
displayRatio = line.Split('=').LastOrDefault();
continue;
}
}
if (!validColorSpaces.Contains(colorSpace.Trim()))
{
Logger.Log($"Warning: Color Space '{colorSpace.Trim()}' not valid.", true, false, "ffmpeg");
colorSpace = "";
}
if (colorRange.Trim() == "unknown")
colorRange = "";
if (!validColorSpaces.Contains(colorTransfer.Trim()))
{
Logger.Log($"Warning: Color Transfer '{colorTransfer.Trim()}' not valid.", true, false, "ffmpeg");
colorTransfer = "";
}
else
{
colorTransfer = colorTransfer.Replace("bt470bg", "gamma28").Replace("bt470m", "gamma28"); // https://forum.videohelp.com/threads/394596-Color-Matrix
}
if (!validColorSpaces.Contains(colorPrimaries.Trim()))
{
Logger.Log($"Warning: Color Primaries '{colorPrimaries.Trim()}' not valid.", true, false, "ffmpeg");
colorPrimaries = "";
}
}
public bool HasAnyValues ()
{
if (!string.IsNullOrWhiteSpace(colorSpace))
return true;
if (!string.IsNullOrWhiteSpace(colorRange))
return true;
if (!string.IsNullOrWhiteSpace(colorTransfer))
return true;
if (!string.IsNullOrWhiteSpace(colorPrimaries))
return true;
return false;
}
public bool HasAllValues()
{
if (string.IsNullOrWhiteSpace(colorSpace))
return false;
if (string.IsNullOrWhiteSpace(colorRange))
return false;
if (string.IsNullOrWhiteSpace(colorTransfer))
return false;
if (string.IsNullOrWhiteSpace(colorPrimaries))
return false;
return true;
}
}
}