lakshmaji/thumbnail 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lakshmaji/thumbnail

Composer 安装命令:

composer require lakshmaji/thumbnail

包简介

Thumbnails for videos

README 文档

README

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

Wiki on web

INDEX

Index Description
What it is - Introduction
Installing FFMpeg - Installing dependency software
Installation - Installing Thumbnail package, Lararavel Integration
Docs - Methods and Description
Generating Thumbnail - Generating thumbnail image with this package
Miscellaneous - Miscellaneous content regarding method calls
License - License Information

What it is

  • Generates Thumbnail (image) for a given video
  • This uses FFMpeg.
  • Converts video to WebM format.

Version

1.4.5

Compatibility

Laravel version Thumbnail version
5.6 1.4.5
5.5 1.4.5
5.4 1.4.5
5.2 1.4.5 or 1.4.2 or 1.3.0
5.1 1.4.5 or 1.4.2 or 1.3.0
5.0 1.4.5 or 1.4.2 or 1.3.0

Note: For 1.4.3 and other earlier version documentation refer here

Installing dependency software

This package relays on FFMpeg, A complete, cross-platform solution to record, convert and stream audio and video i.e, Multimedia .

Installing FFMpeg on 16.04 (Xenial Xerus) LTS

  • Run following command to install FFMpeg

    sudo apt-get update
    sudo apt-get install ffmpeg

Installing FFMpeg on Ubuntu 14.04 LTS

  • Add the mc3man ppa

    sudo add-apt-repository ppa:mc3man/trusty-media
  • Run following command to Update the package list.

    sudo apt-get update
    sudo apt-get update sudo apt-get dist-upgrade
  • Now FFmpeg is available to be installed with apt , Run this command

    sudo apt-get install ffmpeg
    

Installing FFMpeg on CentOS

  • Enable EPEL repository

    • for centos 6

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

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

         yum install epel-release
  • Check whether EPEL respository is eabled by the following command

       yum repolist
  • Import the official GPG key of Nux Dextop repository:

       rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
Nux Dextop is a third-party RPM repository which contains many popular desktop and multimedia related packages (e.g., Ardour, Shutter, etc) for CentOS, RHEL and ScientificLinux. Currently, Nux Dextop repository is available for CentOS/RHEL 6 and 7.
  • Install Nux Dextop with yum command as follows.

    • 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
  • Now verify that Nux Dextop repository is successfully installed:

       yum repolist
  • Run following command to install FFMpeg

       yum install ffmpeg

Installing FFMpeg on Windows

Refer to the following links

WikiHow

AdapticeSolutions

Installation

  • This package is available on packagist
    composer require lakshmaji/thumbnail
  • Add the Service Provider to providers array
Lakshmaji\Thumbnail\ThumbnailServiceProvider::class,
  • Add the Facade to aliases array
'Thumbnail' => Lakshmaji\Thumbnail\Facade\Thumbnail::class,
  • Try updating the application with composer (dependencies but not mandatory 😉 )
  composer update

Configurations

  • Publish the configuration file , this will publish thumbnail.php file to your application config directory.
    php artisan vendor:publish
  • Configure the required FFMpeg configurations.
  • FFMpeg will autodetect ffmpeg and ffprobe binaries. If you want to give binary paths explicitly, you can configure them in .env file.
  • You can specify the output image dimensions in .env file. (dimensions array parameters)
  • Add watermark or playback button url to watermark arry aviable in thumbnail.php
  • Or you can configure them from laravel .env file, the sample watermark resource configurations in .env file
#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

This ensures that all the generated thumbnails with watermarks are having fixed dimensions

Generating Thumbnail

The following example illustrates the usage of Thumbnail package

<?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  

METHOD

$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>);
PARAMETER DESCRIPTION FIELD
VIDEO_SOURCE_DIRECTORY Video resource source path i.e, the name of video along with location where video is present mandatory
THUMBNAIL_STORAGE_DIRECTORY The destination path to save the generated thumbnail image mandatory
THUMBNAIL_NAME The name of Image for output mandatory
TIME_TO_TAKE_SCREENSHOT Time to take screenshot of the video optional
thumbnail image optional

Note : Some of the method parameters are deprecated from version 1.4.4. For earlier versions of this package (<=1.4.3) refer here. The watermark and output image (thumbnail image) dimensions can be configured from app/config.php file.

MISCELLANEOUS

  • To generate the thumbnail image ( screen shot of video) with playback button
    • Your controller class
    Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,$time_to_image);
    • Your config file
    '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', ''),
            ],
    ],
  • To generate the thumbnail image ( screen shot of video)
  Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image);
  • To convert video to WebM format
            $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);

LICENSE

MIT

lakshmaji/thumbnail 适用场景与选型建议

lakshmaji/thumbnail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 123.28k 次下载、GitHub Stars 达 108, 最近一次更新时间为 2017 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「composer」 「thumbnail」 「video」 「ffmpeg」 「laravel」 「Thumbnails」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 lakshmaji/thumbnail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 lakshmaji/thumbnail 我们能提供哪些服务?
定制开发 / 二次开发

基于 lakshmaji/thumbnail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 123.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 108
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 108
  • Watchers: 5
  • Forks: 24
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-22