Start and stop events not just on keyframe. This means we must always queue packets

This commit is contained in:
Isaac Connor 2019-01-15 11:32:44 -05:00
parent 6608cb4e35
commit 8c53f778b6
1 changed files with 27 additions and 27 deletions

View File

@ -718,8 +718,8 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
bytes += packet.size;
dumpPacket(mFormatContext->streams[packet.stream_index], &packet, "Captured");
//Video recording
if ( keyframe && recording.tv_sec ) {
// Video recording
if ( recording.tv_sec ) {
uint32_t last_event_id = monitor->GetLastEventId();
uint32_t video_writer_event_id = monitor->GetVideoWriterEventId();
@ -800,7 +800,8 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
packet_count += 1;
//Write the packet to our video store
Debug(2, "Writing queued packet stream: %d KEY %d, remaining (%d)", avp->stream_index, avp->flags & AV_PKT_FLAG_KEY, packetqueue.size() );
Debug(2, "Writing queued packet stream: %d KEY %d, remaining (%d)",
avp->stream_index, avp->flags & AV_PKT_FLAG_KEY, packetqueue.size() );
if ( avp->stream_index == mVideoStreamId ) {
ret = videoStore->writeVideoFramePacket( avp );
have_video_keyframe = true;
@ -822,15 +823,16 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
} else {
// Not recording
if ( videoStore && keyframe ) {
Info("Deleting videoStore instance");
if ( videoStore ) {
Debug(1,"Deleting videoStore instance");
delete videoStore;
videoStore = NULL;
have_video_keyframe = false;
monitor->SetVideoWriterEventId(0);
}
if ( ! videoStore ) {
// Buffer video packets, since we are not recording.
} // end if recording or not
// Buffer video packets, we need to always have from the last keyframe buffered
// All audio packets are keyframes, so only if it's a video keyframe
if ( packet.stream_index == mVideoStreamId ) {
if ( keyframe ) {
@ -849,8 +851,6 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
packetqueue.queuePacket(&packet);
}
}
}
} // end if recording or not
if ( packet.stream_index == mVideoStreamId ) {
// only do decode if we have had a keyframe, should save a few cycles.