From fc53f5ea6bd27a5d0a9d57d46d10e6d129f76403 Mon Sep 17 00:00:00 2001 From: Linrador <68631622+Linrador@users.noreply.github.com> Date: Mon, 17 Nov 2025 09:41:46 +0100 Subject: [PATCH] performance updated --- WinFormsApp1/Form1.cs | 89 +++++++------------ .../PublishProfiles/FolderProfile.pubxml.user | 2 +- 2 files changed, 31 insertions(+), 60 deletions(-) diff --git a/WinFormsApp1/Form1.cs b/WinFormsApp1/Form1.cs index 0f2c133..820caf8 100644 --- a/WinFormsApp1/Form1.cs +++ b/WinFormsApp1/Form1.cs @@ -14277,43 +14277,19 @@ namespace WinFormsApp1 { try { - var files = temp_folder!.GetFiles(); - - if (files.Length > 0 && (!generatedImagesMatchVideo(video) || !generatedImagesMatchResolution(video))) + // Einfach alles löschen und einmal komplett neu extrahieren + foreach (var tempFile in temp_folder!.GetFiles()) { - int i = 0; - foreach (FileInfo tempFile in files) - { - if (!scanAIisRunning) return; - - i++; - string filename = System.IO.Path.GetFileNameWithoutExtension(tempFile.Name); - string targetName = System.IO.Path.GetFileNameWithoutExtension(video.Name); - - if (!generatedImageMatchesChosenResolution(tempFile) || - (!filename.Contains(targetName) && !IsFileLocked(tempFile))) - { - await UpdateStatusLabel($"Lösche Bilder... ({i}/{files.Length})"); - await Task.Run(() => tempFile.Delete()); - } - } + if (!scanAIisRunning) return; + if (!IsFileLocked(tempFile)) + tempFile.Delete(); } - List missingFrames = getMissingFrames(video); - if (missingFrames.Count > 0 && isMissingFrames(video)) - { - isExtractingAllFrames = missingFrames.Count != Directory.GetFiles(temp_folder.FullName).Length; - - string label = isExtractingAllFrames ? "Extrahiere alle Einzelbilder..." : $"Extrahiere {missingFrames.Count} Einzelbilder..."; - await UpdateStatusLabel(label); - - if (isExtractingAllFrames) - await extractAllFrames(video); - else - await extractSingleFrames(video, missingFrames); - } + isExtractingAllFrames = true; + await UpdateStatusLabel("Extrahiere alle Einzelbilder..."); + await extractAllFrames(video); } - catch (System.Exception ex) + catch (Exception ex) { await Task.Run(() => KillFFMPEGProcesses()); MessageBox.Show(ex.Message, "extractFrames"); @@ -14321,6 +14297,7 @@ namespace WinFormsApp1 } + private async Task extractSingleFrames(FileInfo video, List missingFrames) { SemaphoreSlim throttler = new SemaphoreSlim(4); // max 4 gleichzeitige Prozesse @@ -14342,7 +14319,7 @@ namespace WinFormsApp1 System.TimeSpan time = System.TimeSpan.FromSeconds(seconds - 1); using Process proc = new Process(); proc.StartInfo.FileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ffmpeg.exe"); - proc.StartInfo.Arguments = $"-y -ss {time:hh\\:mm\\:ss} -i \"{video.FullName}\" -vf fps=1 -frames:v 1 -q:v 1 -s {chosenResolution.Width}x{chosenResolution.Height} \"{filename}\""; + proc.StartInfo.Arguments = $"-y -ss {time:hh\\:mm\\:ss} -i \"{video.FullName}\" -vf fps=0.5 -frames:v 1 -q:v 1 -s {chosenResolution.Width}x{chosenResolution.Height} \"{filename}\""; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; @@ -14369,7 +14346,7 @@ namespace WinFormsApp1 proc_ffmpeg.StartInfo.CreateNoWindow = true; proc_ffmpeg.StartInfo.UseShellExecute = false; proc_ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - proc_ffmpeg.StartInfo.Arguments = "-i \"" + video.FullName + "\" -vf fps=1 -q:v 1 -s " + chosenResolution.Width + "x" + chosenResolution.Height + " \"" + System.IO.Path.Combine(temp_folder!.FullName, video.Name + "-%d.jpg") + "\""; + proc_ffmpeg.StartInfo.Arguments = "-i \"" + video.FullName + "\" -vf fps=1 -q:v 5 -s " + chosenResolution.Width + "x" + chosenResolution.Height + " \"" + System.IO.Path.Combine(temp_folder!.FullName, video.Name + "-%d.jpg") + "\""; proc_ffmpeg.Start(); await proc_ffmpeg.WaitForExitAsync(); } @@ -14441,28 +14418,20 @@ namespace WinFormsApp1 { await UpdateStatusLabel("Analysiere Einzelbilder..."); - int batchSize = 1; - for (int i = 0; i < files.Length; i += batchSize) + for (int i = 0; i < files.Length; i++) { if (!scanAIisRunning) break; - var batch = files.Skip(i).Take(batchSize); - var batchResults = await Task.WhenAll(batch.Select(file => - Task.Run(() => - { - var result = nsfwSpy.ClassifyImage(file); - lock (results) - { - results.Add(new NsfwSpyValue(file, result)); - var key = System.IO.Path.GetFileName(file); - if (!analysis.ai.ContainsKey(key)) - analysis.ai[key] = result; - } - return result.PredictedLabel; - }))); + var file = files[i]; + var result = nsfwSpy.ClassifyImage(file); - fileNumber += batchSize; - double progress = 100.0 * Math.Min(fileNumber, fileCount) / fileCount; + results.Add(new NsfwSpyValue(file, result)); + var key = Path.GetFileName(file); + if (!analysis.ai.ContainsKey(key)) + analysis.ai[key] = result; + + fileNumber++; + double progress = 100.0 * fileNumber / fileCount; await UpdateStatusLabel($"Analysiere Einzelbilder... ({Math.Round(progress)}%)"); // Player-Seek gelegentlich @@ -14470,19 +14439,21 @@ namespace WinFormsApp1 { BeginInvoke(() => { - if (WindowState != FormWindowState.Minimized && tabControl1.SelectedTab == tabPage_Editor) + if (WindowState != FormWindowState.Minimized && + tabControl1.SelectedTab == tabPage_Editor) { - flyleafHost_Editor.Player.SeekAccurate(Math.Min(fileNumber, fileCount) * 1000); + flyleafHost_Editor.Player.SeekAccurate( + Math.Min(fileNumber, fileCount) * 1000); } }); } - // UI-Label (nur einmal pro Batch aktualisieren) - var lastLabel = batchResults.LastOrDefault(); - if (lastLabel != null) + // *** UI-Label hier aktualisieren *** + var label = result.PredictedLabel; + if (!string.IsNullOrEmpty(label)) { await UpdateLabelVisibility(label_Editor_Label, true); - await UpdateLabelText(label_Editor_Label, lastLabel); + await UpdateLabelText(label_Editor_Label, label); } } diff --git a/WinFormsApp1/Properties/PublishProfiles/FolderProfile.pubxml.user b/WinFormsApp1/Properties/PublishProfiles/FolderProfile.pubxml.user index 5bb905a..82d9411 100644 --- a/WinFormsApp1/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/WinFormsApp1/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -2,7 +2,7 @@ - True|2025-11-13T13:18:25.1199192Z||;True|2025-11-10T09:34:59.9819614+01:00||;True|2025-11-10T09:31:52.9893994+01:00||;True|2025-11-07T07:27:09.2818809+01:00||;True|2025-10-28T07:54:43.4835993+01:00||;True|2025-10-28T07:49:48.9691140+01:00||;False|2025-10-28T07:48:40.9934972+01:00||;True|2025-10-28T07:41:40.9364570+01:00||;True|2025-10-28T07:34:30.3216200+01:00||;True|2025-10-27T07:38:02.5307378+01:00||;True|2025-10-24T12:49:33.3476720+02:00||;True|2025-10-24T12:45:56.3409114+02:00||;True|2025-10-24T12:37:06.7053780+02:00||;True|2025-10-24T12:21:52.0779529+02:00||;True|2025-10-24T11:39:34.0711190+02:00||;True|2025-10-24T11:32:06.8084304+02:00||;True|2025-10-24T10:49:19.8451151+02:00||;True|2025-10-24T10:35:58.7368296+02:00||;True|2025-09-22T09:12:21.1738434+02:00||;True|2025-09-22T08:41:28.2063145+02:00||;True|2025-09-11T09:25:26.7487573+02:00||;True|2025-09-05T10:35:16.3265491+02:00||;True|2025-08-13T07:12:45.6489499+02:00||;True|2025-08-08T07:25:38.8935816+02:00||;True|2025-08-08T07:19:07.3835648+02:00||;True|2025-08-06T07:38:46.3420158+02:00||;True|2025-07-16T07:41:34.3557961+02:00||;True|2025-07-15T11:01:48.5566218+02:00||;True|2025-07-07T14:59:37.1240379+02:00||;False|2025-07-07T14:57:39.0613209+02:00||;True|2025-07-07T06:29:53.8853096+02:00||;True|2025-07-06T23:39:21.1017631+02:00||;True|2025-07-06T23:24:37.7792733+02:00||;False|2025-07-06T23:19:52.7135594+02:00||;True|2025-07-06T05:55:51.5281444+02:00||;True|2025-07-06T05:14:26.6590895+02:00||;True|2025-07-06T05:07:43.4335057+02:00||;False|2025-07-06T05:06:42.5442365+02:00||;True|2025-06-27T09:56:34.6625992+02:00||;True|2025-06-27T09:55:33.6399545+02:00||;True|2025-06-27T09:35:44.7409289+02:00||;True|2025-06-27T09:35:11.7955472+02:00||;True|2025-06-27T09:23:44.1433728+02:00||;True|2025-06-27T09:10:34.1084041+02:00||;True|2025-06-27T09:06:49.8646149+02:00||;True|2025-06-27T08:55:00.3110860+02:00||;True|2025-06-27T08:47:18.4476580+02:00||;True|2025-06-11T14:42:56.1622930+02:00||;True|2025-06-11T12:33:26.7419370+02:00||;True|2025-06-11T07:48:58.3963584+02:00||;True|2025-06-11T07:42:53.0277862+02:00||;False|2025-06-11T07:39:31.7470335+02:00||;True|2025-06-03T19:58:59.1868907+02:00||;True|2025-06-03T14:33:55.4389500+02:00||;True|2025-06-03T14:16:34.6963918+02:00||;True|2025-06-03T13:26:58.4834917+02:00||;True|2025-06-02T19:01:22.1305699+02:00||;True|2025-06-02T18:27:48.1629252+02:00||;True|2025-06-02T18:12:01.0339452+02:00||;True|2025-04-25T14:02:07.8958669+02:00||;True|2025-04-24T07:32:32.3215936+02:00||;True|2025-04-23T14:24:27.8051379+02:00||;True|2025-04-22T07:23:33.4961515+02:00||;True|2025-04-22T07:16:30.0019927+02:00||;True|2025-04-17T07:35:19.5003910+02:00||;True|2025-04-16T07:51:44.2105982+02:00||;True|2025-04-15T17:39:22.9354819+02:00||;True|2025-04-15T13:59:38.1491035+02:00||;True|2025-04-15T13:26:09.1911007+02:00||;False|2025-04-15T13:24:05.8283613+02:00||;True|2025-04-15T12:05:53.7928484+02:00||;True|2025-04-14T11:46:19.0213400+02:00||;True|2025-04-14T11:19:57.9110025+02:00||;False|2025-04-14T11:18:49.2970157+02:00||;True|2025-04-14T10:56:19.4313583+02:00||;True|2025-04-14T10:09:57.0472222+02:00||;True|2025-04-11T09:36:58.9281719+02:00||;True|2025-04-11T07:56:15.1143584+02:00||;True|2025-04-10T08:08:20.7849097+02:00||;True|2025-04-09T12:56:06.8510589+02:00||;True|2025-04-09T12:39:21.5101756+02:00||;True|2025-04-09T12:35:02.6306664+02:00||;True|2025-04-09T07:53:00.7307516+02:00||;True|2025-04-07T15:17:24.3233000+02:00||;True|2025-04-04T18:09:18.8844877+02:00||;True|2025-04-03T12:27:18.9922316+02:00||;True|2025-04-03T09:48:50.2518754+02:00||;True|2025-03-31T13:53:07.3910797+02:00||;True|2025-03-31T12:46:18.3638787+02:00||;True|2025-03-31T11:01:06.0182900+02:00||;True|2025-03-31T10:55:30.7399322+02:00||;True|2025-03-31T10:41:08.8975919+02:00||;True|2025-03-31T10:15:29.6315309+02:00||;True|2025-03-31T08:53:20.4511304+02:00||;True|2025-03-29T14:23:34.4407251+01:00||;True|2025-03-29T13:42:06.7348581+01:00||;True|2025-03-28T18:06:37.5932036+01:00||;True|2025-03-27T13:26:13.4721799+01:00||;True|2025-03-27T11:19:53.3525657+01:00||;True|2025-03-27T10:09:53.9177515+01:00||; + True|2025-11-17T08:40:23.3639389Z||;True|2025-11-13T14:18:25.1199192+01:00||;True|2025-11-10T09:34:59.9819614+01:00||;True|2025-11-10T09:31:52.9893994+01:00||;True|2025-11-07T07:27:09.2818809+01:00||;True|2025-10-28T07:54:43.4835993+01:00||;True|2025-10-28T07:49:48.9691140+01:00||;False|2025-10-28T07:48:40.9934972+01:00||;True|2025-10-28T07:41:40.9364570+01:00||;True|2025-10-28T07:34:30.3216200+01:00||;True|2025-10-27T07:38:02.5307378+01:00||;True|2025-10-24T12:49:33.3476720+02:00||;True|2025-10-24T12:45:56.3409114+02:00||;True|2025-10-24T12:37:06.7053780+02:00||;True|2025-10-24T12:21:52.0779529+02:00||;True|2025-10-24T11:39:34.0711190+02:00||;True|2025-10-24T11:32:06.8084304+02:00||;True|2025-10-24T10:49:19.8451151+02:00||;True|2025-10-24T10:35:58.7368296+02:00||;True|2025-09-22T09:12:21.1738434+02:00||;True|2025-09-22T08:41:28.2063145+02:00||;True|2025-09-11T09:25:26.7487573+02:00||;True|2025-09-05T10:35:16.3265491+02:00||;True|2025-08-13T07:12:45.6489499+02:00||;True|2025-08-08T07:25:38.8935816+02:00||;True|2025-08-08T07:19:07.3835648+02:00||;True|2025-08-06T07:38:46.3420158+02:00||;True|2025-07-16T07:41:34.3557961+02:00||;True|2025-07-15T11:01:48.5566218+02:00||;True|2025-07-07T14:59:37.1240379+02:00||;False|2025-07-07T14:57:39.0613209+02:00||;True|2025-07-07T06:29:53.8853096+02:00||;True|2025-07-06T23:39:21.1017631+02:00||;True|2025-07-06T23:24:37.7792733+02:00||;False|2025-07-06T23:19:52.7135594+02:00||;True|2025-07-06T05:55:51.5281444+02:00||;True|2025-07-06T05:14:26.6590895+02:00||;True|2025-07-06T05:07:43.4335057+02:00||;False|2025-07-06T05:06:42.5442365+02:00||;True|2025-06-27T09:56:34.6625992+02:00||;True|2025-06-27T09:55:33.6399545+02:00||;True|2025-06-27T09:35:44.7409289+02:00||;True|2025-06-27T09:35:11.7955472+02:00||;True|2025-06-27T09:23:44.1433728+02:00||;True|2025-06-27T09:10:34.1084041+02:00||;True|2025-06-27T09:06:49.8646149+02:00||;True|2025-06-27T08:55:00.3110860+02:00||;True|2025-06-27T08:47:18.4476580+02:00||;True|2025-06-11T14:42:56.1622930+02:00||;True|2025-06-11T12:33:26.7419370+02:00||;True|2025-06-11T07:48:58.3963584+02:00||;True|2025-06-11T07:42:53.0277862+02:00||;False|2025-06-11T07:39:31.7470335+02:00||;True|2025-06-03T19:58:59.1868907+02:00||;True|2025-06-03T14:33:55.4389500+02:00||;True|2025-06-03T14:16:34.6963918+02:00||;True|2025-06-03T13:26:58.4834917+02:00||;True|2025-06-02T19:01:22.1305699+02:00||;True|2025-06-02T18:27:48.1629252+02:00||;True|2025-06-02T18:12:01.0339452+02:00||;True|2025-04-25T14:02:07.8958669+02:00||;True|2025-04-24T07:32:32.3215936+02:00||;True|2025-04-23T14:24:27.8051379+02:00||;True|2025-04-22T07:23:33.4961515+02:00||;True|2025-04-22T07:16:30.0019927+02:00||;True|2025-04-17T07:35:19.5003910+02:00||;True|2025-04-16T07:51:44.2105982+02:00||;True|2025-04-15T17:39:22.9354819+02:00||;True|2025-04-15T13:59:38.1491035+02:00||;True|2025-04-15T13:26:09.1911007+02:00||;False|2025-04-15T13:24:05.8283613+02:00||;True|2025-04-15T12:05:53.7928484+02:00||;True|2025-04-14T11:46:19.0213400+02:00||;True|2025-04-14T11:19:57.9110025+02:00||;False|2025-04-14T11:18:49.2970157+02:00||;True|2025-04-14T10:56:19.4313583+02:00||;True|2025-04-14T10:09:57.0472222+02:00||;True|2025-04-11T09:36:58.9281719+02:00||;True|2025-04-11T07:56:15.1143584+02:00||;True|2025-04-10T08:08:20.7849097+02:00||;True|2025-04-09T12:56:06.8510589+02:00||;True|2025-04-09T12:39:21.5101756+02:00||;True|2025-04-09T12:35:02.6306664+02:00||;True|2025-04-09T07:53:00.7307516+02:00||;True|2025-04-07T15:17:24.3233000+02:00||;True|2025-04-04T18:09:18.8844877+02:00||;True|2025-04-03T12:27:18.9922316+02:00||;True|2025-04-03T09:48:50.2518754+02:00||;True|2025-03-31T13:53:07.3910797+02:00||;True|2025-03-31T12:46:18.3638787+02:00||;True|2025-03-31T11:01:06.0182900+02:00||;True|2025-03-31T10:55:30.7399322+02:00||;True|2025-03-31T10:41:08.8975919+02:00||;True|2025-03-31T10:15:29.6315309+02:00||;True|2025-03-31T08:53:20.4511304+02:00||;True|2025-03-29T14:23:34.4407251+01:00||;True|2025-03-29T13:42:06.7348581+01:00||;True|2025-03-28T18:06:37.5932036+01:00||;True|2025-03-27T13:26:13.4721799+01:00||;True|2025-03-27T11:19:53.3525657+01:00||; \ No newline at end of file