From 709cf08760bb74c16412e5075cd7e2e95f08321f Mon Sep 17 00:00:00 2001 From: k4yt3x Date: Sat, 21 Dec 2024 00:00:00 +0000 Subject: [PATCH] fix(encoder): decreasing PTS precision with increasing video duration (#1269) Signed-off-by: k4yt3x --- CHANGELOG.md | 6 ++++++ src/encoder.cpp | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b03ec32..b643967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +- The issue of decreasing PTS precision with increasing video duration (#1269). + ## [6.3.0] - 2024-12-20 ### Added diff --git a/src/encoder.cpp b/src/encoder.cpp index f0c67d1..7b732f3 100644 --- a/src/encoder.cpp +++ b/src/encoder.cpp @@ -262,8 +262,7 @@ int Encoder::write_frame(AVFrame *frame, int64_t frame_idx) { 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)); + frame->pts = av_rescale_q(frame_idx, av_inv_q(enc_ctx_->framerate), enc_ctx_->time_base); // Convert the frame to the encoder's pixel format if needed if (frame->format != enc_ctx_->pix_fmt) {