Skip to content

Commit 1453746

Browse files
committed
PTS refinements, add test and remove ogg options
1 parent 9e4245a commit 1453746

3 files changed

Lines changed: 74 additions & 22 deletions

File tree

event.c

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,8 @@ static void event_ffmpeg_newfile(struct context *cnt,
608608
unsigned char *convbuf, *y, *u, *v;
609609
char stamp[PATH_MAX];
610610
const char *moviepath;
611+
char codec[8];
612+
long codenbr;
611613

612614
if (!cnt->conf.ffmpeg_output && !cnt->conf.ffmpeg_output_debug)
613615
return;
@@ -627,9 +629,54 @@ static void event_ffmpeg_newfile(struct context *cnt,
627629
* motion movies get the same name as normal movies plus an appended 'm'
628630
* PATH_MAX - 4 to allow for .mpg to be appended without overflow
629631
*/
630-
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%sm", cnt->conf.filepath, stamp);
631-
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s", cnt->conf.filepath, stamp);
632-
632+
/* Set up a testing / evaluation codec which will use a different
633+
* codec for the events.
634+
*/
635+
snprintf(codec, sizeof(codec), "%s", cnt->conf.ffmpeg_video_codec);
636+
if (strcmp(codec, "test") == 0) {
637+
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s Running test of the various output formats.");
638+
codenbr = cnt->event_nr;
639+
while (codenbr > 10){
640+
codenbr -= 10;
641+
}
642+
switch (codenbr) {
643+
case 1:
644+
snprintf(codec, sizeof(codec), "%s", "mpeg4");
645+
break;
646+
case 2:
647+
snprintf(codec, sizeof(codec), "%s", "msmpeg4");
648+
break;
649+
case 3:
650+
snprintf(codec, sizeof(codec), "%s", "swf");
651+
break;
652+
case 4:
653+
snprintf(codec, sizeof(codec), "%s", "flv");
654+
break;
655+
case 5:
656+
snprintf(codec, sizeof(codec), "%s", "ffv1");
657+
break;
658+
case 6:
659+
snprintf(codec, sizeof(codec), "%s", "mov");
660+
break;
661+
case 7:
662+
snprintf(codec, sizeof(codec), "%s", "mp4");
663+
break;
664+
case 8:
665+
snprintf(codec, sizeof(codec), "%s", "mkv");
666+
break;
667+
case 9:
668+
snprintf(codec, sizeof(codec), "%s", "hevc");
669+
break;
670+
default:
671+
snprintf(codec, sizeof(codec), "%s", "msmpeg4");
672+
break;
673+
}
674+
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%s_%sm", cnt->conf.filepath, codec, stamp);
675+
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s_%s", cnt->conf.filepath, codec, stamp);
676+
} else {
677+
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%sm", cnt->conf.filepath, stamp);
678+
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s", cnt->conf.filepath, stamp);
679+
}
633680
if (cnt->conf.ffmpeg_output) {
634681
if (cnt->imgs.type == VIDEO_PALETTE_GREY) {
635682
convbuf = mymalloc((width * height) / 2);
@@ -645,7 +692,7 @@ static void event_ffmpeg_newfile(struct context *cnt,
645692
}
646693

647694
if ((cnt->ffmpeg_output =
648-
ffmpeg_open(cnt->conf.ffmpeg_video_codec, cnt->newfilename, y, u, v,
695+
ffmpeg_open(codec, cnt->newfilename, y, u, v,
649696
cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps,
650697
cnt->conf.ffmpeg_vbr,TIMELAPSE_NONE)) == NULL) {
651698
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (new) file [%s]",
@@ -673,7 +720,7 @@ static void event_ffmpeg_newfile(struct context *cnt,
673720
}
674721

675722
if ((cnt->ffmpeg_output_debug =
676-
ffmpeg_open(cnt->conf.ffmpeg_video_codec, cnt->motionfilename, y, u, v,
723+
ffmpeg_open(codec, cnt->motionfilename, y, u, v,
677724
cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps,
678725
cnt->conf.ffmpeg_vbr,TIMELAPSE_NONE)) == NULL) {
679726
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (motion) file [%s]",

ffmpeg.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,6 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename){
232232
} else if (strcmp(codec, "mov") == 0) {
233233
ext = ".mov";
234234
of = av_guess_format("mov", NULL, NULL);
235-
} else if (strcmp (codec, "ogg") == 0){
236-
ext = ".ogg";
237-
of = av_guess_format ("ogg", NULL, NULL);
238235
} else if (strcmp (codec, "mp4") == 0){
239236
ext = ".mp4";
240237
of = av_guess_format ("mp4", NULL, NULL);
@@ -340,6 +337,15 @@ struct ffmpeg *ffmpeg_open(const char *ffmpeg_video_codec, char *filename,
340337
return NULL;
341338
}
342339

340+
/* Only the newer codec and containers can handle the really fast FPS */
341+
if (((strcmp(ffmpeg_video_codec, "msmpeg4") == 0) ||
342+
(strcmp(ffmpeg_video_codec, "mpeg4") == 0) ||
343+
(strcmp(ffmpeg_video_codec, "swf") == 0) ) && (rate >100)){
344+
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s The frame rate specified is too high for the ffmpeg movie type specified. Choose a different ffmpeg container or lower framerate. ");
345+
ffmpeg_cleanups(ffmpeg);
346+
return NULL;
347+
}
348+
343349
ffmpeg->c = c = AVSTREAM_CODEC_PTR(ffmpeg->video_st);
344350
c->codec_id = ffmpeg->oc->oformat->video_codec;
345351
c->codec_type = AVMEDIA_TYPE_VIDEO;
@@ -358,8 +364,6 @@ struct ffmpeg *ffmpeg_open(const char *ffmpeg_video_codec, char *filename,
358364
if (c->codec_id == MY_CODEC_ID_H264 ||
359365
c->codec_id == MY_CODEC_ID_HEVC){
360366
ffmpeg->vbr = (int)(( (100-vbr) * 51)/100);
361-
} else if (strcmp(ffmpeg_video_codec, "ogg") == 0){
362-
ffmpeg->vbr = (int)(( (100-vbr) * 10)/100);
363367
} else {
364368
ffmpeg->vbr =(int)(((100-vbr)*(100-vbr)*(100-vbr) * 8000) / 1000000) + 1;
365369
}
@@ -415,13 +419,14 @@ struct ffmpeg *ffmpeg_open(const char *ffmpeg_video_codec, char *filename,
415419
av_dict_free(&opts);
416420
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s Selected Output FPS %d", c->time_base.den);
417421

418-
if ((strcmp(ffmpeg_video_codec, "ffv1") == 0) ||
419-
(strcmp(ffmpeg_video_codec, "ogg") == 0) ){
420-
ffmpeg->video_st->time_base.num = 1;
421-
ffmpeg->video_st->time_base.den = 1000;
422-
} else {
422+
ffmpeg->video_st->time_base.num = 1;
423+
ffmpeg->video_st->time_base.den = 1000;
424+
if (strcmp(ffmpeg_video_codec, "swf") == 0) {
423425
ffmpeg->video_st->time_base.num = 1;
424426
ffmpeg->video_st->time_base.den = rate;
427+
if (rate > 50){
428+
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s The FPS could be too high for the SWF container. Consider other choices.");
429+
}
425430
}
426431

427432
ffmpeg->video_outbuf = NULL;
@@ -640,6 +645,7 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic){
640645
AVPacket pkt;
641646
char errstr[128];
642647
struct timeval tv1;
648+
int64_t pts_interval;
643649

644650
gettimeofday(&tv1, NULL);
645651

@@ -665,12 +671,12 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic){
665671
my_packet_unref(pkt);
666672
return -2;
667673
}
668-
pkt.pts = ((1000000L * (tv1.tv_sec - ffmpeg->start_time.tv_sec)) + tv1.tv_usec - ffmpeg->start_time.tv_usec)/10;
669-
pkt.pts = av_rescale_q(pkt.pts,(AVRational){1, 100000},ffmpeg->video_st->time_base);
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);
670676
if (pkt.pts < 1) pkt.pts = 1;
671-
if (pkt.pts < pkt.dts) pkt.pts=pkt.dts;
677+
pkt.dts = pkt.pts;
672678

673-
// MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: pts:%d dts:%d stream:%d ",pkt.pts,pkt.dts,ffmpeg->video_st->time_base.den);
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);
674680
}
675681
if (ffmpeg->tlapse == TIMELAPSE_APPEND) {
676682
retcd = timelapse_append(ffmpeg, pkt);

motion-dist.conf.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,8 @@ ffmpeg_variable_bitrate 0
320320
# it requires no installation of codec on the Windows client.
321321
# swf - gives you a flash film with extension .swf
322322
# flv - gives you a flash video with extension .flv
323-
# ffv1 - FF video codec 1 for Lossless Encoding ( experimental )
324-
# mov - QuickTime ( testing )
325-
# ogg - Ogg/Theora ( testing )
323+
# ffv1 - FF video codec 1 for Lossless Encoding
324+
# mov - QuickTime
326325
# mp4 - MPEG-4 Part 14 H264 encoding
327326
# mkv - Matroska H264 encoding
328327
# hevc - H.265 / HEVC (High Efficiency Video Coding)

0 commit comments

Comments
 (0)