{"record":{"id":"947d7f857105c7d2","repo":"google/ExoPlayer","slug":"initialization-failed","errorCode":null,"errorMessage":"Initialization failed.","messagePattern":"Initialization failed\\.","errorType":"exception","errorClass":"FfmpegDecoderException","httpStatus":null,"severity":"critical","filePath":"extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java","lineNumber":79,"sourceCode":"      Format format,\n      int numInputBuffers,\n      int numOutputBuffers,\n      int initialInputBufferSize,\n      boolean outputFloat)\n      throws FfmpegDecoderException {\n    super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);\n    if (!FfmpegLibrary.isAvailable()) {\n      throw new FfmpegDecoderException(\"Failed to load decoder native libraries.\");\n    }\n    Assertions.checkNotNull(format.sampleMimeType);\n    codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));\n    extraData = getExtraData(format.sampleMimeType, format.initializationData);\n    encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT;\n    outputBufferSize = outputFloat ? OUTPUT_BUFFER_SIZE_32BIT : OUTPUT_BUFFER_SIZE_16BIT;\n    nativeContext =\n        ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount);\n    if (nativeContext == 0) {\n      throw new FfmpegDecoderException(\"Initialization failed.\");\n    }\n    setInitialInputBufferSize(initialInputBufferSize);\n  }\n\n  @Override\n  public String getName() {\n    return \"ffmpeg\" + FfmpegLibrary.getVersion() + \"-\" + codecName;\n  }\n\n  @Override\n  protected DecoderInputBuffer createInputBuffer() {\n    return new DecoderInputBuffer(\n        DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DIRECT,\n        FfmpegLibrary.getInputBufferPaddingSize());\n  }\n\n  @Override\n  protected SimpleDecoderOutputBuffer createOutputBuffer() {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/extensions/ffmpeg/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java#L61-L97","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nFfmpegAudioDecoder decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);\n\n// after: guard support and fall back\nif (FfmpegLibrary.isAvailable()\n    && FfmpegLibrary.supportsFormat(format.sampleMimeType)) {\n  try {\n    decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);\n  } catch (FfmpegDecoderException e) {\n    Log.e(TAG, \"ffmpeg init failed for \" + format.sampleMimeType, e);\n    decoder = null; // renderer falls through to MediaCodec\n  }\n}","handlingStrategy":"try-catch","validationCode":"if (format.sampleMimeType != null\n    && FfmpegLibrary.isAvailable()\n    && FfmpegLibrary.supportsFormat(format.sampleMimeType)\n    && format.sampleRate != Format.NO_VALUE\n    && format.channelCount != Format.NO_VALUE) {\n  // codec is in the build and format is well-formed; init failure is now unlikely\n  decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);\n}","typeGuard":null,"tryCatchPattern":"try {\n  decoder = new FfmpegAudioDecoder(format, numIn, numOut, initialSize, outputFloat);\n} catch (FfmpegDecoderException e) {\n  if (\"Initialization failed.\".equals(e.getMessage())) {\n    // codec-specific init failed: log format details and fall back to MediaCodec\n    Log.e(TAG, \"ffmpeg init failed for \" + format.sampleMimeType, e);\n    decoder = null;\n  } else {\n    throw e;\n  }\n}","preventionTips":["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"],"tags":["android","ffmpeg","decoder-initialization","native-library"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}