Blogger Information
Blog 43
fans 0
comment 3
visits 26529
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
windows上pbootcms(ueditor上传视频) :php使用FFMpeg获取视频第一帧为缩略图方法
Time
Original
1302 people have browsed it

1.下载FFMpeg到电脑安装

地址:http://ffmpeg.org/download.html

步骤:


将文件整体解压存放。

2.进入项目,用composer安装FFMpeg

1.在项目根目录新建一个composer.json文件,文件里写一个空对象(就是一个空的大括号)
2.初始化,执行命令:composer install
3.安装命令:composer require php-ffmpeg/php-ffmpeg

3.进入项目apps\common\function.php 文件

添加公共函数方法:

下列代码中
E:\ffmpeg\bin\ffmpeg.exe’,和 E:\ffmpeg\bin\ffprobe.exe’是步骤一安装FFMpeg存放本地盘的绝对路径

  1. /FFMpeg获取视频第一帧为图片,使用composer下载插件。处理自动加载冲突
  2. function autoloadAdjust($video_src,$ico_src)
  3. {
  4. // 取原有的加载方法
  5. $oldFunctions = spl_autoload_functions();
  6. // 逐个卸载
  7. if ($oldFunctions){
  8. foreach ($oldFunctions as $f) {
  9. spl_autoload_unregister($f);
  10. }
  11. }
  12. // 注册本框架的自动载入
  13. require $_SERVER['DOCUMENT_ROOT'] .'/vendor/autoload.php';
  14. $ffmpeg = FFMpeg\FFMpeg::create(['ffmpeg.binaries'=>'E:\ffmpeg\bin\ffmpeg.exe','ffprobe.binaries'=>'E:\ffmpeg\bin\ffprobe.exe']);
  15. $video_src = 'http://' . $_SERVER['SERVER_NAME'] . $video_src;
  16. $uqid = uniqid();//获取无序字符串
  17. $ico_img = $ico_src .'/'. $uqid . '.png'; //获取符合缩略图格式路径
  18. $ico_src_new = $_SERVER['DOCUMENT_ROOT'] . $ico_src;//获取绝对路径目录
  19. //没有文件夹,就创建
  20. if(!is_dir($ico_src_new)){
  21. mkdir($ico_src_new,0777,true);
  22. }
  23. $ico_src_new = $ico_src_new .'/'. $uqid . '.png';
  24. $video = $ffmpeg->open($video_src);//打开一个本地的视频文件
  25. $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(1));//截取视频中第几秒的截图
  26. $frame->save($ico_src_new);//保存截图
  27. // 如果引用本框架的其它框架已经定义了__autoload,要保持其使用
  28. if (function_exists('__autoload')) {
  29. spl_autoload_register('__autoload');
  30. }
  31. // 再将原来的自动加载函数放回去
  32. if ($oldFunctions){
  33. foreach ($oldFunctions as $f) {
  34. spl_autoload_register($f);
  35. }
  36. }
  37. return $ico_img;//返回图片路径
  38. }

4.进入apps\admin\controller\content\ContentController.php

函数添加代码,文章增加add函数和文章修改mod函数:

在 注释//无缩略图时,自动提取文章第一张图为缩略图上面添加下面代码

  1. $ico_src = '/static/upload/image/' . date("Ymd");
  2. // 无缩略图时,自动提取第一视频第一帧为缩略图
  3. if (!$ico && preg_match('/<source\s+.*?src=\s?[\'|\"](.*?(\.mp4|\.ogg))[\'|\"].*?[\/]?>/i', decode_string($content), $srcs_video) && isset($srcs_video[1])) {
  4. $ico = autoloadAdjust($srcs_video[1],$ico_src);
  5. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!