{"record":{"id":"5c06f26444e9e730","repo":"MathewSachin/Captura","slug":"cannot-connect-video-pipe-to-ffmpeg","errorCode":null,"errorMessage":"Cannot connect Video pipe to FFmpeg","messagePattern":"Cannot connect Video pipe to FFmpeg","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs","lineNumber":216,"sourceCode":"\n        Task _lastFrameTask;\n\n        /// <summary>\n        /// Writes an Image frame.\n        /// </summary>\n        public void WriteFrame(IBitmapFrame Frame)\n        {\n            if (_ffmpegProcess.HasExited)\n            {\n                Frame.Dispose();\n                throw new FFmpegException(_ffmpegProcess.ExitCode);\n            }\n            \n            if (_firstFrame)\n            {\n                if (!_ffmpegIn.WaitForConnection(5000))\n                {\n                    throw new Exception(\"Cannot connect Video pipe to FFmpeg\");\n                }\n\n                _firstFrame = false;\n            }\n\n            if (_lastFrameTask == null)\n            {\n                _lastFrameTask = Task.CompletedTask;\n            }\n\n            if (!(Frame is RepeatFrame))\n            {\n                using (Frame)\n                {\n                    if (Frame.Unwrap() is INV12Frame nv12Frame)\n                    {\n                        nv12Frame.CopyNV12To(_videoBuffer);\n                    }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/MathewSachin/Captura/blob/3fdf41529bf4d50cd7a85aedd856f30e34279a47/src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs#L198-L234","documentation":"Thrown by FFmpegWriter.WriteFrame (src/Captura.FFmpeg/Video/FFmpegVideoWriter.cs:216) when _ffmpegIn.WaitForConnection(5000) returns false on the first frame. FFmpeg must open the `captura-<guid>` video pipe within 5s; if it never does, the timeout fires. This is the first interaction with ffmpeg after StartFFmpeg, so a failure here usually means ffmpeg failed to start or rejected its arguments.","triggerScenarios":"The first WriteFrame call when ffmpeg did not connect to the video named pipe within 5000 ms. Typically ffmpeg exited immediately after start (bad args, missing binary resolution via FFmpegExePath) or is still alive but stalled.","commonSituations":"FFmpegExePath resolved to a bare `ffmpeg.exe` name that isn't on PATH; the rawvideo/nv12 args are malformed; ffmpeg process started but the named-pipe path format is wrong for this OS; system too loaded to start ffmpeg in 5s.","solutions":["Check _ffmpegProcess.HasExited right after StartFFmpeg in the constructor; if dead, read the log immediately.","Confirm FFmpegExePath resolves to a real executable (not the fallback bare name).","Log argsBuilder.GetArgs() and reproduce the command manually.","Raise the 5000 ms connect timeout on slow machines."],"exampleFix":"// before\nif (!_ffmpegIn.WaitForConnection(5000))\n    throw new Exception(\"Cannot connect Video pipe to FFmpeg\");\n// after\nif (!_ffmpegIn.WaitForConnection(5000))\n    throw new Exception(_ffmpegProcess.HasExited\n        ? $\"FFmpeg exited (code {_ffmpegProcess.ExitCode}) before opening the video pipe; args: {args}\"\n        : \"Video pipe connect timed out after 5s\");","handlingStrategy":"validation","validationCode":"// right after StartFFmpeg in the ctor, fail fast with the real reason\n_ffmpegProcess = FFmpegService.StartFFmpeg(argsBuilder.GetArgs(), Args.FileName, out _);\nif (_ffmpegProcess.HasExited) // ffmpeg rejected args and died immediately\n    throw new FFmpegException(_ffmpegProcess.ExitCode);","typeGuard":null,"tryCatchPattern":"try { /* first WriteFrame */ }\ncatch (Exception e) when (e.Message.Contains(\"Video pipe\")) { var reason = _ffmpegProcess.HasExited ? $\"exit {_ffmpegProcess.ExitCode}\" : \"timeout\"; /* report reason */ }","preventionTips":["Check _ffmpegProcess.HasExited immediately after StartFFmpeg.","Confirm FFmpegExePath resolves to a real file, not the bare fallback name.","Log argsBuilder.GetArgs() so a failed connect can be reproduced manually."],"tags":["ffmpeg","named-pipe","recording","video","csharp"],"backgroundTag":null,"analyzedSha":"3fdf41529bf4d50cd7a85aedd856f30e34279a47","analyzedAt":"2026-08-13T19:35:27.486Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}