你如何使用PHP计算mp4视频的持续时间/长度?

时间:2011-02-11 05:45:14

标签: php mp4

如何使用php获取/计算mp4视频的持续时间/长度?

I tried using this但它仅适用于f4v。 :其中你可以帮我解决mp4案例吗?

3 个答案:

答案 0 :(得分:4)

我无法让tandu的解决方案正常运行。

这最终对我有用:

$ffmpeg_output = shell_exec("ffmpeg -i \"$file\" 2>&1");
if( preg_match('/.*Duration: ([0-9:]+).*/', $ffmpeg_output, $matches) ) {
    echo $matches[1];
} else {
    echo "$file failed\n";
}

希望这有助于某人。

答案 1 :(得分:2)

我最近也想这样做。我做了很多关于它的研究,并且在php中没有本机方式。一个建议是ffmpeg-php,但它似乎对我不起作用。另一种方法是使用命令行ffmpeg:

exec("ffmpeg -i \"{$videofile}\" 2>&1");
$search='/Duration: (.*?),/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);

答案 2 :(得分:1)

这可以通过使用php-reader库在纯php中完成。这个库是纯php中ISO Base Media File Format, or ISO/IEC 14496-12的完整实现。然后,您可以信任持续时间的元数据标头,也可以根据stbl框自行计算。

相关问题