{"record":{"id":"efa731c91a2aa9f6","repo":"DrKLO/Telegram","slug":"initialization-failed","errorCode":null,"errorMessage":"Initialization failed.","messagePattern":"Initialization failed\\.","errorType":"exception","errorClass":"FfmpegDecoderException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java","lineNumber":71,"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":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Build FFmpeg with the required decoders enabled and confirm FfmpegLibrary.getCodecName(sampleMimeType) is non-null.","Ensure the Format carries correct initializationData, sampleRate, and channelCount before instantiation.","Fall back to the platform decoder when FFmpeg initialization fails."],"exampleFix":"// before\n// FFmpeg built without --enable-decoder=libfdk_aac\n\n// after\n// rebuild FFmpeg extension with the required codec enabled for the sampleMimeType","handlingStrategy":"try-catch","validationCode":"// validate codec + init data before constructing\nString codec = FfmpegLibrary.getCodecName(format.sampleMimeType);\nboolean ok = codec != null && format.initializationData != null\n    && format.sampleRate > 0 && format.channelCount > 0;\nif (!ok) { /* fix Format or skip FFmpeg */ }","typeGuard":null,"tryCatchPattern":"try { new FfmpegAudioDecoder(format, nIn, nOut, bufSize, outputFloat); }\ncatch (FfmpegDecoderException e) { /* fall back to platform decoder */ }","preventionTips":["Build FFmpeg with the decoders you need enabled.","Ensure Format carries correct initializationData/sampleRate/channelCount.","Always provide a platform-decoder fallback."],"tags":["audio","exoplayer","ffmpeg","native-library","codec-init","jni"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}