{"record":{"id":"e909289e574c33eb","repo":"MathewSachin/Captura","slug":"an-error-occurred-with-ffmpeg-exit-code-exitcod-e90928","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/FFmpegTrimmer.cs","lineNumber":33,"sourceCode":"\n            var inputArgs = argsBuilder.AddInputFile(SourceFile)\n                .AddArg(\"ss\", From)\n                .AddArg(\"to\", To);\n\n            if (HasAudio)\n                inputArgs.SetAudioCodec(\"copy\");\n\n            argsBuilder.AddOutputFile(DestFile);\n\n            var args = argsBuilder.GetArgs();\n\n            var process = FFmpegService.StartFFmpeg(args, DestFile, out _);\n\n            await Task.Factory.StartNew(process.WaitForExit);\n\n            if (process.ExitCode != 0)\n            {\n                throw new FFmpegException(process.ExitCode);\n            }\n        }\n    }\n}","sourceCodeStart":15,"sourceCodeEnd":37,"githubUrl":"https://github.com/MathewSachin/Captura/blob/3fdf41529bf4d50cd7a85aedd856f30e34279a47/src/Captura.FFmpeg/FFmpegTrimmer.cs#L15-L37","documentation":"Thrown by FFmpegTrimmer.Run (src/Captura.FFmpeg/FFmpegTrimmer.cs:33) after process.WaitForExit() when process.ExitCode != 0. The trimmer builds `-ss`/`-to` seek args with audio codec copy, so any ffmpeg failure during the cut surfaces only as the exit code; the per-file log (StartFFmpeg writes to IFFmpegLogRepository) holds the detail.","triggerScenarios":"Trimming a source file that ffmpeg cannot decode, a `-ss`/`-to` range that falls outside the media duration, a destination path that is unwritable, or an audio copy codec that is incompatible with the container of DestFile.","commonSituations":"Source video deleted/moved between selection and trim; destination folder permissions; trimming into a container that rejects `copy` for the source's codec (e.g. opus audio into mp4 without proper tagging); times specified past the clip end.","solutions":["Confirm SourceFile exists and is a decodable media file before calling Run.","Validate `From` < `To` and both are within the source duration.","Ensure DestFile's directory is writable and its container supports stream copy of the source codec.","Inspect the IFFmpegLogRepository entry for DestFile to read ffmpeg's stderr."],"exampleFix":"// before\nawait new FFmpegTrimmer().Run(sourceFile, from, to, destFile, hasAudio);\n// after\nif (!File.Exists(sourceFile)) throw new FileNotFoundException(sourceFile);\nif (to <= from) throw new ArgumentException(\"trim range invalid\");\nawait new FFmpegTrimmer().Run(sourceFile, from, to, destFile, hasAudio);","handlingStrategy":"validation","validationCode":"if (!File.Exists(SourceFile)) throw new FileNotFoundException(SourceFile);\nif (To <= From) throw new ArgumentException(\"trim range invalid\");\nvar dir = Path.GetDirectoryName(DestFile);\nif (!Directory.Exists(dir)) Directory.CreateDirectory(dir);","typeGuard":null,"tryCatchPattern":"try { await trimmer.Run(src, from, to, dest, hasAudio); }\ncatch (FFmpegException e) { /* read log for DestFile, report to user */ }","preventionTips":["Probe the source duration with ffprobe and clamp From/To before trimming.","Ensure the destination container supports stream copy of the source codec.","Write to a temp file then atomically rename to avoid partial outputs."],"tags":["ffmpeg","media-processing","trim","csharp"],"backgroundTag":null,"analyzedSha":"3fdf41529bf4d50cd7a85aedd856f30e34279a47","analyzedAt":"2026-08-13T19:35:27.486Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}