initialize video_first_pts and when setting it need to specify microseconds otherwise we get nanoseconds. White space.
This commit is contained in:
parent
1cb9f98e9b
commit
30fa641186
|
@ -231,8 +231,8 @@ int FfmpegCamera::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
|
||||||
zm_packet->set_packet(&packet);
|
zm_packet->set_packet(&packet);
|
||||||
zm_packet->stream = stream;
|
zm_packet->stream = stream;
|
||||||
zm_packet->pts = av_rescale_q(packet.pts, stream->time_base, AV_TIME_BASE_Q);
|
zm_packet->pts = av_rescale_q(packet.pts, stream->time_base, AV_TIME_BASE_Q);
|
||||||
if ( packet.pts != AV_NOPTS_VALUE ) {
|
if (packet.pts != AV_NOPTS_VALUE) {
|
||||||
if ( stream == mVideoStream ) {
|
if (stream == mVideoStream) {
|
||||||
if (mFirstVideoPTS == AV_NOPTS_VALUE)
|
if (mFirstVideoPTS == AV_NOPTS_VALUE)
|
||||||
mFirstVideoPTS = packet.pts;
|
mFirstVideoPTS = packet.pts;
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ ZMPacket::ZMPacket(ZMPacket &p) :
|
||||||
av_init_packet(&packet);
|
av_init_packet(&packet);
|
||||||
packet.size = 0;
|
packet.size = 0;
|
||||||
packet.data = nullptr;
|
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");
|
Error("error refing packet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ZMPacket {
|
||||||
Image *set_image(Image *);
|
Image *set_image(Image *);
|
||||||
|
|
||||||
int is_keyframe() { return keyframe; };
|
int is_keyframe() { return keyframe; };
|
||||||
int decode( AVCodecContext *ctx );
|
int decode(AVCodecContext *ctx);
|
||||||
explicit ZMPacket(Image *image, SystemTimePoint tv);
|
explicit ZMPacket(Image *image, SystemTimePoint tv);
|
||||||
explicit ZMPacket(ZMPacket &packet);
|
explicit ZMPacket(ZMPacket &packet);
|
||||||
ZMPacket();
|
ZMPacket();
|
||||||
|
@ -88,6 +88,7 @@ class ZMLockedPacket {
|
||||||
lck_(packet_->mutex_, std::defer_lock),
|
lck_(packet_->mutex_, std::defer_lock),
|
||||||
locked(false) {
|
locked(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~ZMLockedPacket() {
|
~ZMLockedPacket() {
|
||||||
if (locked) unlock();
|
if (locked) unlock();
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ VideoStore::VideoStore(
|
||||||
converted_in_samples(nullptr),
|
converted_in_samples(nullptr),
|
||||||
filename(filename_in),
|
filename(filename_in),
|
||||||
format(format_in),
|
format(format_in),
|
||||||
|
video_first_pts(0),
|
||||||
video_first_dts(0),
|
video_first_dts(0),
|
||||||
audio_first_pts(0),
|
audio_first_pts(0),
|
||||||
audio_first_dts(0),
|
audio_first_dts(0),
|
||||||
|
@ -990,23 +991,24 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
|
||||||
frame->pkt_duration = 0;
|
frame->pkt_duration = 0;
|
||||||
|
|
||||||
if (!video_first_pts) {
|
if (!video_first_pts) {
|
||||||
video_first_pts = zm_packet->timestamp.time_since_epoch().count();
|
video_first_pts = static_cast<int64>(std::chrono::duration_cast<Microseconds>(zm_packet->timestamp.time_since_epoch()).count());
|
||||||
Debug(2, "No video_first_pts, set to (%" PRId64 ") secs(%.2f)",
|
Debug(2, "No video_first_pts, set to (%" PRId64 ") secs(%.2f)",
|
||||||
video_first_pts,
|
video_first_pts,
|
||||||
FPSeconds(zm_packet->timestamp.time_since_epoch()).count());
|
FPSeconds(zm_packet->timestamp.time_since_epoch()).count());
|
||||||
|
|
||||||
frame->pts = 0;
|
frame->pts = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Microseconds useconds = std::chrono::duration_cast<Microseconds>(
|
Microseconds useconds = std::chrono::duration_cast<Microseconds>(
|
||||||
zm_packet->timestamp - SystemTimePoint(Microseconds(video_first_pts)));
|
zm_packet->timestamp - SystemTimePoint(Microseconds(video_first_pts)));
|
||||||
frame->pts = av_rescale_q(useconds.count(), AV_TIME_BASE_Q, video_out_ctx->time_base);
|
frame->pts = av_rescale_q(useconds.count(), AV_TIME_BASE_Q, video_out_ctx->time_base);
|
||||||
Debug(2,
|
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_count,
|
||||||
frame->pts,
|
frame->pts,
|
||||||
|
static_cast<int64>(std::chrono::duration_cast<Microseconds>(zm_packet->timestamp.time_since_epoch()).count()),
|
||||||
video_first_pts,
|
video_first_pts,
|
||||||
static_cast<int64>(std::chrono::duration_cast<Microseconds>(useconds).count()),
|
static_cast<int64>(std::chrono::duration_cast<Microseconds>(useconds).count()),
|
||||||
static_cast<int64>(std::chrono::duration_cast<Microseconds>(zm_packet->timestamp.time_since_epoch()).count()),
|
|
||||||
video_out_ctx->time_base.num,
|
video_out_ctx->time_base.num,
|
||||||
video_out_ctx->time_base.den);
|
video_out_ctx->time_base.den);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue