MonoGame/MonoGame · error · InvalidOperationException
ffmpeg exited with non-zero exit code: {ffmpegStdout} {ffmp
Error message
ffmpeg exited with non-zero exit code:
{ffmpegStdout}
{ffmpegStderr} What it means
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.
Source
Thrown at MonoGame.Framework.Content.Pipeline/Audio/DefaultAudioProfile.cs:279
reader.BaseStream.Seek(reader.ReadInt32(), SeekOrigin.Current);
}
}
var dataSize = reader.ReadInt32();
data = reader.ReadBytes(dataSize);
return data;
}
public static void WritePcmFile(AudioContent content, string saveToFile, int bitRate = 192000, int? sampeRate = null)
{
var sampleArg = sampeRate != null ? $"-ar {sampeRate.Value}" : string.Empty;
var ffmpegExitCode = FFmpeg.Run(
$"-y -i \"{content.FileName}\" -vn -c:a pcm_s16le -b:a {bitRate} {sampleArg} -f:a wav -strict experimental \"{saveToFile}\"",
out var ffmpegStdout,
out var ffmpegStderr);
if (ffmpegExitCode != 0)
throw new InvalidOperationException($"ffmpeg exited with non-zero exit code: \n{ffmpegStdout}\n{ffmpegStderr}");
}
public static ConversionQuality ConvertToFormat(AudioContent content, ConversionFormat formatType, ConversionQuality quality, string? saveToFile)
{
var temporaryOutput = Path.GetTempFileName();
try
{
string ffmpegCodecName, ffmpegMuxerName;
//int format;
switch (formatType)
{
case ConversionFormat.Adpcm:
// ADPCM Microsoft
ffmpegCodecName = "adpcm_ms";
ffmpegMuxerName = "wav";
//format = 0x0002; /* WAVE_FORMAT_ADPCM */
break;
case ConversionFormat.Pcm:View on GitHub (pinned to 1d71bbd0ff)
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.
Example fix
// before DefaultAudioProfile.WritePcmFile(content, outPath, bitRate: 999999999); // after DefaultAudioProfile.WritePcmFile(content, outPath, bitRate: 192000); // and check the exception's embedded stderr for ffmpeg's reason
Defensive patterns
Strategy: try-catch
Validate before calling
// Validate input decodability and ffmpeg encoder availability first
ExternalTool.Run("ffmpeg", $"-i \"{content.FileName}\" -hide_banner", out _, out _); Try / catch
try { DefaultAudioProfile.WritePcmFile(content, outPath, bitRate); }
catch (InvalidOperationException ex) when (ex.Message.Contains("ffmpeg exited"))
{ /* read embedded stderr; check encoder support and input validity */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- ffprobe exited with non-zero exit code.
- Failed to parse ffprobe output.
- XMA is not a supported encoding format. It is specific to th
- Could not read the audio data from file "{Path.GetFileName(F
- Incorrect file type! Expected '.wav' but found '.{_fileType}
AI-assisted analysis of MonoGame/MonoGame@1d71bbd0ff (2026-08-13).
Data as JSON: /api/errors/f40acbe238e96f09.
Report an issue: GitHub.