| 446 | } |
| 447 | |
| 448 | static 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 | |
| 488 | static int ffmpeg_set_pktpts(struct ffmpeg *ffmpeg, const struct timeval *tv1) |
| 489 | { |
no test coverage detected