{"record":{"id":"f40acbe238e96f09","repo":"MonoGame/MonoGame","slug":"ffmpeg-exited-with-non-zero-exit-code-ffmpegstd","errorCode":null,"errorMessage":"ffmpeg exited with non-zero exit code: \n{ffmpegStdout}\n{ffmpegStderr}","messagePattern":"ffmpeg exited with non-zero exit code: \n(.+?)\n(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework.Content.Pipeline/Audio/DefaultAudioProfile.cs","lineNumber":279,"sourceCode":"                    reader.BaseStream.Seek(reader.ReadInt32(), SeekOrigin.Current);\n                }\n            }\n\n            var dataSize = reader.ReadInt32();\n            data = reader.ReadBytes(dataSize);\n\n            return data;\n        }\n\n        public static void WritePcmFile(AudioContent content, string saveToFile, int bitRate = 192000, int? sampeRate = null)\n        {\n            var sampleArg = sampeRate != null ? $\"-ar {sampeRate.Value}\" : string.Empty;\n            var ffmpegExitCode = FFmpeg.Run(\n                $\"-y -i \\\"{content.FileName}\\\" -vn -c:a pcm_s16le -b:a {bitRate} {sampleArg} -f:a wav -strict experimental \\\"{saveToFile}\\\"\",\n                out var ffmpegStdout,\n                out var ffmpegStderr);\n            if (ffmpegExitCode != 0)\n                throw new InvalidOperationException($\"ffmpeg exited with non-zero exit code: \\n{ffmpegStdout}\\n{ffmpegStderr}\");\n        }\n\n        public static ConversionQuality ConvertToFormat(AudioContent content, ConversionFormat formatType, ConversionQuality quality, string? saveToFile)\n        {\n            var temporaryOutput = Path.GetTempFileName();\n            try\n            {\n                string ffmpegCodecName, ffmpegMuxerName;\n                //int format;\n                switch (formatType)\n                {\n                    case ConversionFormat.Adpcm:\n                        // ADPCM Microsoft\n                        ffmpegCodecName = \"adpcm_ms\";\n                        ffmpegMuxerName = \"wav\";\n                        //format = 0x0002; /* WAVE_FORMAT_ADPCM */\n                        break;\n                    case ConversionFormat.Pcm:","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework.Content.Pipeline/Audio/DefaultAudioProfile.cs#L261-L297","documentation":"Thrown by DefaultAudioProfile.WritePcmFile when ffmpeg returns a non-zero exit code during PCM/WAV conversion. Unlike ConvertToFormat, WritePcmFile does not retry at lower quality — it fails immediately. The message includes ffmpeg's stdout and stderr for diagnosis.","triggerScenarios":"ffmpeg cannot decode the input (corrupt/unreadable source), the requested codec (pcm_s16le) is unsupported by the installed ffmpeg build, or ffmpeg is missing/broken. A bad bitRate/sampleRate argument can also cause ffmpeg to fail.","commonSituations":"Custom processor calling WritePcmFile with an unsupported sample rate. ffmpeg build without the needed encoder. Source file unreadable by ffmpeg. Out-of-range bitRate value.","solutions":["Read the embedded ffmpegStderr in the exception message to find the exact ffmpeg error.","Run the ffmpeg command manually to reproduce and diagnose.","Install a full ffmpeg build that includes pcm_s16le and required muxers.","Validate the input file with `ffprobe -i <file>` before calling WritePcmFile.","Ensure bitRate and sampleRate arguments are within ffmpeg's accepted ranges."],"exampleFix":"// before\nDefaultAudioProfile.WritePcmFile(content, outPath, bitRate: 999999999);\n\n// after\nDefaultAudioProfile.WritePcmFile(content, outPath, bitRate: 192000);\n// and check the exception's embedded stderr for ffmpeg's reason","handlingStrategy":"try-catch","validationCode":"// Validate input decodability and ffmpeg encoder availability first\nExternalTool.Run(\"ffmpeg\", $\"-i \\\"{content.FileName}\\\" -hide_banner\", out _, out _);","typeGuard":null,"tryCatchPattern":"try { DefaultAudioProfile.WritePcmFile(content, outPath, bitRate); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ffmpeg exited\"))\n{ /* read embedded stderr; check encoder support and input validity */ }","preventionTips":["Use a full ffmpeg build including pcm_s16le and required muxers.","Validate the source file decodes with ffmpeg before conversion.","Keep bitRate/sampleRate within ffmpeg's accepted ranges."],"tags":["audio","content-pipeline","ffmpeg","external-tool","pcm","conversion"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}