Files
flowframes/Code/Data/VidExtraData.cs

124 lines
3.9 KiB
C#
Raw Normal View History

using Flowframes.IO;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Flowframes.Data
{
2021-05-07 23:39:52 +02:00
class VidExtraData
{
2021-05-07 23:39:52 +02:00
// Color
public string colorSpace = "";
public string colorRange = "";
public string colorTransfer = "";
public string colorPrimaries = "";
2021-05-07 23:39:52 +02:00
// Aspect Ratio
public string displayRatio = "";
2021-05-11 15:15:52 +02:00
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" };
2021-05-07 23:39:52 +02:00
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;
}
2021-05-07 23:39:52 +02:00
if (line.Contains("display_aspect_ratio") && Config.GetBool(Config.Key.keepAspectRatio, true))
2021-05-07 23:39:52 +02:00
{
displayRatio = line.Split('=').LastOrDefault();
continue;
}
}
2021-05-11 15:15:52 +02:00
if (!validColorSpaces.Contains(colorSpace.Trim()))
{
Logger.Log($"Warning: Color Space '{colorSpace.Trim()}' not valid.", true, false, "ffmpeg");
colorSpace = "";
2021-05-11 15:15:52 +02:00
}
if (colorRange.Trim() == "unknown")
colorRange = "";
2021-05-11 15:15:52 +02:00
if (!validColorSpaces.Contains(colorTransfer.Trim()))
{
Logger.Log($"Warning: Color Transfer '{colorTransfer.Trim()}' not valid.", true, false, "ffmpeg");
colorTransfer = "";
2021-05-11 15:15:52 +02:00
}
else
{
Logger.Log($"Warning: Using 'gamma28' instead of '{colorTransfer.Trim()}'.", true, false, "ffmpeg");
colorTransfer = colorTransfer.Replace("bt470bg", "gamma28"); // https://forum.videohelp.com/threads/394596-Color-Matrix
}
2021-05-11 15:15:52 +02:00
if (!validColorSpaces.Contains(colorPrimaries.Trim()))
{
Logger.Log($"Warning: Color Primaries '{colorPrimaries.Trim()}' not valid.", true, false, "ffmpeg");
colorPrimaries = "";
2021-05-11 15:15:52 +02:00
}
}
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;
}
}
}