elsayed85/thumbnail

v2.0.0 2022-07-17 17:40 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:05:57 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads composer.lock

网页上的Wiki

索引

这是什么

  • 为给定的视频生成缩略图(图像)
  • 这使用 FFMpeg
  • 将视频转换为WebM格式。

版本

1.4.5

兼容性

注意:对于 1.4.3 及更早版本的文档,请参阅 这里

安装依赖软件

此包依赖于 FFMpeg,这是一个跨平台的完整解决方案,用于记录、转换和流式传输音频和视频,即多媒体。

在 16.04 (Xenial Xerus) LTS 上安装 FFMpeg

  • 运行以下命令安装 FFMpeg

    sudo apt-get update
    sudo apt-get install ffmpeg

在 Ubuntu 14.04 LTS 上安装 FFMpeg

  • 添加 mc3man ppa

    sudo add-apt-repository ppa:mc3man/trusty-media
  • 运行以下命令更新软件包列表。

    sudo apt-get update
    sudo apt-get update sudo apt-get dist-upgrade
  • 现在 FFmpeg 可通过 apt 安装,运行此命令

    sudo apt-get install ffmpeg
    

在 CentOS 上安装 FFMpeg

  • 启用 EPEL 存储库

    • 对于 centos 6

         rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm
    • 对于 centos 5

         rpm -Uvh http://mirrors.kernel.org/fedora-epel/5/i386/epel-release-5-4.noarch.rpm
    • 对于 centos 7

         yum install epel-release
  • 使用以下命令检查 EPEL 存储库是否启用

       yum repolist
  • 导入 Nux Dextop 存储库的官方 GPG 密钥

       rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
Nux Dextop 是一个第三方 RPM 存储库,其中包含许多流行的桌面和多媒体相关软件包(例如 Ardour、Shutter 等)用于 CentOS、RHEL 和 ScientificLinux。目前,Nux Dextop 存储库适用于 CentOS/RHEL 6 和 7。
  • 使用以下 yum 命令安装 Nux Dextop。

    • centos 6

      rpm -Uvh http://li.nux.ro/download/nux/dextop/el6/x86_64/nux-dextop-release-0-2.el6.nux.noarch.rpm
    • centos 7

      rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
  • 现在验证 Nux Dextop 存储库是否已成功安装

       yum repolist
  • 运行以下命令安装 FFMpeg

       yum install ffmpeg

在 Windows 上安装 FFMpeg

参考以下链接

WikiHow

AdapticeSolutions

安装

  • 此包可在 packagist 上找到
    composer require lakshmaji/thumbnail
  • 将服务提供商添加到 providers 数组中
Lakshmaji\Thumbnail\ThumbnailServiceProvider::class,
  • 将外观添加到 aliases 数组中
'Thumbnail' => Lakshmaji\Thumbnail\Facade\Thumbnail::class,
  • 尝试使用 composer 更新应用程序(依赖项,但不是必需的 😉 )
  composer update

配置

  • 发布配置文件,这将发布 thumbnail.php 文件到您的应用程序 config 目录。
    php artisan vendor:publish
  • 配置所需的 FFMpeg 配置。
  • FFMpeg 将自动检测 ffmpeg 和 ffprobe 二进制文件。如果您想明确指定二进制文件路径,可以在 .env 文件中配置它们。
  • 您可以在 .env 文件中指定输出图像尺寸。(dimensions 数组参数)
  • 将水印或播放按钮 URL 添加到 thumbnail.php 中可用的 watermark 数组中
  • 或者,您可以从 laravel .env 文件中配置它们,以下是 .env 文件中示例水印资源配置
#Thumbnail image dimensions
THUMBNAIL_IMAGE_WIDTH  = 320
THUMBNAIL_IMAGE_HEIGHT = 240

#Watermark image
WATERMARK_IMAGE = true
WATERMARK_PATH  = /var/www/html/thumb/storage/watermark/p.png

