-1

I need make 24 frames per second with PHP ffmpeg. This is current format of

$t = mktime(0, 0, 0, 1, 1, 98);

Later I use this function

exec("/usr/local/bin/ffmpeg -ss " . date("H:i:s", $t) . " -i {$file} -f mjpeg -vframes 1 -s {$size} {$tmpfile}");

In date("H:i:s", $t) I need make date("H:i:s.milliseconds", $t). This is not working date("H:i:s.u", $t) because of mktime format (hours, minutes, seconds, day. month, years) I guess.

So, is it possible to add milliseconds to mktime?

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36

1 Answers1

1

I think the simplest solution to print a user defined "H:i:s.u" time is using DateTime::setTime with DateTime::format, which supports microsecond:

echo (new DateTime())->setTime(1, 2, 3, 456789)->format('H:i:s.u');

Result:

01:02:03.456789

That means your PHP can be written as such:

<?php

$hour = 1; $minute = 1; $second = 98;
$millisecond = 123; // or whatever
$t = (new DateTime())->setTime($hour, $minute, $second, $millisecond * 1000);

exec("/usr/local/bin/ffmpeg -ss {$t->format('H:i:s.v')} -i {$file} -f mjpeg -vframes 1 -s {$size} {$tmpfile}");
Koala Yeung
  • 7,475
  • 3
  • 30
  • 50