Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carry over any full seconds due to rounding within TimeCode::fromSeconds #735

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/FFMpeg/Coordinate/TimeCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ public static function fromSeconds($quantity)
{
$minutes = $hours = $frames = 0;

$frames = round(100 * ($quantity - floor($quantity)));
$seconds = floor($quantity);
$carriedOverWholeSeconds = 0; // Becomes 1 if rounded frames is 100

$frames = (int)round(100 * ($quantity - floor($quantity)));

if ($frames === 100) {
$frames = 0;
$carriedOverWholeSeconds = 1;
}

$seconds = floor($quantity) + $carriedOverWholeSeconds;

if ($seconds > 59) {
$minutes = floor($seconds / 60);
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Coordinate/TimeCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function provideSeconds()
return array(
array(0.467, '00:00:00.47'),
array(12.467, '00:00:12.47'),
array(58.9949, '00:00:58.99'),
array(58.999, '00:00:59.00'),
array(59.867, '00:00:59.87'),
array(59.999, '00:01:00.00'),
array(72.467, '00:01:12.47'),
array(3599.467, '00:59:59.47'),
array(3600.467, '01:00:00.47'),
Expand Down