From 76226ca69c5c22a986982f796be52f00a636b3c9 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Jul 2024 14:44:51 -0400 Subject: [PATCH] When using wallclock timestamps, redo the calc and set video_first_dts --- src/zm_videostore.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index c44d0367a..a546247f3 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -1288,9 +1288,17 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr zm_packet) pkt_guard.acquire(opkt); if (monitor->WallClockTimestamps()) { - Microseconds useconds = std::chrono::duration_cast( - zm_packet->timestamp - SystemTimePoint(Microseconds(video_first_pts))); - opkt->pts = opkt->dts = av_rescale_q(useconds.count(), AV_TIME_BASE_Q, video_in_stream->time_base); + int64_t ts = static_cast(std::chrono::duration_cast(zm_packet->timestamp.time_since_epoch()).count()); + if (video_first_dts == AV_NOPTS_VALUE) { + Debug(2, "Starting video first_dts will become %" PRId64, ts); + video_first_dts = ts; + } + opkt->pts = opkt->dts = av_rescale_q(ts-video_first_dts, AV_TIME_BASE_Q, video_in_stream->time_base); + + Debug(2, "dts from timestamp, set to (%" PRId64 ") secs(%.2f), minus first_dts %" PRId64 " = %" PRId64, + ts, + FPSeconds(zm_packet->timestamp.time_since_epoch()).count(), + video_first_dts, ts - video_first_dts); } else if (ipkt->dts != AV_NOPTS_VALUE) { if (video_first_dts == AV_NOPTS_VALUE) { Debug(2, "Starting video first_dts will become %" PRId64, ipkt->dts);