1
mirror of https://github.com/n00mkrad/flowframes synced 2024-09-29 14:38:03 +02:00

Fix consecutive scene change frames

This commit is contained in:
N00MKRAD 2020-12-23 00:07:06 +01:00
parent a9592c02be
commit 9b20e74a5d
3 changed files with 30 additions and 0 deletions

View File

@ -1,5 +1,6 @@
using Flowframes.Data;
using Flowframes.IO;
using Flowframes.Main;
using System;
using System.Drawing;
using System.Globalization;

View File

@ -83,6 +83,7 @@ namespace Flowframes
Program.mainForm.SetStatus("Extracting frames from video...");
await FFmpegCommands.VideoToFrames(inPath, outPath, Config.GetInt("dedupMode") == 2, false, Utils.GetOutputResolution(inPath, true));
Utils.FixConsecutiveSceneFrames(Path.Combine(current.tempFolder, Paths.scenesDir), current.framesFolder);
if (extractAudio)
{
@ -90,6 +91,7 @@ namespace Flowframes
if (audioFile != null && !File.Exists(audioFile))
await FFmpegCommands.ExtractAudio(inPath, audioFile);
}
if (!canceled && Config.GetBool("enableLoop") && Config.GetInt("timingMode") != 1)
{
string lastFrame = IOUtils.GetHighestFrameNumPath(outPath);

View File

@ -5,6 +5,7 @@ using Flowframes.OS;
using Flowframes.UI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
@ -315,5 +316,31 @@ namespace Flowframes.Main
int b = a + 2; // Larger multiple
return (n - a > b - n) ? b : a; // Return of closest of two
}
public static void FixConsecutiveSceneFrames (string sceneFramesPath, string sourceFramesPath)
{
Stopwatch sw = new Stopwatch();
List<string> sceneFrames = IOUtils.GetFilesSorted(sceneFramesPath).Select(x => Path.GetFileNameWithoutExtension(x)).ToList();
List<string> sourceFrames = IOUtils.GetFilesSorted(sourceFramesPath).Select(x => Path.GetFileNameWithoutExtension(x)).ToList();
List<string> sceneFramesToDelete = new List<string>();
foreach(string scnFrame in sceneFrames)
{
if (sceneFramesToDelete.Contains(scnFrame))
continue;
int sourceIndexForScnFrame = sourceFrames.IndexOf(scnFrame); // Get source index of scene frame
string followingFrame = sourceFrames[sourceIndexForScnFrame + 1]; // Get filename/timestamp of the next source frame
if (sceneFrames.Contains(followingFrame)) // If next source frame is in scene folder, add to deletion list
sceneFramesToDelete.Add(followingFrame);
}
foreach (string frame in sceneFramesToDelete)
IOUtils.TryDeleteIfExists(Path.Combine(sceneFramesPath, frame + ".png"));
Logger.Log("Ran FixConsecutiveSceneFrames in " + FormatUtils.Time(sw.Elapsed));
}
}
}