项目作者: lakshmaji

项目描述 :
Thumbnail for a given video using FFMpeg
高级语言: PHP
项目地址: git://github.com/lakshmaji/Thumbnail.git
创建时间: 2016-05-12T12:46:48Z
项目社区:https://github.com/lakshmaji/Thumbnail

开源协议:MIT License

下载


Thumbnail

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

    1. sudo apt-get update
    2. sudo apt-get install ffmpeg

Installing FFMpeg on Ubuntu 14.04 LTS

  • Add the mc3man ppa

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

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

    1. sudo apt-get install ffmpeg

Installing FFMpeg on CentOS

  • Enable EPEL repository

    • for centos 6

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

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

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

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

    1. rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
  • Install Nux Dextop with yum command as follows.

    • centos 6

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

      1. 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:

    1. yum repolist
  • Run following command to install FFMpeg

    1. yum install ffmpeg

Installing FFMpeg on Windows

Refer to the following links

WikiHow

AdapticeSolutions


Installation

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


Configurations

  • Publish the configuration file , this will publish thumbnail.php file to your application config directory.
    1. 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
      ```bash

      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

  1. This ensures that all the generated thumbnails with watermarks are having fixed dimensions
  2. ---
  3. >### Generating Thumbnail
  4. The following example illustrates the usage of Thumbnail package
  5. ```php
  6. <?php
  7. namespace Trending\Http\Controllers\File;
  8. use Carbon;
  9. use Thumbnail;
  10. use Illuminate\Http\Request;
  11. use Trending\Http\Controllers\Controller;
  12. /**
  13. * -----------------------------------------------------------------------------
  14. * ThumbnailTest - a class illustarting the usage og Thumbnail package
  15. * -----------------------------------------------------------------------------
  16. * This class having the functionality to upload a video file
  17. * and generate corresponding thumbnail
  18. *
  19. * @since 1.0.0
  20. * @version 1.0.0
  21. * @author lakshmaji
  22. */
  23. class ThumbnailTest extends AnotherClass
  24. {
  25. public function testThumbnail()
  26. {
  27. // get file from input data
  28. $file = $this->request->file('file');
  29. // get file type
  30. $extension_type = $file->getClientMimeType();
  31. // set storage path to store the file (actual video)
  32. $destination_path = storage_path().'/uploads';
  33. // get file extension
  34. $extension = $file->getClientOriginalExtension();
  35. $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
  36. $file_name = $timestamp;
  37. $upload_status = $file->move($destination_path, $file_name);
  38. if($upload_status)
  39. {
  40. // file type is video
  41. // set storage path to store the file (image generated for a given video)
  42. $thumbnail_path = storage_path().'/images';
  43. $video_path = $destination_path.'/'.$file_name;
  44. // set thumbnail image name
  45. $thumbnail_image = $fb_user_id.".".$timestamp.".jpg";
  46. // set the thumbnail image "palyback" video button
  47. $water_mark = storage_path().'/watermark/p.png';
  48. // get video length and process it
  49. // assign the value to time_to_image (which will get screenshot of video at that specified seconds)
  50. $time_to_image = floor(($data['video_length'])/2);
  51. $thumbnail_status = Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,$time_to_image);
  52. if($thumbnail_status)
  53. {
  54. echo "Thumbnail generated";
  55. }
  56. else
  57. {
  58. echo "thumbnail generation has failed";
  59. }
  60. }
  61. }
  62. }
  63. // end of class ThumbnailTest
  64. // end of file ThumbnailTest.php

METHOD

  1. $thumbnail_status = Thumbnail::getThumbnail(<VIDEO_SOURCE_DIRECTORY>,<THUMBNAIL_STORAGE_DIRECTORY>,<THUMBNAIL_NAME>);
  1. $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
      1. Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,$time_to_image);
    • Your config file
      1. 'watermark' => [
      2. 'image' => [
      3. 'enabled' => env('WATERMARK_IMAGE', true),
      4. 'path' => env('WATERMARK_PATH', 'http://voluntarydba.com/pics/YouTube%20Play%20Button%20Overlay.png'),
      5. ],
      6. 'video' => [
      7. 'enabled' => env('WATERMARK_VIDEO', false),
      8. 'path' => env('WATERMARK_PATH', ''),
      9. ],
      10. ],
  • To generate the thumbnail image ( screen shot of video)

    1. Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image);
  • To convert video to WebM format
    ```php

    1. $video_path = $destination_path.'/'.$file_name; // source video path
    2. $clipped_video = $destination_path.'/'.'clipped_'.$file_name; // converted video file

Thumbnail::clipWebM($video_path,$clipped_video);
```


LICENSE

MIT