From db52a61b010b83a98b517528b95c5d24be1cc2fd Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 15 Apr 2016 15:22:58 -0400 Subject: [PATCH] More debugging and restore copying lastkeyframe. Also init videoStore to NULL so that we don't crash --- src/zm_ffmpeg_camera.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 15d48c7d3..c563e7d19 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -61,6 +61,7 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::stri mOpenStart = 0; mReopenThread = 0; wasRecording = false; + videoStore = NULL; #if HAVE_LIBSWSCALE mConvertContext = NULL; @@ -350,7 +351,8 @@ int FfmpegCamera::OpenFfmpeg() { if ( mAudioStreamId == -1 ) Debug( 2, "Unable to locate audio stream in %s", mPath.c_str() ); - Debug ( 1, "Found video stream" ); + Debug ( 3, "Found video stream at index %d", mVideoStreamId ); + Debug ( 3, "Found audio stream at index %d", mAudioStreamId ); mCodecContext = mFormatContext->streams[mVideoStreamId]->codec; @@ -397,7 +399,7 @@ int FfmpegCamera::OpenFfmpeg() { Fatal("Image size mismatch. Required: %d Available: %d",pSize,imagesize); } - Debug ( 1, "Validated imagesize" ); + Debug ( 1, "Validated imagesize %d", pSize ); #if HAVE_LIBSWSCALE Debug ( 1, "Calling sws_isSupportedInput" ); @@ -579,9 +581,11 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi avpicture_fill( (AVPicture *)mFrame, directbuffer, imagePixFormat, width, height); //Keep the last keyframe so we can establish immediate video - /*if(packet.flags & AV_PKT_FLAG_KEY) - av_copy_packet(&lastKeyframePkt, &packet);*/ - //TODO I think we need to store the key frame location for seeking as part of the event + if(packet.flags & AV_PKT_FLAG_KEY) { + Debug(3, "Have keyframe"); + av_copy_packet(&lastKeyframePkt, &packet); + //TODO I think we need to store the key frame location for seeking as part of the event + } //Video recording if ( recording && !wasRecording ) { @@ -591,6 +595,9 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); wasRecording = true; strcpy(oldDirectory, event_file); + + + // Need to write out all the frames from the last keyframe? } else if ( ( ! recording ) && wasRecording && videoStore ) { Info("Deleting videoStore instance"); @@ -649,9 +656,10 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi } if ( videoStore && recording ) { if ( record_audio ) { - Debug(3, "Recording audio packet" ); + Debug(3, "Recording audio packet streamindex(%d) packetstreamindex(%d)", mAudioStreamId, packet.stream_index ); //Write the packet to our video store - int ret = videoStore->writeAudioFramePacket(&packet, mFormatContext->streams[packet.stream_index]); //FIXME no relevance of last key frame + //FIXME no relevance of last key frame + int ret = videoStore->writeAudioFramePacket( &packet, mFormatContext->streams[packet.stream_index] ); if ( ret < 0 ) {//Less than zero and we skipped a frame av_free_packet( &packet ); return 0;