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 FFmpegWriter.WriteAudio (src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs:150) as new FFmpegException(exitCode) when _ffmpegProcess.HasExited at audio-write time during a live recording. The ffmpeg child died mid-capture; the next audio block write detects it. The exit code is the only surfaced detail; the IFFmpegLogRepository entry holds the stderr.

Source

Thrown at src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs:150

        bool _firstAudio = true;

        Task _lastAudio;

        /// <summary>
        /// Write audio block to Audio Stream.
        /// </summary>
        /// <param name="Buffer">Buffer containing audio data.</param>
        /// <param name="Length">Length of audio data in bytes.</param>
        public void WriteAudio(byte[] Buffer, int Offset, int Length)
        {
            // Might happen when writing Gif
            if (_audioPipe == null)
                return;

            if (_ffmpegProcess.HasExited)
            {
                throw new FFmpegException( _ffmpegProcess.ExitCode);
            }

            if (_firstAudio)
            {
                if (!_audioPipe.WaitForConnection(5000))
                {
                    throw new Exception("Cannot connect Audio pipe to FFmpeg");
                }

                _firstAudio = false;
            }

            // We don't need semaphores for audio since audio frames arrive less often.
            _lastAudio?.Wait();

            // Drop audio bytes to sync with video once we've reached stability from frame side.
            if (_initialStability)
            {

View on GitHub (pinned to 3fdf41529b)

Solutions

  1. Read the IFFmpegLogRepository entry for this recording to get ffmpeg's stderr.
  2. Check free disk space and that the output path is still writable.
  3. Verify Args.Frequency/Args.Channels match the audio provider's WaveFormat.
  4. Inspect whether the video pipe (WriteFrame) already failed first.

Example fix

// before
if (_ffmpegProcess.HasExited) throw new FFmpegException(_ffmpegProcess.ExitCode);
// after - distinguish 'already dead' from 'just died' for the caller
if (_ffmpegProcess.HasExited)
    throw new FFmpegException(_ffmpegProcess.ExitCode,
        new IOException("ffmpeg exited during audio write; see ffmpeg log"));
Defensive patterns

Strategy: try-catch

Validate before calling

// monitor ffmpeg liveness and free disk during capture
if (_writer == null || process.HasExited) StopRecording();
if (new DriveInfo(Path.GetPathRoot(outputFile)).AvailableFreeSpace < MinFreeBytes) StopRecording();

Try / catch

try { writer.WriteAudio(buf, 0, len); }
catch (FFmpegException e) { StopRecording(); ShowLog(ServiceProvider.Get<IFFmpegLogRepository>().Items.Last()); }

Prevention

When it happens

Trigger: Writing an audio block after ffmpeg has exited. Common: encoder crashed (bad args, unsupported sample format), output file became unwritable, disk full, or the video pipe write earlier killed ffmpeg.

Common situations: Disk fills up mid-recording; output path on a removable drive that disconnected; audio sample format/channel count mismatches the s16le PCM feed; an earlier frame write already broke the video pipe.

Related errors


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