DrKLO/Telegram · error
opus_repacketizer_cat() failed: %s\n
Error message
opus_repacketizer_cat() failed: %s\n
What it means
opus_repacketizer_cat() returned a status other than OPUS_OK when adding a packet to the repacketizer context. This library function validates the packet before merging it: it checks that the packet is a valid Opus packet and that its configuration (sample rate, frame size, mode, bandwidth) is compatible with packets already in the buffer. The specific error code is translated to a human-readable string by opus_strerror(). After the error, the loop breaks but the tool does not exit immediately — it proceeds to output whatever packets were successfully buffered.
Source
Thrown at TMessagesProj/jni/opus/src/repacketizer_demo.c:149
fprintf(stderr, "Invalid payload length\n");
fclose(fin);
fclose(fout);
return EXIT_FAILURE;
}
break;
}
err = fread(ch, 1, 4, fin);
rng[i] = char_to_int(ch);
err = fread(packets[i], 1, len[i], fin);
if (feof(fin))
{
eof = 1;
break;
}
err = opus_repacketizer_cat(rp, packets[i], len[i]);
if (err!=OPUS_OK)
{
fprintf(stderr, "opus_repacketizer_cat() failed: %s\n", opus_strerror(err));
break;
}
}
nb_packets = i;
if (eof)
break;
if (!split)
{
err = opus_repacketizer_out(rp, 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;
}View on GitHub (pinned to 45ab8f4308)
Solutions
- Ensure all packets being merged come from the same encoder session with identical configuration (same sample rate, channels, application, frame size).
- Log the opus_strerror output to identify the specific failure (OPUS_INVALID_PACKET vs OPUS_BAD_ARG).
- Validate each packet with opus_packet_parse before feeding it to the repacketizer.
- Reduce the merge count to isolate which packet triggers the error.
Example fix
// before
err = opus_repacketizer_cat(rp, packets[i], len[i]);
if (err != OPUS_OK) {
fprintf(stderr, "opus_repacketizer_cat() failed: %s\n", opus_strerror(err));
break;
}
// after: validate packet compatibility before cat
int toc = packets[i][0];
int frame_size_check = opus_packet_get_nb_samples(packets[i], len[i], 48000);
if (frame_size_check <= 0) {
fprintf(stderr, "Skipping invalid packet at index %d\n", i);
continue;
}
err = opus_repacketizer_cat(rp, packets[i], len[i]);
if (err != OPUS_OK) {
fprintf(stderr, "opus_repacketizer_cat() failed: %s\n", opus_strerror(err));
break;
} Defensive patterns
Strategy: validation
Validate before calling
// Validate packet before calling opus_repacketizer_cat
int safe_cat(OpusRepacketizer *rp, const unsigned char *data, int len) {
// Check packet looks valid
if (len < 1 || data[0] == 0) return OPUS_INVALID_PACKET;
int ret = opus_repacketizer_cat(rp, data, len);
if (ret != OPUS_OK) {
fprintf(stderr, "cat failed: %s (len=%d, toc=0x%02x)\n",
opus_strerror(ret), len, data[0]);
}
return ret;
} Try / catch
if ((err = opus_repacketizer_cat(rp, data, len)) != OPUS_OK) {
fprintf(stderr, "cat failed: %s\n", opus_strerror(err));
// optionally: skip this packet and continue, or abort
break;
} Prevention
- Ensure all packets originate from the same encoder session with identical configuration.
- Validate packet TOC byte and frame count with opus_packet_get_nb_frames before merging.
- Log the TOC byte and length of each packet to diagnose configuration mismatches.
- Use opus_repacketizer_init before each batch to start with a clean state.
When it happens
Trigger: Merging packets from different encoder instances with different configurations; merging packets with different frame sizes (e.g., 20ms and 40ms); merging a CELT-mode packet with a SILK-mode packet; passing a malformed or truncated packet payload; exceeding the maximum merged packet size. The most common error code is OPUS_INVALID_PACKET.
Common situations: Concatenating packets from different audio streams; a bug in the packet-generation step producing malformed packets; mixing narrowband and wideband packets; version mismatch between encoder and the repacketizer API.
Related errors
- opus_repacketizer_out() failed: %s\n
- usage: %s [options] input_file output_file\n
- -merge parameter must be at least 1.\n
- -merge parameter must be less than 48.\n
- Unknown option: %s\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/7e9bd8cfe7a4eddc.
Report an issue: GitHub.