diff --git a/Sources/GrowthLapse/VideoProcessor.swift b/Sources/GrowthLapse/VideoProcessor.swift index 32f9b5c..e497278 100644 --- a/Sources/GrowthLapse/VideoProcessor.swift +++ b/Sources/GrowthLapse/VideoProcessor.swift @@ -450,6 +450,11 @@ final class VideoProcessor: ObservableObject { clipNumber: clipNumber, totalClips: videos.count ) + if !settings.keepIntermediateClips { + removeTemporaryFile(segmentURL) + removeTemporaryFile(stabilizedURL) + removeTemporaryFile(tempDirectory.appendingPathComponent(String(format: "clip_%04d.trf", clipNumber))) + } } else { try await normalizeSourceSegment( source: video.url, @@ -808,6 +813,10 @@ final class VideoProcessor: ObservableObject { throw VideoProcessingError.ffmpegFailed("Xfade Übergang \(index)", result.output) } + if !settings.keepIntermediateClips { + removeTemporaryFile(current) + removeTemporaryFile(next) + } current = out currentDuration += settings.targetClipLength - settings.transitionLength progress = 0.75 + (Double(index) / Double(totalSteps)) * 0.25 @@ -834,6 +843,17 @@ final class VideoProcessor: ObservableObject { try FileManager.default.copyItem(at: source, to: outputFile) } + private func removeTemporaryFile(_ url: URL) { + guard FileManager.default.fileExists(atPath: url.path) else { + return + } + do { + try FileManager.default.removeItem(at: url) + } catch { + appendLog("Warnung: Temporäre Datei konnte nicht gelöscht werden: \(url.lastPathComponent) (\(error.localizedDescription))") + } + } + private func escapeConcatPath(_ path: String) -> String { path.replacingOccurrences(of: "'", with: "'\\''") }