From e211ad34ab4179a26c9b1bb24655a52c58ea0e55 Mon Sep 17 00:00:00 2001 From: Linrador <68631622+Linrador@users.noreply.github.com> Date: Thu, 11 Jun 2026 08:21:00 +0200 Subject: [PATCH] bugfixes --- backend/analyze.go | 33 +++++++++++++++++---------------- backend/assets_generate.go | 8 ++++++-- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/backend/analyze.go b/backend/analyze.go index 7d1843d..34f0820 100644 --- a/backend/analyze.go +++ b/backend/analyze.go @@ -965,7 +965,7 @@ func recordAnalyzeVideo(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(r.Context(), 30*time.Minute) defer cancel() - hits, err := analyzeVideoFromFrames(ctx, outPath) + hits, analyzeStartedAtMs, analyzeTotalFrames, err := analyzeVideoFromFrames(ctx, outPath) if err != nil { logAnalyzeError("analyze-frames", file, outPath, err) @@ -979,6 +979,10 @@ func recordAnalyzeVideo(w http.ResponseWriter, r *http.Request) { return } + // Wichtig: publishAnalysisFinished erst NACH writeVideoAIForFile feuern, + // damit refreshDoneMetaForFile im Frontend das Rating bereits in der Datei vorfindet. + defer publishAnalysisFinished(analyzeStartedAtMs, analyzeTotalFrames, file, "Analyse abgeschlossen") + appLogf("🧪 [analyze] hits file=%q count=%d", file, len(hits)) durationSec, derr := durationSecondsForAnalyze(ctx, outPath) @@ -1617,7 +1621,7 @@ func appendHighlightHitsFromPrediction( return append(hits, next...) } -func analyzeVideoFromFrames(ctx context.Context, outPath string) ([]analyzeHit, error) { +func analyzeVideoFromFrames(ctx context.Context, outPath string) ([]analyzeHit, int64, int, error) { return analyzeVideoFromFramesForGoal(ctx, outPath) } @@ -1743,9 +1747,9 @@ func analyzeGlobalPercentMessageFromCurrent(current int, total int) string { func analyzeVideoFromFramesForGoal( ctx context.Context, outPath string, -) (highlightHits []analyzeHit, err error) { +) (highlightHits []analyzeHit, startedAtMs int64, totalFrames int, err error) { file := filepath.Base(strings.TrimSpace(outPath)) - startedAtMs := publishAnalysisStarted(file, analyzeProgressTotal, "Analyse 0%") + startedAtMs = publishAnalysisStarted(file, analyzeProgressTotal, "Analyse 0%") publishAnalyzeExtractProgress( startedAtMs, @@ -1756,19 +1760,19 @@ func analyzeVideoFromFramesForGoal( if err := ctx.Err(); err != nil { publishAnalysisError(startedAtMs, file, "Analyse abgebrochen", err) - return nil, err + return nil, startedAtMs, 0, err } durationSec, _ := durationSecondsForAnalyze(ctx, outPath) if err := ctx.Err(); err != nil { publishAnalysisError(startedAtMs, file, "Analyse abgebrochen", err) - return nil, err + return nil, startedAtMs, 0, err } if durationSec <= 0 { err := appErrorf("videolänge konnte nicht bestimmt werden") publishAnalysisError(startedAtMs, file, "Analyse fehlgeschlagen", err) - return nil, err + return nil, startedAtMs, 0, err } publishPercentRange := func(lastPercent *int, nextPercent int, current int, total int, extractPhase bool) { @@ -1827,14 +1831,14 @@ func analyzeVideoFromFramesForGoal( *lastPercent = nextPercent } - failCancelled := func() ([]analyzeHit, error) { + failCancelled := func() ([]analyzeHit, int64, int, error) { err := ctx.Err() if err == nil { err = context.Canceled } publishAnalysisError(startedAtMs, file, "Analyse abgebrochen", err) - return nil, err + return nil, startedAtMs, 0, err } lastExtractPercent := 0 @@ -1880,13 +1884,13 @@ func analyzeVideoFromFramesForGoal( if err != nil { publishAnalysisError(startedAtMs, file, "Frames konnten nicht extrahiert werden", err) - return nil, err + return nil, startedAtMs, 0, err } if len(samples) == 0 { err := appErrorf("keine frame-samples vorhanden") publishAnalysisError(startedAtMs, file, "Keine Frames vorhanden", err) - return nil, err + return nil, startedAtMs, 0, err } total := len(samples) @@ -2043,8 +2047,7 @@ func analyzeVideoFromFramesForGoal( cleanHighlightHits := mergeAnalyzeHits(highlightHits) - publishAnalysisFinished(startedAtMs, total, file, "Analyse abgeschlossen") - return cleanHighlightHits, nil + return cleanHighlightHits, startedAtMs, total, nil } // Fallback: langsame Einzelbild-Analyse, nur wenn der AI-Server-Batch fehlschlägt. @@ -2093,9 +2096,7 @@ func analyzeVideoFromFramesForGoal( cleanHighlightHits := mergeAnalyzeHits(highlightHits) - publishAnalysisFinished(startedAtMs, total, file, "Analyse abgeschlossen") - - return cleanHighlightHits, nil + return cleanHighlightHits, startedAtMs, total, nil } func sameAnalyzeComboLabel(a, b string) bool { diff --git a/backend/assets_generate.go b/backend/assets_generate.go index 02f3494..d49fa0b 100644 --- a/backend/assets_generate.go +++ b/backend/assets_generate.go @@ -172,11 +172,13 @@ func ensureAnalyzeAllGoalsForVideoCtxForce( return false, skipAnalysisBecauseBadSpriteError(reason) } - hits, err := analyzeVideoFromFrames(actx, videoPath) + hits, analyzeStartedAtMs, analyzeTotalFrames, err := analyzeVideoFromFrames(actx, videoPath) if err != nil { return false, err } + defer publishAnalysisFinished(analyzeStartedAtMs, analyzeTotalFrames, filepath.Base(videoPath), "Analyse abgeschlossen") + segments := buildAnalyzeSegmentsForGoal(hits, durationSec) segments = prepareAIRatingSegments(segments) @@ -1585,11 +1587,13 @@ func prepareVideoForSplit(ctx context.Context, videoPath, sourceURL, goal string return out, nil } - hits, aerr := analyzeVideoFromFrames(ctx, videoPath) + hits, analyzeStartedAtMs2, analyzeTotalFrames2, aerr := analyzeVideoFromFrames(ctx, videoPath) if aerr != nil { return out, nil } + defer publishAnalysisFinished(analyzeStartedAtMs2, analyzeTotalFrames2, filepath.Base(videoPath), "Analyse abgeschlossen") + segments := buildAnalyzeSegmentsForGoal(hits, durationSec) segments = prepareAIRatingSegments(segments)