{"record":{"id":"5ab44672e78a017e","repo":"SubtitleEdit/subtitleedit","slug":"could-not-cut-the-audio-window-with-ffmpeg","errorCode":null,"errorMessage":"Could not cut the audio window with ffmpeg.","messagePattern":"Could not cut the audio window with ffmpeg\\.","errorType":"exception","errorClass":"ForcedAlignerException","httpStatus":null,"severity":"error","filePath":"src/ui/Features/Files/ImportPlainText/CrispAsrAlignOnlyRunner.cs","lineNumber":170,"sourceCode":"\n    public Task<IReadOnlyList<OpenAiSttChunker.SilenceInterval>> DetectSilenceAsync(CancellationToken cancellationToken)\n        => OpenAiSttChunker.DetectSilenceIntervalsAsync(_ffmpegPath, _audioFileName, cancellationToken: cancellationToken);\n\n    public async Task<string> ExtractWindowAsync(double startSeconds, double durationSeconds, CancellationToken cancellationToken)\n    {\n        var target = Path.Combine(\n            _workFolder,\n            \"se-align-\" + _windowIndex.ToString(CultureInfo.InvariantCulture) + \".wav\");\n        _windowIndex++;\n        _windowFiles.Add(target);\n\n        var ok = await OpenAiSttChunker\n            .ExtractChunkAsync(_ffmpegPath, _audioFileName, target, startSeconds, durationSeconds, cancellationToken)\n            .ConfigureAwait(false);\n\n        if (!ok || !File.Exists(target))\n        {\n            throw new ForcedAlignerException(\"Could not cut the audio window with ffmpeg.\");\n        }\n\n        return target;\n    }\n\n    public void Dispose()\n    {\n        foreach (var file in _windowFiles)\n        {\n            TryDelete(file);\n            TryDelete(Path.ChangeExtension(file, \".txt\"));\n            TryDelete(Path.ChangeExtension(file, \".aligned.srt\"));\n        }\n\n        _windowFiles.Clear();\n    }\n\n    private static void TryDelete(string fileName)","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Features/Files/ImportPlainText/CrispAsrAlignOnlyRunner.cs#L152-L188","documentation":"Thrown by FfmpegWindowAudioSource.ExtractWindowAsync when OpenAiSttChunker.ExtractChunkAsync returned false or the target WAV was not created. ffmpeg is the cutting tool, so this means the slice of the source audio could not be produced for the aligner to read.","triggerScenarios":"ExtractChunkAsync(ffmpegPath, audioFileName, target, startSeconds, durationSeconds) returns false, OR returns true but File.Exists(target) is false.","commonSituations":"ffmpeg not installed or not on PATH; _ffmpegPath points to a wrong binary; source audio deleted or unreadable; disk full in the work folder; startSeconds/durationSeconds out of range (e.g. beyond the stream end); ffmpeg lacks the decoder for the source codec.","solutions":["Verify ffmpeg is installed and _ffmpegPath is correct: run `ffmpeg -version` in the same environment.","Confirm the source audio file still exists and is readable.","Ensure the work folder is writable and has free space.","Validate startSeconds/durationSeconds are within TotalSeconds before slicing.","Capture ffmpeg's stderr (ExtractChunkAsync logs it) for the exact failure."],"exampleFix":"// guard the slice bounds\nvar dur = Math.Min(durationSeconds, source.TotalSeconds - startSeconds);\nif (dur <= 0) throw new InvalidOperationException(\"window out of range\");\nvar ok = await OpenAiSttChunker.ExtractChunkAsync(_ffmpegPath, _audioFileName, target, startSeconds, dur, ct);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(_ffmpegPath) || !File.Exists(_ffmpegPath))\n    throw new ForcedAlignerException(\"ffmpeg not found at: \" + _ffmpegPath);\nif (startSeconds < 0 || startSeconds >= source.TotalSeconds)\n    throw new ForcedAlignerException(\"window start out of range\");","typeGuard":"static bool FfmpegAvailable(string p) => !string.IsNullOrEmpty(p) && File.Exists(p);","tryCatchPattern":"try { return await source.ExtractWindowAsync(start, dur, ct); }\ncatch (ForcedAlignerException ex) when (ex.Message.Contains(\"ffmpeg\")) {\n    logger.Error(\"ffmpeg slice failed; check ffmpeg path/permissions.\"); throw; }","preventionTips":["Resolve and verify the ffmpeg path at app startup.","Confirm the work folder is writable with free disk space.","Clamp window bounds to TotalSeconds before slicing."],"tags":["subtitle-edit","forced-aligner","ffmpeg","audio-extraction","missing-dependency"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}