SubtitleEdit/subtitleedit · error · InvalidOperationException

ffmpeg failed to extract chunk {i + 1}/{boundaries.Count} ({

Error message

ffmpeg failed to extract chunk {i + 1}/{boundaries.Count} ({boundary.StartSeconds:0.##}s → {boundary.EndSeconds:0.##}s) from {audioFileName}

What it means

OpenAiSttChunker.ExtractChunkAsync returned false (ffmpeg exited non-zero), so the chunk WAV for the i-th boundary was not produced. The ViewModel surfaces it as InvalidOperationException naming the chunk index, the start/end seconds, and the source audio file.

Source

Thrown at src/ui/Features/Video/SpeechToText/SpeechToTextViewModel.cs:1601

            var boundary = boundaries[i];
            var chunkPath = Path.Combine(GetSttTempFolder(), $"se-stt-chunk-{Guid.NewGuid()}{extension}");
            // Register before extraction so a throw mid-extract still drains
            // the (possibly partial) file via the outer _filesToDelete sweep.
            _filesToDelete.Add(chunkPath);

            LogToConsole(
                $"Chunk {i + 1}/{boundaries.Count}: " +
                $"{TimeSpan.FromSeconds(boundary.StartSeconds):mm\\:ss} → {TimeSpan.FromSeconds(boundary.EndSeconds):mm\\:ss}");

            try
            {
                var extractOk = await OpenAiSttChunker.ExtractChunkAsync(
                    ffmpegPath, audioFileName, chunkPath,
                    boundary.StartSeconds, boundary.DurationSeconds, cancellationToken);
                if (!extractOk)
                {
                    throw new InvalidOperationException(
                        $"ffmpeg failed to extract chunk {i + 1}/{boundaries.Count} " +
                        $"({boundary.StartSeconds:0.##}s → {boundary.EndSeconds:0.##}s) from {audioFileName}");
                }

                // Wrap the caller's segment progress so streaming segments coming
                // from this chunk get offset back to absolute time before the UI
                // sees them.
                var offsetSeconds = boundary.StartSeconds;
                var offsettingProgress = new Progress<OpenAiCompatibleSegment>(seg =>
                {
                    segmentProgress.Report(new OpenAiCompatibleSegment
                    {
                        Id = seg.Id,
                        Start = seg.Start + offsetSeconds,
                        End = seg.End + offsetSeconds,
                        Text = seg.Text,
                    });
                });

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Confirm ffmpegPath resolves to a working ffmpeg binary (run `ffmpeg -version`).
  2. Verify audioFileName exists and is decodable.
  3. Check boundary.StartSeconds/DurationSeconds produce a positive, in-range duration.
  4. Run the exact ffmpeg command ExtractChunkAsync builds, manually, to read the underlying stderr.

Example fix

// before: pass boundaries without sanity-checking
// after: skip degenerate boundaries before extracting
if (boundary.DurationSeconds <= 0 || boundary.EndSeconds > totalAudioSeconds)
{
    LogToConsole($"Skipping degenerate chunk {i + 1}");
    continue;
}
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(ffmpegPath)) return Invalid("ffmpeg not found at " + ffmpegPath);
if (!File.Exists(audioFileName)) return Invalid("audio file missing");
if (boundary.DurationSeconds <= 0) return Invalid("zero-length chunk");

Try / catch

try { extractOk = await OpenAiSttChunker.ExtractChunkAsync(...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ffmpeg failed to extract chunk"))
{ /* log chunk index + boundary, continue or abort the run */ }

Prevention

When it happens

Trigger: ffmpegPath does not resolve to a working ffmpeg; audioFileName is missing/corrupt/undecodable; boundary.StartSeconds/EndSeconds are out of range or produce zero/negative DurationSeconds; output chunkPath is on a non-writable directory.

Common situations: ffmpeg not installed or moved after settings saved; truncated audio file; rounding errors producing 0-length chunks at the very start/end of short clips; permissions on the temp chunk folder.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/236c2c12f6239ae7. Report an issue: GitHub.