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 FFmpegAudioWriter.Write (src/Captura.FFmpeg/Audio/FFmpegAudioWriter.cs:54) as new FFmpegException(exitCode) when _ffmpegProcess.HasExited is true at write time. FFmpegException (src/Captura.FFmpeg/FFmpegException.cs:5-9) only carries the exit code; the real cause is in the ffmpeg log captured by FFmpegService.StartFFmpeg via ErrorDataReceived into IFFmpegLogRepository.

Source

Thrown at src/Captura.FFmpeg/Audio/FFmpegAudioWriter.cs:54

        public void Dispose()
        {
            Flush();

            _ffmpegIn.Close();
            _ffmpegProcess.WaitForExit();
        }

        public void Flush()
        {
            _ffmpegIn.Flush();
        }

        public void Write(byte[] Data, int Offset, int Count)
        {
            if (_ffmpegProcess.HasExited)
            {
                throw new FFmpegException(_ffmpegProcess.ExitCode);
            }

            _ffmpegIn.Write(Data, Offset, Count);
        }
    }
}

View on GitHub (pinned to 3fdf41529b)

Solutions

  1. Read the matching IFFmpegLogRepository entry for this output file to get ffmpeg's stderr (the actual error line).
  2. Confirm the requested audio codec/encoder is supported: run `ffmpeg.exe -encoders` and match the name exactly.
  3. Verify the output path is writable and on a volume with free space.
  4. Cross-check Frequency/Channels passed to FFmpegAudioWriter against the source audio.

Example fix

// before
_ffmpegIn.Write(Data, Offset, Count); // happens after HasExited guard throws
// after - surface the captured ffmpeg log instead of only the exit code
catch (FFmpegException e)
{
    var log = ServiceProvider.Get<IFFmpegLogRepository>().Items.LastOrDefault();
    throw new FFmpegException(e.Message + $"\nFFmpeg stderr:\n{log}", e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before each write, confirm ffmpeg is still alive (cheaper than catching)
if (_writer == null || _ffmpegProcessHasExitedFlag) return;
// (the writer already checks HasExited internally; pre-check avoids a wasted call)

Try / catch

try { _writer.Write(data, 0, data.Length); }
catch (FFmpegException e) { var log = ServiceProvider.Get<IFFmpegLogRepository>().Items.Last(); /* show log, stop recording */ }

Prevention

When it happens

Trigger: Calling Write(byte[]) after the ffmpeg child process has already terminated with a non-zero exit code. The process died during encoding (bad codec/args, missing encoder build, unwritable output path) and the next audio chunk write detects HasExited.

Common situations: Codec args reference an encoder not compiled into this ffmpeg build (e.g. libmp3lame absent); output directory is read-only or the file is locked by another process; sample rate/channel count args are inconsistent with the PCM stream; disk full.

Related errors


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