From e953b5d14b4ea9a507d707fe8c40337a484e152a Mon Sep 17 00:00:00 2001 From: MrDave Date: Sat, 3 Sep 2016 08:48:38 -0600 Subject: [PATCH] Timelapse fps and regression fixes --- event.c | 4 ++-- ffmpeg.c | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/event.c b/event.c index 533afe3d..2be1e6d6 100644 --- a/event.c +++ b/event.c @@ -796,14 +796,14 @@ static void event_ffmpeg_timelapse(struct context *cnt, MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: Events will be appended to file"); cnt->ffmpeg_timelapse = ffmpeg_open(codec_mpg,cnt->timelapsefilename, y, u, v - ,cnt->imgs.width, cnt->imgs.height, 24 + ,cnt->imgs.width, cnt->imgs.height, cnt->conf.frame_limit ,cnt->conf.ffmpeg_bps,cnt->conf.ffmpeg_vbr,TIMELAPSE_APPEND); } else { MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: Timelapse using mpeg4 codec."); MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: Events will be trigger new files"); cnt->ffmpeg_timelapse = ffmpeg_open(codec_mpeg ,cnt->timelapsefilename, y, u, v - ,cnt->imgs.width, cnt->imgs.height, 1 + ,cnt->imgs.width, cnt->imgs.height, cnt->conf.frame_limit ,cnt->conf.ffmpeg_bps,cnt->conf.ffmpeg_vbr,TIMELAPSE_NEW); } diff --git a/ffmpeg.c b/ffmpeg.c index 17452ba9..050da61c 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -421,10 +421,11 @@ struct ffmpeg *ffmpeg_open(const char *ffmpeg_video_codec, char *filename, ffmpeg->video_st->time_base.num = 1; ffmpeg->video_st->time_base.den = 1000; - if (strcmp(ffmpeg_video_codec, "swf") == 0) { + if ((strcmp(ffmpeg_video_codec, "swf") == 0) || + (ffmpeg->tlapse != TIMELAPSE_NONE) ) { ffmpeg->video_st->time_base.num = 1; ffmpeg->video_st->time_base.den = rate; - if (rate > 50){ + if ((rate > 50) && (strcmp(ffmpeg_video_codec, "swf") == 0)){ MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s The FPS could be too high for the SWF container. Consider other choices."); } } @@ -671,18 +672,19 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic){ my_packet_unref(pkt); return -2; } + } + if (ffmpeg->tlapse == TIMELAPSE_APPEND) { + retcd = timelapse_append(ffmpeg, pkt); + } else if (ffmpeg->tlapse == TIMELAPSE_NEW) { + retcd = av_write_frame(ffmpeg->oc, &pkt); + } else { pts_interval = ((1000000L * (tv1.tv_sec - ffmpeg->start_time.tv_sec)) + tv1.tv_usec - ffmpeg->start_time.tv_usec) + 10000; pkt.pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},ffmpeg->video_st->time_base); if (pkt.pts < 1) pkt.pts = 1; pkt.dts = pkt.pts; - -// MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: pts:%d dts:%d stream:%d interval %d",pkt.pts,pkt.dts,ffmpeg->video_st->time_base.den,pts_interval); - } - if (ffmpeg->tlapse == TIMELAPSE_APPEND) { - retcd = timelapse_append(ffmpeg, pkt); - } else { retcd = av_write_frame(ffmpeg->oc, &pkt); } +// MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: pts:%d dts:%d stream:%d interval %d",pkt.pts,pkt.dts,ffmpeg->video_st->time_base.den,pts_interval); my_packet_unref(pkt); if (retcd != 0) {