Skip to content

Commit 793080e

Browse files
authored
Merge pull request #152 from Mr-DaveDev/ffmpeg-fixes
Timelapse fps and regression fixes
2 parents 802c228 + e953b5d commit 793080e

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

event.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,14 @@ static void event_ffmpeg_timelapse(struct context *cnt,
796796
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: Events will be appended to file");
797797
cnt->ffmpeg_timelapse =
798798
ffmpeg_open(codec_mpg,cnt->timelapsefilename, y, u, v
799-
,cnt->imgs.width, cnt->imgs.height, 24
799+
,cnt->imgs.width, cnt->imgs.height, cnt->conf.frame_limit
800800
,cnt->conf.ffmpeg_bps,cnt->conf.ffmpeg_vbr,TIMELAPSE_APPEND);
801801
} else {
802802
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: Timelapse using mpeg4 codec.");
803803
MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: Events will be trigger new files");
804804
cnt->ffmpeg_timelapse =
805805
ffmpeg_open(codec_mpeg ,cnt->timelapsefilename, y, u, v
806-
,cnt->imgs.width, cnt->imgs.height, 1
806+
,cnt->imgs.width, cnt->imgs.height, cnt->conf.frame_limit
807807
,cnt->conf.ffmpeg_bps,cnt->conf.ffmpeg_vbr,TIMELAPSE_NEW);
808808
}
809809

ffmpeg.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,11 @@ struct ffmpeg *ffmpeg_open(const char *ffmpeg_video_codec, char *filename,
421421

422422
ffmpeg->video_st->time_base.num = 1;
423423
ffmpeg->video_st->time_base.den = 1000;
424-
if (strcmp(ffmpeg_video_codec, "swf") == 0) {
424+
if ((strcmp(ffmpeg_video_codec, "swf") == 0) ||
425+
(ffmpeg->tlapse != TIMELAPSE_NONE) ) {
425426
ffmpeg->video_st->time_base.num = 1;
426427
ffmpeg->video_st->time_base.den = rate;
427-
if (rate > 50){
428+
if ((rate > 50) && (strcmp(ffmpeg_video_codec, "swf") == 0)){
428429
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s The FPS could be too high for the SWF container. Consider other choices.");
429430
}
430431
}
@@ -671,18 +672,19 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic){
671672
my_packet_unref(pkt);
672673
return -2;
673674
}
674-
pts_interval = ((1000000L * (tv1.tv_sec - ffmpeg->start_time.tv_sec)) + tv1.tv_usec - ffmpeg->start_time.tv_usec) + 10000;
675-
pkt.pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},ffmpeg->video_st->time_base);
676-
if (pkt.pts < 1) pkt.pts = 1;
677-
pkt.dts = pkt.pts;
678-
679-
// 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);
680675
}
681676
if (ffmpeg->tlapse == TIMELAPSE_APPEND) {
682677
retcd = timelapse_append(ffmpeg, pkt);
678+
} else if (ffmpeg->tlapse == TIMELAPSE_NEW) {
679+
retcd = av_write_frame(ffmpeg->oc, &pkt);
683680
} else {
681+
pts_interval = ((1000000L * (tv1.tv_sec - ffmpeg->start_time.tv_sec)) + tv1.tv_usec - ffmpeg->start_time.tv_usec) + 10000;
682+
pkt.pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},ffmpeg->video_st->time_base);
683+
if (pkt.pts < 1) pkt.pts = 1;
684+
pkt.dts = pkt.pts;
684685
retcd = av_write_frame(ffmpeg->oc, &pkt);
685686
}
687+
// 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);
686688
my_packet_unref(pkt);
687689

688690
if (retcd != 0) {

0 commit comments

Comments
 (0)