{"record":{"id":"e2a69bab63a3a497","repo":"NickeManarin/ScreenToGif","slug":"error-while-capturing-frames-with-ffmpeg","errorCode":null,"errorMessage":"Error while capturing frames with FFmpeg.","messagePattern":"Error while capturing frames with FFmpeg\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ScreenToGif.ViewModel/VideoSourceViewModel.cs","lineNumber":768,"sourceCode":"                    if (Math.Abs(current - FrameCount) < double.Epsilon)\n                        GetFiles(folder);\n                }\n            };\n            \n            _process.StartInfo = info;\n            _process.Start();\n            _process.BeginOutputReadLine();\n            _process.BeginErrorReadLine();\n            \n            await _process.WaitForExitAsync();\n\n            if (_process == null)\n                return;\n\n            var error = await _process?.StandardError?.ReadToEndAsync();\n\n            if (!string.IsNullOrWhiteSpace(error))\n                throw new Exception(\"Error while capturing frames with FFmpeg.\") { HelpLink = $\"Command:\\n\\r{info.Arguments}\\n\\rResult:\\n\\r{error}\" };\n        }\n        catch (Exception e)\n        {\n            LogWriter.Log(e, \"Error importing frames with FFmpeg\");\n\n            IsImporting = false;\n\n            Dispatcher.CurrentDispatcher.Invoke(() => ShowErrorRequested?.Invoke(this, LocalizationHelper.Get(\"S.ImportVideo.Error\") + Environment.NewLine + e.Message + Environment.NewLine + e.HelpLink));\n        }\n    }\n\n    private void ImportAndSeek()\n    {\n        if (_cancelled)\n            return;\n\n        lock (_lock)\n        {","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/NickeManarin/ScreenToGif/blob/a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd/ScreenToGif.ViewModel/VideoSourceViewModel.cs#L750-L786","documentation":"Thrown by VideoSourceViewModel after an FFmpeg process exits with non-empty StandardError output. The method starts FFmpeg to extract frames from a video, awaits its exit, then checks if error text was written. If so, it throws with the FFmpeg command arguments and error output embedded in the exception's HelpLink.","triggerScenarios":"FFmpeg process runs (info.Arguments) and exits, but writes error messages to stderr. Common FFmpeg errors: unsupported codec, corrupt input file, invalid arguments, missing encoder, permission denied on output path, or the input video file is unreadable.","commonSituations":"User selects a video with a codec FFmpeg doesn't support (rare but possible with custom builds). FFmpeg binary is not found or is an older version lacking the needed decoder. Output folder is read-only. Input video file is corrupted or truncated. FFmpeg arguments (e.g., filter, fps) are misconfigured.","solutions":["Read the exception's HelpLink which contains the FFmpeg command and stderr output — this pinpoints the exact FFmpeg error.","Verify the FFmpeg binary version supports the input codec (run 'ffmpeg -codecs').","Check the input video file is not corrupted (play it in a media player).","Ensure the output/temp directory has write permissions and sufficient disk space.","Update FFmpeg to a recent build with all common codecs enabled."],"exampleFix":"// before\nif (!string.IsNullOrWhiteSpace(error))\n    throw new Exception(\"Error while capturing frames with FFmpeg.\") { HelpLink = $\"Command:\\n\\r{info.Arguments}\\n\\rResult:\\n\\r{error}\" };\n\n// after: include error directly in message for easier debugging, check exit code\nif (_process.ExitCode != 0 || !string.IsNullOrWhiteSpace(error))\n    throw new Exception($\"Error while capturing frames with FFmpeg (exit {_process.ExitCode}): {error}\")\n    { HelpLink = $\"Command:\\n\\r{info.Arguments}\" };","handlingStrategy":"try-catch","validationCode":"// Validate input file before starting FFmpeg\nif (!File.Exists(inputPath))\n    throw new FileNotFoundException(\"Input video not found\", inputPath);\nvar info = new FileInfo(inputPath);\nif (info.Length == 0)\n    throw new InvalidDataException(\"Input video file is empty.\");\nif (!File.Exists(ffmpegPath))\n    throw new FileNotFoundException(\"FFmpeg binary not found\", ffmpegPath);","typeGuard":null,"tryCatchPattern":"// The existing catch block at line 770 already handles this:\n// it logs, sets IsImporting=false, and shows a user error dialog.\n// Ensure e.HelpLink (containing FFmpeg stderr) is shown to the user.","preventionTips":["Validate the input video file exists and is non-empty before launching FFmpeg.","Verify the FFmpeg binary path and version before use.","Check that the output/temp directory has write permission and free disk space.","Parse FFmpeg's exit code separately from stderr — exit code 0 with stderr output is normal for FFmpeg."],"tags":["ffmpeg","video","process","frame-extraction","external-dependency"],"backgroundTag":null,"analyzedSha":"a4d0a67c2131cd048ceec86cd40afc2f1a06f2fd","analyzedAt":"2026-08-13T11:12:06.147Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}