diff --git a/lib/codeclib.c b/lib/codeclib.c index 24ff22cef..79e1e5dbc 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -1349,9 +1349,13 @@ static int packetizer_samplestream(AVPacket *pkt, GString *buf, str *input_outpu // most common case: new input packet has just enough (or more) data as what we need if (G_LIKELY(pkt && buf->len == 0 && pkt->size >= input_output->len)) { memcpy(input_output->s, pkt->data, input_output->len); - if (pkt->size > input_output->len) // any leftovers? + // any leftovers? + if (pkt->size > input_output->len) { g_string_append_len(buf, (char *) pkt->data + input_output->len, pkt->size - input_output->len); + enc->packet_pts = pkt->pts + input_output->len + * (enc->def->bits_per_sample * enc->def->clockrate_mult / 8); + } return buf->len >= input_output->len ? 1 : 0; } // we have to move data around. append input packet to buffer if we have one @@ -1363,6 +1367,9 @@ static int packetizer_samplestream(AVPacket *pkt, GString *buf, str *input_outpu // copy requested data into provided output buffer and remove from interim buffer memcpy(input_output->s, buf->str, input_output->len); g_string_erase(buf, 0, input_output->len); + // adjust output pts + enc->avpkt.pts = enc->packet_pts; + enc->packet_pts += input_output->len * (enc->def->bits_per_sample * enc->def->clockrate_mult / 8); return buf->len >= input_output->len ? 1 : 0; } diff --git a/lib/codeclib.h b/lib/codeclib.h index 10efeaa92..7af12fdce 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -239,6 +239,7 @@ struct encoder_s { AVPacket avpkt; AVAudioFifo *fifo; int64_t fifo_pts; // pts of first data in fifo + int64_t packet_pts; // first pts of data in packetizer buffer int ptime; int bitrate; int samples_per_frame; // for encoding