Ste*_*hry 12
如果您使用的是linux/unix并安装了ffmpeg,请执行以下操作:
$time = exec("ffmpeg -i " . escapeshellarg($path) . " 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
list($hms, $milli) = explode('.', $time);
list($hours, $minutes, $seconds) = explode(':', $hms);
$total_seconds = ($hours * 3600) + ($minutes * 60) + $seconds;
Run Code Online (Sandbox Code Playgroud)
/**
* /sf/answers/499483911/
* @param string $path
* @return int
*/
function getDurationOfWavInMs($path) {
$time = getDurationOfWav($path);
list($hms, $milli) = explode('.', $time);
list($hours, $minutes, $seconds) = explode(':', $hms);
$totalSeconds = ($hours * 3600) + ($minutes * 60) + $seconds;
return ($totalSeconds * 1000) + $milli;
}
/**
*
* @param string $path
* @return string
*/
function getDurationOfWav($path) {
$cmd = "ffmpeg -i " . escapeshellarg($path) . " 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//";
return exec($cmd);
}
Run Code Online (Sandbox Code Playgroud)
谢谢,斯蒂芬!这对我来说效果很好(尽管对于数百个文件来说速度很慢)。