diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 1484d5234..82471c3dc 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -231,8 +231,8 @@ int FfmpegCamera::Capture(std::shared_ptr &zm_packet) { zm_packet->set_packet(&packet); zm_packet->stream = stream; zm_packet->pts = av_rescale_q(packet.pts, stream->time_base, AV_TIME_BASE_Q); - if ( packet.pts != AV_NOPTS_VALUE ) { - if ( stream == mVideoStream ) { + if (packet.pts != AV_NOPTS_VALUE) { + if (stream == mVideoStream) { if (mFirstVideoPTS == AV_NOPTS_VALUE) mFirstVideoPTS = packet.pts; diff --git a/src/zm_packet.cpp b/src/zm_packet.cpp index 3361667e0..55a78721e 100644 --- a/src/zm_packet.cpp +++ b/src/zm_packet.cpp @@ -83,7 +83,7 @@ ZMPacket::ZMPacket(ZMPacket &p) : av_init_packet(&packet); packet.size = 0; packet.data = nullptr; - if ( zm_av_packet_ref(&packet, &p.packet) < 0 ) { + if (zm_av_packet_ref(&packet, &p.packet) < 0) { Error("error refing packet"); } } diff --git a/src/zm_packet.h b/src/zm_packet.h index 66a6250ca..9cce4dd03 100644 --- a/src/zm_packet.h +++ b/src/zm_packet.h @@ -66,7 +66,7 @@ class ZMPacket { Image *set_image(Image *); int is_keyframe() { return keyframe; }; - int decode( AVCodecContext *ctx ); + int decode(AVCodecContext *ctx); explicit ZMPacket(Image *image, SystemTimePoint tv); explicit ZMPacket(ZMPacket &packet); ZMPacket(); @@ -88,6 +88,7 @@ class ZMLockedPacket { lck_(packet_->mutex_, std::defer_lock), locked(false) { } + ~ZMLockedPacket() { if (locked) unlock(); } diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 67f31cabc..1bd0724d5 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -93,6 +93,7 @@ VideoStore::VideoStore( converted_in_samples(nullptr), filename(filename_in), format(format_in), + video_first_pts(0), video_first_dts(0), audio_first_pts(0), audio_first_dts(0), @@ -990,23 +991,24 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr &zm_packet frame->pkt_duration = 0; if (!video_first_pts) { - video_first_pts = zm_packet->timestamp.time_since_epoch().count(); + video_first_pts = static_cast(std::chrono::duration_cast(zm_packet->timestamp.time_since_epoch()).count()); Debug(2, "No video_first_pts, set to (%" PRId64 ") secs(%.2f)", video_first_pts, FPSeconds(zm_packet->timestamp.time_since_epoch()).count()); frame->pts = 0; } else { + Microseconds useconds = std::chrono::duration_cast( zm_packet->timestamp - SystemTimePoint(Microseconds(video_first_pts))); frame->pts = av_rescale_q(useconds.count(), AV_TIME_BASE_Q, video_out_ctx->time_base); Debug(2, - "Setting pts for frame(%d) to (%" PRId64 ") from (start %" PRIu64 " - %" PRIu64 " - us(%" PRIi64 ") @ %d/%d", + "Setting pts for frame(%d) to (%" PRId64 ") from (zm_packet->timestamp(%" PRIi64 " - first %" PRId64 " us %" PRId64 " ) @ %d/%d", frame_count, frame->pts, + static_cast(std::chrono::duration_cast(zm_packet->timestamp.time_since_epoch()).count()), video_first_pts, static_cast(std::chrono::duration_cast(useconds).count()), - static_cast(std::chrono::duration_cast(zm_packet->timestamp.time_since_epoch()).count()), video_out_ctx->time_base.num, video_out_ctx->time_base.den); }