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