我需要使用 PHP ffmpeg
每秒制作 24 帧.这是当前的格式
$t = mktime(0, 0, 0, 1, 1, 98);
后来我用这个功能
exec("/usr/local/bin/ffmpeg -ss " . date("H:i:s", $t) . " -i {$file} -f mjpeg -vframes 1 -s {$size} {$tmpfile}");
在
date("H:i:s", $t)
我需要制作 date("H:i:s.milliseconds", $t)
.这不起作用date("H:i:s.u", $t)
因为mktime
格式(小时,分钟,秒,日。月,年)我猜。那么,是否可以将毫秒添加到
mktime
?
最佳答案
我认为打印用户定义的“H:i:s.u”时间的最简单解决方案是使用 DateTime::setTime 和 DateTime::format ,它支持微秒:
echo (new DateTime())->setTime(1, 2, 3, 456789)->format('H:i:s.u');
结果:
01:02:03.456789
这意味着您的 PHP 可以这样编写:
<?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}");
关于php - 如何以毫秒为单位制作 `mktime` 格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58024544/