fix(encoder): always use the calculated PTS with corrected math

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x
2024-12-16 00:00:00 +00:00
parent 33ee43a088
commit 5884dd1ba4
7 changed files with 39 additions and 39 deletions

View File

@@ -253,10 +253,12 @@ int Encoder::write_frame(AVFrame *frame, int64_t frame_idx) {
AVFrame *converted_frame = nullptr;
int ret;
// Set the frame's presentation timestamp if not set
if (frame->pts <= 0) {
frame->pts = frame_idx;
}
// Let the encoder decide the frame type
frame->pict_type = AV_PICTURE_TYPE_NONE;
// Calculate this frame's presentation timestamp (PTS)
frame->pts = frame_idx * (enc_ctx_->time_base.den * enc_ctx_->framerate.den /
(enc_ctx_->time_base.num * enc_ctx_->framerate.num));
// Convert the frame to the encoder's pixel format if needed
if (frame->format != enc_ctx_->pix_fmt) {