试图找到ffmpeg的持续时间

时间:2013-01-17 12:04:03

标签: php ffmpeg

  

可能重复:
  PHP Function to get MP3 duration

我目前获得了以下用于获取视频时长的代码

$file = "videos/the_video.mp4";
passthru("ffmpeg -i ".$file." 2>&1");
$duration = ob_get_contents();
$search='/Duration: (.*?)[.]/';

$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE);
$duration = $matches[1][0];

我如何使用MP3?

1 个答案:

答案 0 :(得分:1)

如果你想要一个没有ffmpeg的解决方案,你可以使用getID3:

http://getid3.sourceforge.net/

此处找到源代码示例:

http://www.talkphp.com/general/2600-php-get-mp3-song-length.html

require_once('/path/to/getid3.php'); 

$getID3 = new getID3; 
$filename = "/path/to/mp3"; 

$ThisFileInfo = $getID3->analyze($filename); 
getid3_lib::CopyTagsToComments($ThisFileInfo); 

echo @$ThisFileInfo['playtime_string'];