DrKLO/Telegram · error

Failed to create the encoder: %s\n

Error message

Failed to create the encoder: %s\n

What it means

opus_custom_encoder_create(mode, channels, &err) set err to a non-zero error code. The mode was created successfully but the encoder object for the given channel count could not be built. The message prints opus_strerror(err) for the detail. Both open files are closed before returning.

Source

Thrown at TMessagesProj/jni/opus/celt/opus_custom_demo.c:107

   fin = fopen(inFile, "rb");
   if (!fin)
   {
      fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
      return 1;
   }
   outFile = argv[argc-1];
   fout = fopen(outFile, "wb+");
   if (!fout)
   {
      fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
      fclose(fin);
      return 1;
   }

   enc = opus_custom_encoder_create(mode, channels, &err);
   if (err != 0)
   {
      fprintf(stderr, "Failed to create the encoder: %s\n", opus_strerror(err));
      fclose(fin);
      fclose(fout);
      return 1;
   }
   dec = opus_custom_decoder_create(mode, channels, &err);
   if (err != 0)
   {
      fprintf(stderr, "Failed to create the decoder: %s\n", opus_strerror(err));
      fclose(fin);
      fclose(fout);
      return 1;
   }
   opus_custom_decoder_ctl(dec, OPUS_GET_LOOKAHEAD(&skip));

   if (argc>7)
   {
      complexity=atoi(argv[5]);
      opus_custom_encoder_ctl(enc,OPUS_SET_COMPLEXITY(complexity));

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Validate channels is 1 or 2 before creating the encoder.
  2. Read the printed opus_strerror to identify OPUS_BAD_ARG vs allocation failure.
  3. Match channels to the mode's design; if the mode expects mono, pass 1.
  4. Free memory / reduce concurrent allocations if it's an allocation failure.

Example fix

// before
channels = atoi(argv[2]); // user passes 0 or 3
enc = opus_custom_encoder_create(mode, channels, &err);

// after
channels = atoi(argv[2]);
if (channels != 1 && channels != 2) { fprintf(stderr, "channels must be 1 or 2\n"); return 1; }
enc = opus_custom_encoder_create(mode, channels, &err);
Defensive patterns

Strategy: validation

Validate before calling

// Validate channels before creating the encoder.
channels = atoi(argv[2]);
if (channels != 1 && channels != 2) { fprintf(stderr, "channels must be 1 or 2\n"); return 1; }

Prevention

When it happens

Trigger: err != OPUS_OK. Typically OPUS_BAD_ARG when channels is not 1 or 2, or when the mode is inconsistent with the requested channels; or an allocation failure inside the encoder. channels comes from atoi(argv[2]) and is unchecked.

Common situations: Passing channels=0 or a value >2; passing a channel count the custom mode wasn't designed for; memory pressure during encoder allocation; a mode created with parameters incompatible with mono/stereo.

Related errors


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