google/ExoPlayer · critical · FfmpegDecoderException
Initialization failed.
Error message
Initialization failed.
What it means
FfmpegDecoderException ('Initialization failed.') thrown when the native ffmpegInitialize(...) returns 0, i.e. avcodec/FFmpeg could not create a decoder context for the requested codec. By this point the native library IS loaded (that was checked first), so the failure is codec- or stream-specific: unsupported codec configuration, invalid extra data, or native allocation failure.
Source
Thrown at extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java:79
Format format,
int numInputBuffers,
int numOutputBuffers,
int initialInputBufferSize,
boolean outputFloat)
throws FfmpegDecoderException {
super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);
if (!FfmpegLibrary.isAvailable()) {
throw new FfmpegDecoderException("Failed to load decoder native libraries.");
}
Assertions.checkNotNull(format.sampleMimeType);
codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));
extraData = getExtraData(format.sampleMimeType, format.initializationData);
encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT;
outputBufferSize = outputFloat ? OUTPUT_BUFFER_SIZE_32BIT : OUTPUT_BUFFER_SIZE_16BIT;
nativeContext =
ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount);
if (nativeContext == 0) {
throw new FfmpegDecoderException("Initialization failed.");
}
setInitialInputBufferSize(initialInputBufferSize);
}
@Override
public String getName() {
return "ffmpeg" + FfmpegLibrary.getVersion() + "-" + codecName;
}
@Override
protected DecoderInputBuffer createInputBuffer() {
return new DecoderInputBuffer(
DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT,
FfmpegLibrary.getInputBufferPaddingSize());
}
@Override
protected SimpleDecoderOutputBuffer createOutputBuffer() {View on GitHub (pinned to dd430f7053)
Solutions
- Confirm the codec is actually in your FFmpeg build (FfmpegLibrary.supportsFormat(mime) and the build flags used for the natives)
- Inspect the Format: sampleRate, channelCount and initializationData must be populated correctly by the extractor for that container
- Catch FfmpegDecoderException and let the renderer fall back to the platform decoder for that format
- Free decoder instances and retry if the device is under native memory pressure
Example fix
// before
FfmpegAudioDecoder decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);
// after: guard support and fall back
if (FfmpegLibrary.isAvailable()
&& FfmpegLibrary.supportsFormat(format.sampleMimeType)) {
try {
decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);
} catch (FfmpegDecoderException e) {
Log.e(TAG, "ffmpeg init failed for " + format.sampleMimeType, e);
decoder = null; // renderer falls through to MediaCodec
}
} Defensive patterns
Strategy: try-catch
Validate before calling
if (format.sampleMimeType != null
&& FfmpegLibrary.isAvailable()
&& FfmpegLibrary.supportsFormat(format.sampleMimeType)
&& format.sampleRate != Format.NO_VALUE
&& format.channelCount != Format.NO_VALUE) {
// codec is in the build and format is well-formed; init failure is now unlikely
decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);
} Try / catch
try {
decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);
} catch (FfmpegDecoderException e) {
if ("Initialization failed.".equals(e.getMessage())) {
// codec-specific init failed: log format details and fall back to MediaCodec
Log.e(TAG, "ffmpeg init failed for " + format.sampleMimeType, e);
decoder = null;
} else {
throw e;
}
} Prevention
- Check FfmpegLibrary.supportsFormat(mime) before constructing the decoder — your FFmpeg build may not include that codec
- Ensure extractors fill sampleRate, channelCount and initializationData correctly
- Keep a platform-decoder fallback so one codec's init failure does not kill playback
When it happens
Trigger: Initializing FfmpegAudioDecoder for a sample MIME type whose FFmpeg build lacks the codec; format.initializationData (codec-specific extradata, e.g. AAC AudioSpecificConfig) malformed or absent; channelCount/sampleRate zero or nonsensical in the Format; native memory pressure during avcodec_open.
Common situations: Custom FFmpeg builds compiled without the needed decoders (--disable-everything minus the codec list); broken streams created by non-standard muxers; device memory exhaustion when many decoders open.
Related errors
- Failed to initialize decoder. Error: ${gav1GetErrorMessage(g
- Failed to load decoder native libraries.
- Failed to load decoder native library.
- Buffer render error: ${gav1GetErrorMessage(gav1DecoderContex
- Initialization data must be of length 1
AI-assisted analysis of google/ExoPlayer@dd430f7053 (2026-08-14).
Data as JSON: /api/errors/947d7f857105c7d2.
Report an issue: GitHub.