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

Add HOURS:MM:SS.MICROSECONDS output option to TimeCode #549

Open
artyuum opened this issue Jul 24, 2018 · 1 comment
Open

Add HOURS:MM:SS.MICROSECONDS output option to TimeCode #549

artyuum opened this issue Jul 24, 2018 · 1 comment

Comments

@artyuum
Copy link

artyuum commented Jul 24, 2018

Hi, is there a way to specify a format for the returned duration time ?
Example for a video of 5 seconds, the following code returns the following value :

$duration = $ffprobe->format('file.mp4')->get('duration');
echo $duration;

// Output
5

I'd like to be able to add the sexagesimal option in order to get the duration time in the following format : HOURS:MM:SS.MICROSECONDS.

Is it possible to do that with the current version of your wrapper ?

@jens1o jens1o changed the title Get video duration in the specified format Add HOURS:MM:SS.MICROSECONDS output option to TimeCode Jul 24, 2018
@jens1o jens1o added this to the 1.x milestone Jul 24, 2018
@jens1o
Copy link
Member

jens1o commented Jul 24, 2018

No, it's not. But it should be possible with little code of yourself.

/**
* Creates timecode from number of seconds.
*
* @param float $quantity
*
* @return TimeCode
*/
public static function fromSeconds($quantity)
{
$minutes = $hours = $frames = 0;
$frames = round(100 * ($quantity - floor($quantity)));
$seconds = floor($quantity);
if ($seconds > 59) {
$minutes = floor($seconds / 60);
$seconds = $seconds % 60;
}
if ($minutes > 59) {
$hours = floor($minutes / 60);
$minutes = $minutes % 60;
}
return new static($hours, $minutes, $seconds, $frames);
}

But I'd be willing to add another method to TimeCode to make it accessible for anyone. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants