在PHP中上传视频的持续时间


Duration of an uploaded video in PHP

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

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

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

函数shell_exec以字符串形式返回所有输出。Exec只返回最后一行。

试试这个

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