DrKLO/Telegram · error · FfmpegDecoderException

Initialization failed.

Error message

Initialization failed.

What it means

After confirming the FFmpeg libraries loaded, FfmpegAudioDecoder calls the native ffmpegInitialize(codecName, extraData, outputFloat, sampleRate, channelCount). If it returns 0 the constructor throws FfmpegDecoderException('Initialization failed.'), meaning the native codec context could not be created for the given parameters.

Source

Thrown at TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java:71

      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 45ab8f4308)

Solutions

  1. Build FFmpeg with the required decoders enabled and confirm FfmpegLibrary.getCodecName(sampleMimeType) is non-null.
  2. Ensure the Format carries correct initializationData, sampleRate, and channelCount before instantiation.
  3. Fall back to the platform decoder when FFmpeg initialization fails.

Example fix

// before
// FFmpeg built without --enable-decoder=libfdk_aac

// after
// rebuild FFmpeg extension with the required codec enabled for the sampleMimeType
Defensive patterns

Strategy: try-catch

Validate before calling

// validate codec + init data before constructing
String codec = FfmpegLibrary.getCodecName(format.sampleMimeType);
boolean ok = codec != null && format.initializationData != null
    && format.sampleRate > 0 && format.channelCount > 0;
if (!ok) { /* fix Format or skip FFmpeg */ }

Try / catch

try { new FfmpegAudioDecoder(format, nIn, nOut, bufSize, outputFloat); }
catch (FfmpegDecoderException e) { /* fall back to platform decoder */ }

Prevention

When it happens

Trigger: ffmpegInitialize returns 0 due to an unsupported codec name, malformed/missing extraData (codec-specific config), invalid sample rate or channel count, or an FFmpeg build that lacks the requested decoder.

Common situations: FFmpeg was compiled without the needed codec (--enable-decoder); the Format's initializationData (extraData) is empty or corrupt; sampleRate/channelCount set to NO_VALUE or unsupported.

Related errors


AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14). Data as JSON: /api/errors/efa731c91a2aa9f6. Report an issue: GitHub.