public function getFrame($frame_number = false, $frame_rate = false) { try { $toolkit = new PHPVideoToolkit(PHPVIDEOTOOLKIT_TEMP_DIRECTORY); $tmp_name = $toolkit->unique() . '-%index.jpg'; // extract the frame $toolkit->extractFrame($frame_number, $frame_rate, '%ft'); $toolkit->setOutput(PHPVIDEOTOOLKIT_TEMP_DIRECTORY, $tmp_name, PHPVideoToolkit::OVERWRITE_EXISTING); $result = $this->_toolkit->execute(false, true); // check the image has been outputted if ($result !== PHPVideoToolkit::RESULT_OK) { return false; } $temp_output = array_shift(array_flip($toolkit->getLastOutput())); print_r($temp_output); $gd_img = imagecreatefromjpeg($temp_output); $ffmpeg_frame_time = $toolkit->formatTimecode($frame_number, '%ft', '%hh:%mm:%ss.%ms', $frame_rate); } catch (Exception $e) { echo $e; } return new ffmpeg_frame($gd_img, $ffmpeg_frame_time); }
require_once 'example-config.php'; // require the library require_once '../phpvideotoolkit.' . $use_version . '.php'; // temp directory $tmp_dir = PHPVIDEOTOOLKIT_EXAMPLE_ABSOLUTE_BATH . 'tmp/'; // set the frame rate for the timecodes $frame_rate = 25; // set the time to examine / format $timecode = '01:14:32.59'; $timecode_format = '%hh:%mm:%ss.%ms'; echo '<strong>Original Timecode</strong><br />'; echo $timecode . '<br /><br />'; // start ffmpeg class $toolkit = new PHPVideoToolkit($tmp_dir); echo '<strong>Timecode conversion to seconds</strong><br />'; echo 'Frame seconds (rounded) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%st', $frame_rate) . '<br />'; echo 'Frame seconds (rounded down) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%sf', $frame_rate) . '<br />'; echo 'Frame seconds (rounded up) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%sc', $frame_rate) . '<br />'; echo 'Frame seconds -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%mt', $frame_rate) . '<br /><br />'; echo '<strong>Timecode conversion to frames</strong><br />'; echo 'Frame number (in current second) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%fn', $frame_rate) . '<br />'; echo 'Frame number (in video) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%ft', $frame_rate) . '<br /><br />'; echo '<strong>Timecode conversion to other timecodes</strong><br />'; echo 'hh:mm -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm', $frame_rate) . '<br />'; echo 'hh:mm:ss -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm:%ss', $frame_rate) . '<br />'; echo 'hh:mm:ss.fn -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm:%ss.%fn', $frame_rate) . '<br />'; echo 'hh:mm:ss.ms -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%hh:%mm:%ss.%ms', $frame_rate) . '<br />'; echo 'mm:ss (smart minutes) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%mm:%ss', $frame_rate) . '<br />'; echo 'mm:ss.fn (smart minutes) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%mm:%ss.%fn', $frame_rate) . '<br />'; echo 'ss.ms (smart seconds) -> ' . $toolkit->formatTimecode($timecode, $timecode_format, '%ss.%ms', $frame_rate) . '<br />'; echo '</body></html>';