我正在使用php(Phalcon frameWork)。
我试图用ffmpeg来做到这一点,但是它花费了太多。
我需要缩略图作为视频的屏幕截图。
还有其他解决方案(仅PHP)吗?
这是我的代码:
// where ffmpeg is located, such as /usr/sbin/ffmpeg
$ffmpeg = '/usr/bin/ffmpeg';
// the input video file
$video = BASE_PATH . "/public/uploads/video/" . $fileName;
// where you'll save the image
$image = BASE_PATH . "/public/uploads/image/" . "thumbnail-".$fileName .".jpg";
// default time to get the image
$second = 1;
// get the duration and a random place within that
$cmd = "$ffmpeg -i $video 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));
}
// get the screenshot
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg $image 2>&1";
`$cmd`;