php - 如何以毫秒为单位制作 `mktime` 格式?

标签 php date ffmpeg milliseconds mktime

我需要使用 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::setTimeDateTime::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/

相关文章:

php - 将YouTube持续时间转换为秒

php - Laravel 和 MySQL 按周获取数据

PHP/MySQL 数组帮助需要

python - Pandas df日期按组计算

不同国家的 C# 和当前本地时间

c# - 用于合并音频和视频的 FFmpeg 命令不起作用 - C#

python - 如何在 ffmpeg-python 中使用 'shortest' 参数

php - 在 php 中捕获外键错误

javascript - 从 IE 上的日期获取时区字符串

c++ - 如何打开AVCodec?