Skip to content

Commit

Permalink
Merge pull request #14 from seabasss/fix/rounding-duration-seconds
Browse files Browse the repository at this point in the history
Add multiple duration calculation methods in Timecode class
  • Loading branch information
dbpolito authored Nov 5, 2024
2 parents d8ae864 + 92e5da8 commit 68174d1
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion src/Timecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,60 @@ public function calculateFrameCountWithDropFrame() : float
}

/**
* Get total of seconds based on frame count
* Get total duration in seconds based on frame count, rounded down to the nearest second
*
* @return int
*/
public function durationInSeconds() : int
{
return (int) ($this->frameCount / $this->frameRate);
}

/**
* Get total duration in seconds based on frame count, rounded to the nearest second
*
* @return int
*/
public function durationInSecondsRounded() : int
{
return (int) round($this->frameCount / $this->frameRate);
}

/**
* Get total duration in seconds based on frame count, rounded to the nearest second
* Ensures a minimum of 1 second if frames are present
*
* @return int
*/
public function durationInSecondsRoundedMinOne() : int
{
if ($this->frameCount === 0) {
return 0;
}

return max(1, (int) round($this->frameCount / $this->frameRate));
}

/**
* Get total duration in seconds based on frame count, rounded up to the nearest second
*
* @return int
*/
public function durationInSecondsRoundedUp() : int
{
return (int) ceil($this->frameCount / $this->frameRate);
}

/**
* Get total duration in seconds with fractional precision based on frame count
*
* @return float
*/
public function durationInSecondsWithFractions() : float
{
return $this->frameCount / $this->frameRate;
}

/**
* Adds a timecode or a frame count to the current SMPTE object
*
Expand Down

0 comments on commit 68174d1

Please sign in to comment.