How to covert seconds into SMPTE time code

Mark
Mark used Ask the Experts™
on
Example:

I have a value of 10.331667

How do I convert that to 00:00:10.33
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
MarkProgrammer

Author

Commented:
Unfortunately not. In the interim I am using ffprobe's output.
Most Valuable Expert 2011
Top Expert 2016
Commented:
PHP has no direct way to convert the SMPTE value into HH:MM:SS.TH fractions, so there will be some amount of programming involved.  This might give you a starting point.  It rounds the fractional seconds to a two-digit decimal value.
http://iconoun.com/demo/temp_mark.php

<?php // demo/temp_mark.php
/**
 * http://www.experts-exchange.com/questions/28899303/How-to-covert-seconds-into-SMPTE-time-code.html
 *
 * https://en.wikipedia.org/wiki/SMPTE_timecode
 * http://php.net/results.php?q=smpte&l=en&p=all
 *
 * http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL-Procedural-Version.html
 * http://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
 *
 * http://php.net/manual/en/datetime.formats.php
 * http://php.net/manual/en/datetime.formats.date.php
 *
 * http://php.net/manual/en/function.explode.php
 * http://php.net/manual/en/function.strtotime.php
 * http://php.net/manual/en/function.date.php
 */
error_reporting(E_ALL);
echo '<pre>';


// A FUNCTION TO CONVERT THE DATA
function smpte_timecode($dat)
{
    // ROUND THE TIME AND BREAK APART ON THE DECIMAL, GIVING SECONDS, FRACTIONS
    $dat = number_format($dat,2);
    $arr = explode('.', $dat);
    return date('H:i:s', strtotime('Today ' . $arr[0] . ' seconds'))
    . '.'
    . substr($arr[1], 0, 2)
    ;
}


// A SAMPLE CONVERSION
$dat = 10.331667;
echo PHP_EOL . $dat;
echo PHP_EOL . smpte_timecode($dat);

Open in new window

MarkProgrammer

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial