From 48c18ca4ed4517b3e2a7697dc791cd38bb268c85 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 23 Dec 2022 09:02:41 -0500 Subject: [PATCH] Attempt to better handle 32bit wrap around in the pts in the input stream. --- src/zm_ffmpeg_camera.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index cb6c9dff8..d9a16f3c7 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -188,6 +188,7 @@ int FfmpegCamera::Capture(std::shared_ptr &zm_packet) { start_read_time = std::chrono::steady_clock::now(); int ret; AVFormatContext *formatContextPtr; + int64_t lastPTS; if ( mSecondFormatContext and ( @@ -197,12 +198,14 @@ int FfmpegCamera::Capture(std::shared_ptr &zm_packet) { ) ) { // if audio stream is behind video stream, then read from audio, otherwise video formatContextPtr = mSecondFormatContext; + lastPTS = mLastAudioPTS; Debug(4, "Using audio input because audio PTS %" PRId64 " < video PTS %" PRId64, av_rescale_q(mLastAudioPTS, mAudioStream->time_base, AV_TIME_BASE_Q), av_rescale_q(mLastVideoPTS, mVideoStream->time_base, AV_TIME_BASE_Q) ); } else { formatContextPtr = mFormatContext; + lastPTS = mLastVideoPTS; Debug(4, "Using video input because %" PRId64 " >= %" PRId64, (mAudioStream?av_rescale_q(mLastAudioPTS, mAudioStream->time_base, AV_TIME_BASE_Q):0), av_rescale_q(mLastVideoPTS, mVideoStream->time_base, AV_TIME_BASE_Q) @@ -224,6 +227,11 @@ int FfmpegCamera::Capture(std::shared_ptr &zm_packet) { } return -1; } + if ((packet->pts < 0) and (lastPTS >=0)) { + // 32-bit wrap around? + Info("Suspected 32bit wraparound in input pts. %"PRId64, packet->pts); + return -1; + } av_packet_guard pkt_guard{packet};