MathewSachin/Captura · error · FFmpegException

An Error Occurred with FFmpeg, Exit Code: {ExitCode}.\nSee F

Error message

An Error Occurred with FFmpeg, Exit Code: {ExitCode}.\nSee FFmpeg Log for more info.

What it means

Thrown by FFmpegTrimmer.Run (src/Captura.FFmpeg/FFmpegTrimmer.cs:33) after process.WaitForExit() when process.ExitCode != 0. The trimmer builds `-ss`/`-to` seek args with audio codec copy, so any ffmpeg failure during the cut surfaces only as the exit code; the per-file log (StartFFmpeg writes to IFFmpegLogRepository) holds the detail.

Source

Thrown at src/Captura.FFmpeg/FFmpegTrimmer.cs:33

            var inputArgs = argsBuilder.AddInputFile(SourceFile)
                .AddArg("ss", From)
                .AddArg("to", To);

            if (HasAudio)
                inputArgs.SetAudioCodec("copy");

            argsBuilder.AddOutputFile(DestFile);

            var args = argsBuilder.GetArgs();

            var process = FFmpegService.StartFFmpeg(args, DestFile, out _);

            await Task.Factory.StartNew(process.WaitForExit);

            if (process.ExitCode != 0)
            {
                throw new FFmpegException(process.ExitCode);
            }
        }
    }
}

View on GitHub (pinned to 3fdf41529b)

Solutions

  1. Confirm SourceFile exists and is a decodable media file before calling Run.
  2. Validate `From` < `To` and both are within the source duration.
  3. Ensure DestFile's directory is writable and its container supports stream copy of the source codec.
  4. Inspect the IFFmpegLogRepository entry for DestFile to read ffmpeg's stderr.

Example fix

// before
await new FFmpegTrimmer().Run(sourceFile, from, to, destFile, hasAudio);
// after
if (!File.Exists(sourceFile)) throw new FileNotFoundException(sourceFile);
if (to <= from) throw new ArgumentException("trim range invalid");
await new FFmpegTrimmer().Run(sourceFile, from, to, destFile, hasAudio);
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(SourceFile)) throw new FileNotFoundException(SourceFile);
if (To <= From) throw new ArgumentException("trim range invalid");
var dir = Path.GetDirectoryName(DestFile);
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);

Try / catch

try { await trimmer.Run(src, from, to, dest, hasAudio); }
catch (FFmpegException e) { /* read log for DestFile, report to user */ }

Prevention

When it happens

Trigger: Trimming a source file that ffmpeg cannot decode, a `-ss`/`-to` range that falls outside the media duration, a destination path that is unwritable, or an audio copy codec that is incompatible with the container of DestFile.

Common situations: Source video deleted/moved between selection and trim; destination folder permissions; trimming into a container that rejects `copy` for the source's codec (e.g. opus audio into mp4 without proper tagging); times specified past the clip end.

Related errors


AI-assisted analysis of MathewSachin/Captura@3fdf41529b (2026-08-13). Data as JSON: /api/errors/e909289e574c33eb. Report an issue: GitHub.