Skip to content

Commit 3644409

Browse files
committed
Fixed PSNR+SSIM being broken, fixed issues with image sequences not working with some utils
1 parent fb54cd1 commit 3644409

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

ff-utils-winforms/Data/MediaFile.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public MediaFile(string path, bool requestFpsInputIfUnset = true)
5656
if (FileCount < 1)
5757
return;
5858

59-
Logger.Log($"MediaFile ctor");
60-
6159
if(requestFpsInputIfUnset && InputRate == null)
6260
{
6361
PromptForm form = new PromptForm("Enter Frame Rate", $"Please enter a frame rate to use for the image sequence '{Name.Trunc(80)}'.", "30");

ff-utils-winforms/Extensions/ExtensionMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ public static bool IsConcatFile(this string filePath)
254254
public static string GetConcStr (this string filePath, int rate = -1)
255255
{
256256
string rateStr = rate >= 0 ? $"-r {rate} " : "";
257-
return filePath.IsConcatFile() ? $"{rateStr}-safe 0 -f concat" : "";
257+
return filePath.IsConcatFile() ? $"{rateStr}-safe 0 -f concat " : "";
258258
}
259259

260260
public static string GetFfmpegInputArg(this string filePath)
261261
{
262-
return "-i " + (filePath.IsConcatFile() ? filePath.GetConcStr() : "") + filePath.Wrap();
262+
return $"{(filePath.IsConcatFile() ? filePath.GetConcStr() : "")} -i {filePath.Wrap()}";
263263
}
264264

265265
public static int CountOccurences (this List<string> list, string stringToLookFor)

ff-utils-winforms/Media/FfmpegOutputHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void UpdateFfmpegProgress(string ffmpegTime)
103103
if (TrackList.current == null && overrideTargetDurationMs < 0)
104104
return;
105105

106-
long currInDuration = overrideTargetDurationMs > 0 ? overrideTargetDurationMs : TrackList.current.File.DurationMs;
106+
long currInDuration = overrideTargetDurationMs > 0 ? overrideTargetDurationMs : (TrackList.current != null ? TrackList.current.File.DurationMs : 0);
107107

108108
if (currInDuration < 1)
109109
{
@@ -124,7 +124,7 @@ static void UpdateFfmpegProgress(string ffmpegTime)
124124

125125
static bool HideMessage(string msg)
126126
{
127-
string[] hiddenMsgs = new string[] { "can produce invalid output", "pixel format", "provided invalid", "Non-monotonous" };
127+
string[] hiddenMsgs = new string[] { "can produce invalid output", "pixel format", "provided invalid", "Non-monotonous", "not enough frames to estimate rate", "invalid dropping", "message repeated" };
128128

129129
foreach (string str in hiddenMsgs)
130130
if (msg.MatchesWildcard($"*{str}*"))

ff-utils-winforms/UI/Tasks/UtilGetMetrics.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static async Task Run(bool fixRate = true)
7272
Logger.Log("Calculating SSIM...");
7373
string select = subsample > 1 ? $"select=not(mod(n-1\\,{subsample}))," : "";
7474
string args = $"{r} {vidLq.GetFfmpegInputArg()} {r} {vidHq.GetFfmpegInputArg()} -filter_complex {f}{select}ssim -f null -";
75-
string output = await AvProcess.GetFfmpegOutputAsync(args, false, true);
75+
string output = await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine, "info", true, true);
7676
List<string> ssimLines = output.SplitIntoLines().Where(x => x.Contains("] SSIM ")).ToList();
7777

7878
if (ssimLines.Count < 1)
@@ -82,7 +82,7 @@ public static async Task Run(bool fixRate = true)
8282
else
8383
{
8484
string scoreStr = ssimLines[0].Split(" All:").LastOrDefault();
85-
Logger.Log($"SSIM Score: {scoreStr}", false, ReplaceLastLine());
85+
Logger.Log($"SSIM Score: {scoreStr.Replace("inf", "Infinite")}", false, ReplaceLastLine());
8686
}
8787
}
8888

@@ -91,7 +91,7 @@ public static async Task Run(bool fixRate = true)
9191
Logger.Log("Calculating PSNR...");
9292
string select = subsample > 1 ? $"select=not(mod(n-1\\,{subsample}))," : "";
9393
string args = $"{r} {vidLq.GetFfmpegInputArg()} {r} {vidHq.GetFfmpegInputArg()} -filter_complex {f}{select}psnr -f null -";
94-
string output = await AvProcess.GetFfmpegOutputAsync(args, false, true);
94+
string output = await AvProcess.RunFfmpeg(args, AvProcess.LogMode.OnlyLastLine, "info", true, true);
9595
List<string> psnrLines = output.SplitIntoLines().Where(x => x.Contains("] PSNR ")).ToList();
9696

9797
if (psnrLines.Count < 1)
@@ -101,7 +101,7 @@ public static async Task Run(bool fixRate = true)
101101
else
102102
{
103103
string scoreStr = psnrLines[0].Split("average:").LastOrDefault().Split(' ')[0];
104-
Logger.Log($"PSNR Score: {scoreStr}", false, ReplaceLastLine());
104+
Logger.Log($"PSNR Score: {scoreStr.Replace("inf", "Infinite")}", false, ReplaceLastLine());
105105
}
106106
}
107107
}

0 commit comments

Comments
 (0)