Thumbnail

Thumbnail for a given video using FFMpeg

This project is maintained by lakshmajim

Thumbnail

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 - Generateing thumbnail image with this package
Miscellaneous - Miscellaneous content regarding method calls
Twilio - License Information

What it is

Version

1.0.0


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 Ubuntu

Installing FFMpeg on CentOS

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.

Installing FFMpeg on Windows

Refer to the following links

WikiHow

AdapticeSolutions


Installation

    composer require lakshmajim/thumbnail
Lakshmajim\Thumbnail\ThumbnailServiceProvider::class,
'Thumbnail' => Lakshmajim\Thumbnail\Facade\Thumbnail::class,

Genearting 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   lakshmajim <lakshmajee88@gmail.com>
 */
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,160,128,$time_to_image,$water_mark,true);      
            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>,<HEIGHT_OF_IMAGE>,<WIDTH_OF_IMAGE>,<TIME_TO_TAKE_SCREENSHOT>,<WATERMARK_SOURCE_PATH>,<WATER_MARK>);
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
HEIGHT_OF_IMAGE The height of output image optional
WIDTH_OF_IMAGE The width of output image
TIME_TO_TAKE_SCREENSHOT Time to take screenshot of the video optional
WATERMARK_SOURCE_PATH The name of watermark or play button along with the storage path optional
WATER_MARK if this value set to true then it inserts play button or watermark on thumbnail image
THUMBNAIL_IMAGE_WIDTH The height of thumbnail image with watermark mandatory
THUMBNAIL_IMAGE_HEIGHT The width of Thumbnail image with watermark mandatory

Note The final output thumbnail image dimensions must be specified in .env file.

THUMBNAIL_IMAGE_WIDTH  = 320
THUMBNAIL_IMAGE_HEIGHT = 240

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


MISCELLANEOUS

Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,160,128,$time_to_image,$water_mark,false);
Thumbnail::getThumbnail($video_path,$thumbnail_path,$thumbnail_image,160,128,$time_to_image,$water_mark,true);

LICENSE

MIT