MCPcopy Create free account
hub / github.com/Motion-Project/motion / ffmpeg_set_pts

Function ffmpeg_set_pts

src/ffmpeg.c:448–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448static int ffmpeg_set_pts(struct ffmpeg *ffmpeg, const struct timeval *tv1)
449{
450
451 int64_t pts_interval;
452
453 if (ffmpeg->tlapse != TIMELAPSE_NONE) {
454 ffmpeg->last_pts++;
455 ffmpeg->picture->pts = ffmpeg->last_pts;
456 } else {
457 pts_interval = ((1000000L * (tv1->tv_sec - ffmpeg->start_time.tv_sec)) + tv1->tv_usec - ffmpeg->start_time.tv_usec);
458 if (pts_interval < 0) {
459 /* This can occur when we have pre-capture frames. Reset start time of video. */
460 ffmpeg_reset_movie_start_time(ffmpeg, tv1);
461 pts_interval = 0;
462 }
463 if (ffmpeg->last_pts < 0) {
464 // This is the very first frame, ensure PTS is zero
465 ffmpeg->picture->pts = 0;
466 } else
467 ffmpeg->picture->pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},ffmpeg->video_st->time_base) + ffmpeg->base_pts;
468
469 if (ffmpeg->test_mode == TRUE) {
470 MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO
471 ,_("PTS %"PRId64" Base PTS %"PRId64" ms interval %"PRId64" timebase %d-%d")
472 ,ffmpeg->picture->pts,ffmpeg->base_pts,pts_interval
473 ,ffmpeg->video_st->time_base.num,ffmpeg->video_st->time_base.den);
474 }
475
476 if (ffmpeg->picture->pts <= ffmpeg->last_pts) {
477 //We have a problem with our motion loop timing and sending frames or the rounding into the PTS.
478 if (ffmpeg->test_mode == TRUE) {
479 MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("BAD TIMING!! Frame skipped."));
480 }
481 return -1;
482 }
483 ffmpeg->last_pts = ffmpeg->picture->pts;
484 }
485 return 0;
486}
487
488static int ffmpeg_set_pktpts(struct ffmpeg *ffmpeg, const struct timeval *tv1)
489{

Callers 1

ffmpeg_put_frameFunction · 0.85

Calls 1

Tested by

no test coverage detected