DrKLO/Telegram · error

opus_repacketizer_out() failed: %s\n

Error message

opus_repacketizer_out() failed: %s\n

What it means

In the merge (non-split) code path, opus_repacketizer_out() returned a value of 0 or negative, indicating failure. This function assembles all buffered packets into a single output packet; a return of 0 means the repacketizer is empty, and a negative value is an error code (decoded by opus_strerror). Common causes: the repacketizer buffer is empty because opus_repacketizer_cat failed for all packets, or the merged output exceeds MAX_PACKETOUT. Note that this branch does not exit — it only prints the error and continues the main loop.

Source

Thrown at TMessagesProj/jni/opus/src/repacketizer_demo.c:179

         if (err>0) {
            unsigned char int_field[4];
            int_to_char(err, int_field);
            if(fwrite(int_field, 1, 4, fout)!=4){
               fprintf(stderr, "Error writing.\n");
               return EXIT_FAILURE;
            }
            int_to_char(rng[nb_packets-1], int_field);
            if (fwrite(int_field, 1, 4, fout)!=4) {
               fprintf(stderr, "Error writing.\n");
               return EXIT_FAILURE;
            }
            if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {
               fprintf(stderr, "Error writing.\n");
               return EXIT_FAILURE;
            }
            /*fprintf(stderr, "out len = %d\n", err);*/
         } else {
            fprintf(stderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(err));
         }
      } else {
         int nb_frames = opus_repacketizer_get_nb_frames(rp);
         for (i=0;i<nb_frames;i++)
         {
            err = opus_repacketizer_out_range(rp, i, i+1, output_packet, MAX_PACKETOUT);
            if (err>0) {
               unsigned char int_field[4];
               int_to_char(err, int_field);
               if (fwrite(int_field, 1, 4, fout)!=4) {
                  fprintf(stderr, "Error writing.\n");
                  return EXIT_FAILURE;
               }
               if (i==nb_frames-1)
                  int_to_char(rng[nb_packets-1], int_field);
               else
                  int_to_char(0, int_field);
               if (fwrite(int_field, 1, 4, fout)!=4) {

View on GitHub (pinned to 45ab8f4308)

Solutions

  1. Reduce the -merge count to produce smaller combined packets.
  2. Check the opus_strerror output for the specific error code (OPUS_BUFFER_TOO_SMALL, OPUS_INVALID_PACKET).
  3. Ensure the input packets are from a compatible encoder configuration.
  4. Inspect whether any opus_repacketizer_cat errors preceded this failure (error 229).
Defensive patterns

Strategy: validation

Validate before calling

// Check repacketizer state before calling opus_repacketizer_out
int nb_frames = opus_repacketizer_get_nb_frames(rp);
if (nb_frames == 0) {
    fprintf(stderr, "Repacketizer is empty, skipping output.\n");
    continue;
}
int out_len = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);
if (out_len <= 0) {
    fprintf(stderr, "out failed: %s\n", opus_strerror(out_len));
    continue;
}

Try / catch

int out_len = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);
if (out_len <= 0) {
    fprintf(stderr, "opus_repacketizer_out() failed: %s\n", opus_strerror(out_len));
    // continue to next batch rather than abort
    continue;
}

Prevention

When it happens

Trigger: All opus_repacketizer_cat calls failed in the inner loop, leaving the repacketizer empty; the merged packet would exceed the output buffer (MAX_PACKETOUT=32000 bytes); the packets contain incompatible frame configurations that the repacketizer cannot combine. The `else` branch at line 178 handles this without exiting, so the loop continues to the next batch.

Common situations: Merging packets that individually are valid but together exceed the maximum packet size; repacketizer_cat silently broke the loop before any packet was added; testing edge cases with maximum-size packets.

Related errors


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