From 7496dc392fdd2e7cd00f352d0ac24038f9636a4b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 21 Jun 2016 14:06:07 -0400 Subject: [PATCH 1/4] get rid of use of separator, just use \n --- src/zm_ffmpeg.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 767359abd..6392f2d9e 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -349,15 +349,8 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output) int flags = (is_output ? ic->oformat->flags : ic->iformat->flags); AVStream *st = ic->streams[i]; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); - unsigned char *separator = ic->dump_separator; - char **codec_separator = (char **)av_opt_ptr(st->codec->av_class, st->codec, "dump_separator"); - int use_format_separator = !*codec_separator; - if (use_format_separator) - *codec_separator = av_strdup((const char *)separator); avcodec_string(buf, sizeof(buf), st->codec, is_output); - if (use_format_separator) - av_freep(codec_separator); Debug(3, " Stream #%d:%d", index, i); /* the pid is an important information, so we display it */ @@ -389,7 +382,7 @@ void zm_dump_stream_format(AVFormatContext *ic, int i, int index, int is_output) int tbc = st->codec->time_base.den && st->codec->time_base.num; if (fps || tbr || tbn || tbc) - Debug(3, "%s", separator); + Debug(3, "\n" ); if (fps) zm_log_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps"); From 25f7a8cadfd02c4cca0a9b6109bf7ff49f7af800 Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Sat, 9 Jul 2016 22:31:01 +1000 Subject: [PATCH 2/4] Restore lost fixes for deprecation --- src/zm_ffmpeg.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 6392f2d9e..7a2c966d4 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -197,11 +197,23 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint } /* Fill in the buffers */ - if(!avpicture_fill( (AVPicture*)input_avframe, (uint8_t*)in_buffer, in_pf, width, height ) ) { +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + if (av_image_fill_arrays(input_avframe->data, input_avframe->linesize, + (uint8_t*) in_buffer, in_pf, width, height, 1) <= 0) { +#else + if (avpicture_fill((AVPicture*) input_avframe, (uint8_t*) in_buffer, + in_pf, width, height) <= 0) { +#endif Error("Failed filling input frame with input buffer"); return -7; } - if(!avpicture_fill( (AVPicture*)output_avframe, out_buffer, out_pf, width, height ) ) { +#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0) + if (av_image_fill_arrays(output_avframe->data, output_avframe->linesize, + out_buffer, out_pf, width, height, 1) <= 0) { +#else + if (avpicture_fill((AVPicture*) output_avframe, out_buffer, out_pf, width, + height) <= 0) { +#endif Error("Failed filling output frame with output buffer"); return -8; } @@ -330,8 +342,7 @@ int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat } } -static void zm_log_fps(double d, const char *postfix) -{ +static void zm_log_fps(double d, const char *postfix) { uint64_t v = lrintf(d * 100); if (!v) { Debug(3, "%1.4f %s", d, postfix); From 5d2ece0063667bdbcd94d4696d4eb8d11c39f13d Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Sun, 10 Jul 2016 11:57:08 +1000 Subject: [PATCH 3/4] Why are these failing --- src/zm_ffmpeg.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 7a2c966d4..4af4055a4 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -150,14 +150,14 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint Error("NULL Input or output buffer"); return -1; } - if(in_pf == 0 || out_pf == 0) { - Error("Invalid input or output pixel formats"); - return -2; - } - if(!width || !height) { - Error("Invalid width or height"); - return -3; - } + // if(in_pf == 0 || out_pf == 0) { + // Error("Invalid input or output pixel formats"); + // return -2; + // } + // if(!width || !height) { + // Error("Invalid width or height"); + // return -3; + // } #if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0) /* Warn if the input or output pixelformat is not supported */ From f1b9e1205ad199913cf56d3fdda9fdd7e8de3e0d Mon Sep 17 00:00:00 2001 From: Steve Gilvarry Date: Tue, 12 Jul 2016 23:13:02 +1000 Subject: [PATCH 4/4] Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio --- src/zm_ffmpeg_camera.cpp | 59 ++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index ecf965767..deb5f5e4e 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -597,7 +597,16 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi if ( recording && !wasRecording ) { //Instantiate the video storage module - videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); + if (mAudioStreamId == -1 && !record_audio) { + videoStore = new VideoStore((const char *) event_file, "mp4", + mFormatContext->streams[mVideoStreamId], + NULL, startTime); + } else { + videoStore = new VideoStore((const char *) event_file, "mp4", + mFormatContext->streams[mVideoStreamId], + mFormatContext->streams[mAudioStreamId], + startTime); + } wasRecording = true; strcpy(oldDirectory, event_file); @@ -606,24 +615,38 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi delete videoStore; videoStore = NULL; } - - //The directory we are recording to is no longer tied to the current event. Need to re-init the videostore with the correct directory and start recording again - if ( recording && wasRecording && (strcmp(oldDirectory, event_file) != 0 ) && (packet.flags & AV_PKT_FLAG_KEY) ) { - // don't open new videostore until we're on a key frame..would this require an offset adjustment for the event as a result?... - // if we store our key frame location with the event will that be enough? + + // The directory we are recording to is no longer tied to the current + // event. Need to re-init the videostore with the correct directory and + // start recording again + if (recording && wasRecording && (strcmp(oldDirectory, event_file) != 0) + && (packet.flags & AV_PKT_FLAG_KEY)) { + // Don't open new videostore until we're on a key frame..would this + // require an offset adjustment for the event as a result?...if we store + // our key frame location with the event will that be enough? Info("Re-starting video storage module"); if(videoStore){ delete videoStore; videoStore = NULL; - } + } - videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime); + if (mAudioStreamId == -1 && !record_audio) { + videoStore = new VideoStore((const char *) event_file, "mp4", + mFormatContext->streams[mVideoStreamId], + NULL, startTime); + } else { + videoStore = new VideoStore((const char *) event_file, "mp4", + mFormatContext->streams[mVideoStreamId], + mFormatContext->streams[mAudioStreamId], + startTime); + } strcpy(oldDirectory, event_file); } if ( videoStore && recording ) { //Write the packet to our video store - int ret = videoStore->writeVideoFramePacket(&packet, mFormatContext->streams[mVideoStreamId]);//, &lastKeyframePkt); + int ret = videoStore->writeVideoFramePacket(&packet, + mFormatContext->streams[mVideoStreamId]); //, &lastKeyframePkt); if(ret<0){//Less than zero and we skipped a frame av_free_packet( &packet ); return 0; @@ -632,13 +655,20 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi #if HAVE_LIBSWSCALE if ( mConvertContext == NULL ) { - mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL ); + mConvertContext = sws_getContext(mCodecContext->width, + mCodecContext->height, + mCodecContext->pix_fmt, + width, height, + imagePixFormat, SWS_BICUBIC, NULL, + NULL, NULL); if ( mConvertContext == NULL ) Fatal( "Unable to create conversion context for %s", mPath.c_str() ); - } + } - if ( sws_scale( mConvertContext, mRawFrame->data, mRawFrame->linesize, 0, mCodecContext->height, mFrame->data, mFrame->linesize ) < 0 ) - Fatal( "Unable to convert raw format %u to target format %u at frame %d", mCodecContext->pix_fmt, imagePixFormat, frameCount ); + if (sws_scale(mConvertContext, mRawFrame->data, mRawFrame->linesize, + 0, mCodecContext->height, mFrame->data, mFrame->linesize) < 0) + Fatal("Unable to convert raw format %u to target format %u at frame %d", + mCodecContext->pix_fmt, imagePixFormat, frameCount); #else // HAVE_LIBSWSCALE Fatal( "You must compile ffmpeg with the --enable-swscale option to use ffmpeg cameras" ); #endif // HAVE_LIBSWSCALE @@ -650,7 +680,8 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi if ( record_audio ) { Debug(4, "Recording audio packet" ); //Write the packet to our video store - int ret = videoStore->writeAudioFramePacket(&packet, mFormatContext->streams[packet.stream_index]); //FIXME no relevance of last key frame + int ret = videoStore->writeAudioFramePacket(&packet, + mFormatContext->streams[packet.stream_index]); //FIXME no relevance of last key frame if ( ret < 0 ) {//Less than zero and we skipped a frame av_free_packet( &packet ); return 0;