PHP 中上传视频的时长

Duration of an uploaded video in PHP

我需要知道上传到页面的视频的时长。为此,我编写了一个 PHP 脚本:

<?php

$command = "ffmpeg -i video.mp4 2>&1 | grep Duration | awk '{print }' | tr -d ,; ";
$cm = shell_exec($command) ;
echo "$cm";

?>

当我通过终端执行这个程序时它显示了持续时间,但是在 PHP 页面中调用它时它没有给出输出。 请给我一个解决方案....

提前致谢。

函数shell_execreturns输出所有的字符串。只执行 returns 最后一行。

试试这个

<?php

$command = "ffmpeg -i video.mp4 2>&1 | grep Duration | awk '{print }' | tr -d ,; ";
echo exec($command) ;

?>