SubtitleEdit/subtitleedit · error · InvalidOperationException

yt-dlp subtitle download exited with code {process.ExitCode}

Error message

yt-dlp subtitle download exited with code {process.ExitCode}.

What it means

Thrown by DownloadSubtitlesOnlyAsync after the yt-dlp subtitle process exits non-zero. The captured stderr (read synchronously via ReadToEndAsync) is appended so the real yt-dlp error is visible. Mirrors error 372 but for the subtitle-only invocation which uses --skip-download.

Source

Thrown at src/ui/Logic/Download/YtDlpDownloadService.cs:396

        var stdoutTask = process.StandardOutput.ReadToEndAsync(cancellationToken);
        var stderrTask = process.StandardError.ReadToEndAsync(cancellationToken);

        try
        {
            await process.WaitForExitAsync(cancellationToken);
        }
        catch (OperationCanceledException)
        {
            TryKillProcess(process);
            throw;
        }

        await stdoutTask;
        if (process.ExitCode != 0)
        {
            var details = (await stderrTask).Trim();
            throw new InvalidOperationException(
                $"yt-dlp subtitle download exited with code {process.ExitCode}." +
                (string.IsNullOrEmpty(details) ? string.Empty : Environment.NewLine + details));
        }
    }

    // The title fetch is a live network round-trip to the video site; cap it so
    // a stalled extractor can't leave the save-as flow stuck behind a spinner.
    private static readonly TimeSpan TitleFetchTimeout = TimeSpan.FromSeconds(15);

    public async Task<string?> GetVideoTitleAsync(string url, CancellationToken cancellationToken)
    {
        cancellationToken.ThrowIfCancellationRequested();
        if (!File.Exists(GetFullFileName()))
        {
            return null;
        }

        using var process = new Process

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Inspect the stderr in the exception message for the specific yt-dlp error.
  2. Update yt-dlp (re-run DownloadYtDlp) to get current subtitle extractors.
  3. Verify the video actually has subtitles in the requested language before requesting auto-subs.
  4. Retry on transient network/geo errors or supply cookies for restricted videos.

Example fix

// before
await _ytDlp.DownloadAutoGeneratedSubtitlesAsync(url, stem, ct);

// after: distinguish 'no subtitles' from real failures
catch (InvalidOperationException ex)
{
    if (ex.Message.Contains("no subtitles") || ex.Message.Contains("NO sub"))
        return; // acceptable: video has none
    await _ytDlp.DownloadYtDlp(null, ct); // update extractor then retry
    throw;
}
Defensive patterns

Strategy: try-catch

Try / catch

try { await svc.DownloadAutoGeneratedSubtitlesAsync(url, stem, ct); }
catch (InvalidOperationException ex)
{
    if (ex.Message.Contains("no subtitles")) return; // acceptable
    await svc.DownloadYtDlp(null, ct); throw; // update extractor, retry upstream
}

Prevention

When it happens

Trigger: yt-dlp exits non-zero during a subtitle fetch: video has no subtitles, --sub-langs regex matched nothing, site extractor broke, network/geo-block, or an outdated yt-dlp.

Common situations: Requesting auto-subs on a video that has none; yt-dlp version too old for a changed subtitle endpoint; region-blocked video.

Related errors


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