#Custom FFMPEG binaries path
FFMPEG_BINARIES = true
FFMPEG_PATH     = /opt/local/ffmpeg/bin/ffmpeg
FFPROBE_PATH    = /opt/local/ffmpeg/bin/ffprobe
FFMPEG_TIMEOUT  = 3600
FFMPEG_THREADS  = 12

这确保所有生成的带有水印的缩略图都具有固定尺寸

生成缩略图

以下示例说明了 Thumbnail 包的用法

<?php 

namespace Trending\Http\Controllers\File;

use Carbon;
use Thumbnail;
use Illuminate\Http\Request;
use Trending\Http\Controllers\Controller;


/**
 * -----------------------------------------------------------------------------
 *   ThumbnailTest - a class illustarting the usage og Thumbnail package 
 * -----------------------------------------------------------------------------
 * This class having the functionality to upload a video file 
 * and generate corresponding thumbnail
 *
 * @since    1.0.0
 * @version  1.0.0
 * @author   lakshmaji 
 */
class ThumbnailTest extends AnotherClass
{
  public function testThumbnail()
  {
    // get file from input data
    $file             = $this->request->file('file');

    // get file type
    $extension_type   = $file->getClientMimeType();
    
    // set storage path to store the file (actual video)
    $destination_path = storage_path().'/uploads';

    // get file extension
    $extension        = $file->getClientOriginalExtension();


    $timestamp        = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
    $file_name        = $timestamp;
    
    $upload_status    = $file->move($destination_path, $file_name);         

    if($upload_status)
    {
      // file type is video
      // set storage path to store the file (image generated for a given video)
      $thumbnail_path   = storage_path().'/images';

      $video_path       = $destination_path.'/'.$file_name;

      // set thumbnail image name
      $thumbnail_image  = $fb_user_id.".".$timestamp.".jpg";
      
      // set the thumbnail image "palyback" video button
      $water_mark       = storage_path().'/watermark/p.png';

      // get video length and process it
      // assign the value to time_to_image (which will get screenshot of video at that specified seconds)
      $time_to_image    = floor(($data['video_length'])/2);


      $thumbnail_status = Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,$time_to_image);
      if($thumbnail_status)
      {
        echo "Thumbnail generated";
      }
      else
      {
        echo "thumbnail generation has failed";
      }
    }
  }
}
// end of class ThumbnailTest
// end of file ThumbnailTest.php  

方法

$thumbnail_status = Thumbnail::getThumbnail(<VIDEO_SOURCE_DIRECTORY>,<THUMBNAIL_STORAGE_DIRECTORY>,<THUMBNAIL_NAME>);
$thumbnail_status = Thumbnail::getThumbnail(<VIDEO_SOURCE_DIRECTORY>,<THUMBNAIL_STORAGE_DIRECTORY>,<THUMBNAIL_NAME>,<TIME_TO_TAKE_SCREENSHOT>);

注意:从版本 1.4.4 开始,一些方法参数已弃用。对于此包的早期版本(<=1.4.3),请参阅 这里。水印和输出图像(缩略图)尺寸可以配置在 app/config.php 文件中。

杂项

  • 要生成带有播放按钮的缩略图图像(视频截图)
    • 您的控制器类
    Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,$time_to_image);
    • 您的配置文件
    'watermark' => [
            'image' => [
                'enabled' => env('WATERMARK_IMAGE', true),
                'path'    => env('WATERMARK_PATH', 'http://voluntarydba.com/pics/YouTube%20Play%20Button%20Overlay.png'),
            ],
            'video' => [
                'enabled' => env('WATERMARK_VIDEO', false),
                'path'    => env('WATERMARK_PATH', ''),
            ],
    ],
  • 要生成缩略图图像(视频截图)
  Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image);
  • 将视频转换为WebM格式
            $video_path = $destination_path.'/'.$file_name; // source video path
                        $clipped_video  = $destination_path.'/'.'clipped_'.$file_name; // converted video file
 
Thumbnail::clipWebM($video_path,$clipped_video);

许可证

MIT