{"record":{"id":"d7ece91b17faab52","repo":"MathewSachin/Captura","slug":"an-error-occurred-with-ffmpeg-exit-code-exitcod-d7ece9","errorCode":null,"errorMessage":"An Error Occurred with FFmpeg, Exit Code: {ExitCode}.\\nSee FFmpeg Log for more info.","messagePattern":"An Error Occurred with FFmpeg, Exit Code: (.+?)\\.\\\\nSee FFmpeg Log for more info\\.","errorType":"exception","errorClass":"FFmpegException","httpStatus":null,"severity":"error","filePath":"src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs","lineNumber":150,"sourceCode":"\n        bool _firstAudio = true;\n\n        Task _lastAudio;\n\n        /// <summary>\n        /// Write audio block to Audio Stream.\n        /// </summary>\n        /// <param name=\"Buffer\">Buffer containing audio data.</param>\n        /// <param name=\"Length\">Length of audio data in bytes.</param>\n        public void WriteAudio(byte[] Buffer, int Offset, int Length)\n        {\n            // Might happen when writing Gif\n            if (_audioPipe == null)\n                return;\n\n            if (_ffmpegProcess.HasExited)\n            {\n                throw new FFmpegException( _ffmpegProcess.ExitCode);\n            }\n\n            if (_firstAudio)\n            {\n                if (!_audioPipe.WaitForConnection(5000))\n                {\n                    throw new Exception(\"Cannot connect Audio pipe to FFmpeg\");\n                }\n\n                _firstAudio = false;\n            }\n\n            // We don't need semaphores for audio since audio frames arrive less often.\n            _lastAudio?.Wait();\n\n            // Drop audio bytes to sync with video once we've reached stability from frame side.\n            if (_initialStability)\n            {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/MathewSachin/Captura/blob/3fdf41529bf4d50cd7a85aedd856f30e34279a47/src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs#L132-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the IFFmpegLogRepository entry for this recording to get ffmpeg's stderr.","Check free disk space and that the output path is still writable.","Verify Args.Frequency/Args.Channels match the audio provider's WaveFormat.","Inspect whether the video pipe (WriteFrame) already failed first."],"exampleFix":"// before\nif (_ffmpegProcess.HasExited) throw new FFmpegException(_ffmpegProcess.ExitCode);\n// after - distinguish 'already dead' from 'just died' for the caller\nif (_ffmpegProcess.HasExited)\n    throw new FFmpegException(_ffmpegProcess.ExitCode,\n        new IOException(\"ffmpeg exited during audio write; see ffmpeg log\"));","handlingStrategy":"try-catch","validationCode":"// monitor ffmpeg liveness and free disk during capture\nif (_writer == null || process.HasExited) StopRecording();\nif (new DriveInfo(Path.GetPathRoot(outputFile)).AvailableFreeSpace < MinFreeBytes) StopRecording();","typeGuard":null,"tryCatchPattern":"try { writer.WriteAudio(buf, 0, len); }\ncatch (FFmpegException e) { StopRecording(); ShowLog(ServiceProvider.Get<IFFmpegLogRepository>().Items.Last()); }","preventionTips":["Watch disk free space during recording and stop before it hits zero.","Verify Args.Frequency/Channels equal the audio provider's WaveFormat before starting.","Treat a HasExited writer as terminal: stop the capture, do not keep writing."],"tags":["ffmpeg","recording","audio","process-exit","csharp"],"backgroundTag":null,"analyzedSha":"3fdf41529bf4d50cd7a85aedd856f30e34279a47","analyzedAt":"2026-08-13T19:35:27.486Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}