从视频文件生成预览图像?
PHP 有没有办法给定视频文件(.mov
、.mp4
)来生成缩略图预览?
Is there a way in PHP given a video file (.mov
, .mp4
) to generate a thumbnail image preview?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案#1(较旧)(不推荐)
首先安装
ffmpeg-php
项目 (http: //ffmpeg-php.sourceforge.net/)然后你可以使用这个简单的代码:
描述:这个项目使用二进制扩展
.so
文件,它非常旧,上次更新是 2008 年。因此,可能不适用于较新版本的FFMpeg
或PHP
。解决方案#2(更新2018)(推荐)
首先安装
PHP-FFMpeg
项目(https://github.com/PHP-FFMpeg/PHP-FFMpeg)(只需运行安装:
composer require php-ffmpeg/php-ffmpeg
)然后您可以使用这个简单的代码:
描述:它是更新、更现代的项目,可与最新版本的
FFMpeg
和PHP
配合使用。请注意,它是proc_open()
PHP 函数所必需的。Solution #1 (Older) (not recommended)
Firstly install
ffmpeg-php
project (http://ffmpeg-php.sourceforge.net/)And then you can use of this simple code:
Description: This project use binary extension
.so
file, It's very old and last update was for 2008. So, maybe don't works with newer version ofFFMpeg
orPHP
.Solution #2 (Update 2018) (recommended)
Firstly install
PHP-FFMpeg
project (https://github.com/PHP-FFMpeg/PHP-FFMpeg)(just run for install:
composer require php-ffmpeg/php-ffmpeg
)And then you can use of this simple code:
Description: It's newer and more modern project and works with latest version of
FFMpeg
andPHP
. Note that it's required toproc_open()
PHP function.我想到了两种方法:
使用命令行工具,例如流行的 ffmpeg ,但是您几乎总是需要一个自己的服务器(或一个非常好的服务器管理员/托管公司)来实现
使用“< screenshoot" 插件="http://www.longtailvideo.com/" rel="noreferrer">LongTail 视频播放器,允许创建手动屏幕截图,然后将其发送到服务器端脚本.
Two ways come to mind:
Using a command-line tool like the popular ffmpeg, however you will almost always need an own server (or a very nice server administrator / hosting company) to get that
Using the "screenshoot" plugin for the LongTail Video player that allows the creation of manual screenshots that are then sent to a server-side script.
我推荐 php-ffmpeg 库。
如果您想从视频中提取多个图像,可以使用以下过滤器:
默认情况下,这会将帧保存为 jpg 图像。
您可以使用
setFrameFileType
覆盖此设置,以另一种格式保存帧:I recommend php-ffmpeg library.
If you want to extract multiple images from the video, you can use the following filter:
By default, this will save the frames as jpg images.
You are able to override this using
setFrameFileType
to save the frames in another format: