我有一个上传到服务器的flv文件。我想用以下格式“分钟:秒”显示其持续时间。任何人都可以帮我吗?
谢谢
答案 0 :(得分:7)
还有一个FFMPEG PHP扩展即。 apt-get install php5-ffmpeg
然后
$movie = new ffmepg_movie("path/to/movie.flv"); $duration_in_seconds = $movie->getDuration();
这对我以前有用。该扩展适用于检索元数据并测试上传的文件是否为FLV等
答案 1 :(得分:4)
这是我的代码,用于抓取一个帧并从视频中生成图像......
// get the duration and a random place within that
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
exec($cmd);
// get the screenshot
exec("ffmpeg -i " . $videoPath . " -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg " . $imageOutput . " 2>&1");
$ second变量是0到总持续时间之间的随机数。 第二个exec()是从选定的框架创建一个图像文件。
$ imageOutput是生成图像的绝对路径位置。 例如:/home/ariawan/image-generated.jpg
答案 2 :(得分:3)
我使用getID3 PHP library
,用普通的旧PHP编写,没有任何依赖。
它不仅以秒为单位为您提供.flv
电影的持续时间,还将其转换为minute:seconds
格式。以下是v.1.7.9(最新稳定版getid3
)的代码示例:
<?php
// getId3 library uses deprecated eregi_* functions
// which generate errors under PHP 5.3 - so I excluded them
error_reporting(E_ALL ^ E_DEPRECATED);
// just for debugging/sample
header('Content-Type: text/plain');
// include the getid3 base class in order to use the lib
require_once('./lib/getid3.php');
// path to your .flv file
$filename = './sample.flv';
$getID3 = new getID3();
$fileInfo = $getID3->analyze($filename);
// echoes something like 127.8743
print 'Playtime in seconds: ' . $fileInfo['playtime_seconds'];
print chr(10);
// echoes something like: 2:07
print 'Playtime in minute:seconds format: ' . $fileInfo['playtime_string'];
答案 3 :(得分:2)
我使用php和ffmpeg来获取视频的持续时间。
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
}
exec($cmd);
print_r()要查看的$ time变量。 确保在你的机器上安装ffmpeg .. 希望这会有所帮助。